Skip to content

FR34KY-CODER/FreeCodeCamp-SMSclassifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 

Repository files navigation

📡 Neural Network SMS Text Classifier

This project trains a binary classification neural network to distinguish between spam and ham (non-spam) SMS messages using TensorFlow and Keras.


📁 Dataset

The data used is the SMS Spam Collection dataset from FreeCodeCamp, consisting of two .tsv files:

  • train-data.tsv — training set
  • valid-data.tsv — validation/test set

Each line is formatted as:

<label> <TAB> <message>

Where <label> is either "ham" or "spam".


⚙️ Installation & Setup

bash pip install tensorflow pip install tensorflow-datasets pip install pandas numpy matplotlib

!wget https://cdn.freecodecamp.org/project-data/sms/train-data.tsv
!wget https://cdn.freecodecamp.org/project-data/sms/valid-data.tsv

🧠 Model Architecture

  • Input: Raw SMS text string
  • TextVectorization Layer: tokenizes and pads the input
  • Embedding Layer: converts tokens to dense vectors (dim=16)
  • GlobalAveragePooling1D: reduces sequence
  • Dense Layer (24 units, ReLU): learns non-linear combinations
  • Dropout (0.5): for regularization
  • Output Layer (sigmoid): predicts probability of spam

🏋️ Training Parameters

  • Loss: BinaryCrossentropy
  • Optimizer: Adam
  • Epochs: 20
  • Metrics: Accuracy
  • Validation Set: valid-data.tsv

🔮 Prediction Function

This function accepts a raw string message and returns:

[probability (01), "ham" or "spam"]

Example:

predict_message("how are you doing today?")
# Output: [0.0123, "ham"]

Code:

def predict_message(pred_text):
    input_data = np.array([pred_text], dtype=object)
    prediction = model.predict(input_data)
    spam_prob = float(prediction[0][0])
    label = 'spam' if spam_prob > 0.5 else 'ham'
    return [spam_prob, label]

✅ Test Pass Criteria

Your model must correctly classify the following test messages:

[
  "how are you doing today",
  "sale today! to stop texts call 98912460324",
  "i dont want to go. can we try it a different day? available sat",
  "our new mobile video service is live. just install on your phone to start watching.",
  "you have won £1000 cash! call to claim your prize.",
  "i'll bring it tomorrow. don't forget the milk.",
  "wow, is your arm alright. that happened to me one time too"
]

All predictions must match expected labels ("ham" or "spam") for success.


Colab Notebook Link (version problems)

https://colab.research.google.com/drive/1s7oLDkVU_kBd1biHSb7nmPi6Coq1gkze?authuser=2#scrollTo=lMHwYXHXCar3

🏆 Certificate

Upon passing the test suite, FreeCodeCamp awards a certificate for this project as part of their Machine Learning curriculum.


About

It's the Repo containing the Notebook for the 5th and last task of my FreeCodeCamp Certification course.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors