This project predicts whether a given SMS message is spam or not using a feedforward neural network implemented in PyTorch.
- 🧠 Neural Network with multiple hidden layers using LeakyReLU activation function and Dropout
- ⚖️ Binary Cross-Entropy (BCE) Loss for binary classification
- 🔄 Adam optimizer for training
- 🔀 Train/Validation/Test split with mini-batches for robust evaluation
- 📈 CountVectorizer feature extraction for converting text messages into numerical features
- 💾 Saving and loading vectorizer for consistent preprocessing during inference
- 🎨 Interactive Gradio Interface for real-time prediction
Below is a preview of the Gradio Interface used for real-time classification:
- PyTorch – model, training, and inference
- pandas – data handling
- matplotlib – loss visualization
- pickle – saving/loading vectorizer and trained model
- Gradio — interactive web interface for real-time model demos
- Python 3.13+
- Recommended editor: VS Code
- Clone the repository
git clone https://github.com/hurkanugur/SMS-Spam-Classifier.git- Navigate to the
SMS-Spam-Classifierdirectory
cd SMS-Spam-Classifier- Install dependencies
pip install -r requirements.txtView → Command Palette → Python: Create Environment- Choose Venv and your Python version
- Select requirements.txt to install dependencies
- Click OK
assets/
└── app_screenshot.png # Screenshot of the application
data/
└── SMSSpamCollection # Raw dataset
model/
├── sms_spam_classifier.pth # Trained model (after training)
└── vectorizer.pkl # Saved CountVectorizer for text preprocessing
src/
├── config.py # Paths, hyperparameters, split ratios
├── dataset.py # Data loading & preprocessing
├── device_manager.py # Selects and manages compute device
├── train.py # Training pipeline
├── inference.py # Inference pipeline
├── model.py # Neural network definition
└── visualize.py # Training/validation plots
main/
├── main_train.py # Entry point for training
└── main_inference.py # Entry point for inference
requirements.txt # Python dependenciesInput → Linear(256) → LeakyReLU(0.01) → Dropout(0.5)
→ Linear(128) → LeakyReLU(0.01) → Dropout(0.5)
→ Linear(64) → LeakyReLU(0.01) → Dropout(0.5)
→ Linear(32) → LeakyReLU(0.01) → Dropout(0.5)
→ Linear(1) → Sigmoid(Output)Navigate to the project directory:
cd SMS-Spam-ClassifierRun the training script:
python -m main.main_trainor
python3 -m main.main_trainNavigate to the project directory:
cd SMS-Spam-ClassifierRun the app:
python -m main.main_inferenceor
python3 -m main.main_inference