A complete email classification system combining BERT embeddings and Scikit-learn classifiers, trained on multiple datasets and deployable via FastAPI.
This project uses BERT embeddings to capture context and semantics, improving spam and phishing detection. Later, classical ML classifiers (Logistic Regression, SVM, Random Forest) are trained on these embeddings for production deployment. Key Highlights:
- Fine-tuned BERT model for phishing detection (offline)
- Multi-dataset combination for robust training
- Classical ML classifiers trained on TF-IDF features
- Saved as
.pklfiles for deployment - FastAPI endpoints for real-time email scanning
- Hugging Face integration for model sharing
- Combined 3 public spam datasets
- Classifiers: Logistic Regression, SVM, Random Forest
- Feature extraction: TF-IDF vectorization
- Best model saved as
spam_model_fixed.pkl - Hugging Face link for BERT embeddings:
👉 Your Hugging Face Model
- 🔐 Secure Gmail API connection
- 📥 Fetch recent emails
- 🤖 Classify as Spam / Legitimate / Phishing
- 📊 Generate evaluation metrics
- 🌐 RESTful API powered by FastAPI
- Create a virtual environment
# Windows
python -m venv env
.\env\Scripts\activate
# Linux / macOS
python3 -m venv env
source env/bin/activate- Install required packages
pip install -r Requirements.txt- Run the FastAPI server
uvicorn main:app --reload