A simple, real-world spam detection neural network built from scratch in PyTorch.
This model classifies SMS / short text messages as Spam or Ham (Not Spam).
The project is small, easy to understand, and perfect for learning.
You can fork it, fine-tune it, and use it as a starting point for your own projects.
1defpredict(text):2 vec = vectorizer.transform([text]).toarray()3 vec = torch.tensor(vec, dtype=torch.float32)45with torch.no_grad():6 output = model(vec)78return"Spam"if output.item()>0.35else"Ham"910# Example11print(predict("Congratulations! You won $1000. Click now!"))
🔧 Training & Fine-Tuning
The model can be improved and fine-tuned by:
Adding more data (larger SMS datasets)
Increasing n-grams (ngram_range=(1,2))
Adjusting class weights in BCEWithLogitsLoss
Training with more epochs
Using embeddings or LSTM for contextual understanding
💡 Fork this repo and experiment freely. Make it your own!
🌟 Support the Project
If this project is helpful:
⭐ Give this repository a star
🍴 Fork it and improve it
📢 Share it with others learning PyTorch
Following and starring helps me keep releasing open-source projects!
📌 Source Code & Updates
For the full source code, training scripts, and future updates,
please visit the GitHub repository linked to this project.
📜 License
This project is open-source and intended for educational purposes.
MIT License applies.
🤗 Hugging Face Friendly
You can also upload this model to Hugging Face Model Hub.
Include spam_nn.pth, vectorizer.pkl, config.json, and inference.py to make it ready for inference online.