Spam_Detection_LSTM / README.md
RebKip's picture
Update README.md
ce58313 verified
|
Raw History Blame Contribute Delete
3.53 kB
---
title: Spam Detection LSTM
emoji: 🚫
colorFrom: red
colorTo: red
sdk: docker
app_file: src/streamlit_app.py
app_port: 8501
tags:
- streamlit
pinned: false
short_description: AI-powered Spam vs. Ham classifier built with an LSTM RNN
license: mit
description: AI-powered Spam vs. Ham classifier built with an LSTM Recurrent Neural Network and Streamlit.
---
# 🚫 LSTM Spam Email & SMS Detector
An interactive, production-ready web application that utilizes a **Long Short-Term Memory (LSTM)** recurrent neural network to classify text messages as **Spam** or **Ham (Legitimate)**.
This project demonstrates an end-to-end Machine Learning pipeline: from raw text preprocessing and tokenization to model training, evaluation calibration, and containerized deployment via Docker.
---
## πŸš€ Interactive Demo
1. Type or paste any suspicious message or email into the text area.
2. Click **Predict**.
3. The app will return a classification badge (**SPAM** or **HAM**) alongside the model's precise internal probability score.
---
## πŸ“Š Model Performance & Calibration
During evaluation on the test split (**1,032 samples**), the model was calibrated to prioritize a **High-Precision Strategy** to minimize irritating False Positives (marking a critical legitimate email as spam).
Using an optimized decision threshold of **0.80**, the model achieves the following metrics:
### πŸ“ˆ Metrics Summary
* **Accuracy:** 97.67%
* **Precision:** 95.61% *(High precision ensures safe filtering)*
* **Recall:** 85.16%
* **F1-Score:** 90.08%
### πŸ“ Classification Report
```text
precision recall f1-score support
Negative (0) 0.98 0.99 0.99 904
Positive (1) 0.96 0.85 0.90 128
accuracy 0.98 1032
macro avg 0.97 0.92 0.94 1032
weighted avg 0.98 0.98 0.98 1032
```
---
## 🧠 Technical Architecture & Pipeline
1. **Text Preprocessing:** User input strings are automatically normalized to lowercase and stripped of redundant structural padding characters.
2. **Tokenization:** Text sequences are mapped to numerical vector keys using a pre-saved training vocabulary tokenizer (`spam_tokenizer.pickle`).
3. **Sequence Padding:** Sequences are bound to a strict maximum token length of **50** using a `post-padding` structure.
4. **Deep Learning Model:** A Keras/TensorFlow architecture utilizing dense Word Embedding layers followed by sequential **LSTM** memory layers to capture contextual long-term text dependencies.
---
## πŸ› οΈ Tech Stack & Engineering Details
* **Frontend UI:** Streamlit
* **Deep Learning Runtime:** TensorFlow / Keras
* **Data Processing:** NumPy & Pandas
* **Deployment Container:** Docker (Python 3.13-slim optimized environment)
---
## πŸ“ Repository Directory Layout
```text
β”œβ”€β”€ Dockerfile # Container building directives & environment exposure
β”œβ”€β”€ requirements.txt # Managed Python dependencies
└── src/
β”œβ”€β”€ streamlit_app.py # Main UI dashboard and inference logic
β”œβ”€β”€ best_lstm_model.keras # Pre-trained network layers and model weights
└── spam_tokenizer.pickle # Binary serialized vocabulary tokenizer asset
```
# Welcome to Streamlit!
Edit `/src/streamlit_app.py` to customize this app to your heart's desire. :heart:
If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
forums](https://discuss.streamlit.io).