A deep-learning SMS spam detector built with TensorFlow/Keras (LSTM) and served via a Flask web app.
spam_classifier/
├── app.py # Flask web app (trains model on startup, serves UI + /predict API)
├── LSTM_Spam_Detection.ipynb # Jupyter notebook with full EDA + training walkthrough
├── SMSSpamCollection.csv # Dataset (tab-separated: label \t message)
└── requirements.txt
pip install -r requirements.txtPlace SMSSpamCollection.csv in the same folder as app.py.
python app.pyThe script will:
- Load and balance the dataset (down-sample ham to match spam count).
- Tokenize and pad sequences.
- Train a two-layer LSTM model (up to 30 epochs with early stopping).
- Start a Flask server at 👉 http://127.0.0.1:5001.
Open the URL in your browser, type any SMS message, and click Classify Message.
| Layer | Details |
|---|---|
| Embedding | vocab=500, dim=16, input_len=50 |
| LSTM | units=20, dropout=0.2, return_seq=True |
| LSTM | units=20, dropout=0.2 |
| Dense | 1 unit, sigmoid activation |
Loss: binary_crossentropy | Optimizer: adam
The UCI SMS Spam Collection dataset — 5,572 messages labelled ham or spam.
Ham messages are down-sampled to 747 to match the spam count before training.
POST /predict
// Request
{ "message": "Congratulations! You've won a free prize. Call now!" }
// Response
{ "label": "SPAM", "score": 0.9821 }