An NLP-powered email classification system that automatically categorizes incoming emails using classical machine learning. The system preprocesses raw email text, extracts features, and classifies emails in real time through an interactive Chainlit chat interface.
- Manual email sorting is time-consuming and error-prone
- Goal: Build a lightweight, deployable classifier that categorizes emails accurately without heavy transformer models
- Emphasis on speed and interpretability over complexity
Raw Email Text → Preprocessing → Feature Extraction → Classification → Chainlit UI
- Stopword removal
- Tokenization
- Stemming
- Bag-of-Words representation from Kaggle email dataset
- Vocabulary saved as
vocab.pklfor inference reuse
- Multinomial Naive Bayes well-suited for discrete word count features
- Trained with stratified 80/20 train-test split
- Model serialized as
email_classifier.pklfor deployment
- Chainlit interactive chat UI user pastes email text, gets instant classification
├── smart_email_agent_train.py # Training script
├── app.py # Chainlit deployment app
├── email_classifier.pkl # Trained Naive Bayes model
├── vocab.pkl # Vocabulary (feature columns)
├── classes.pkl # Class labels
└── README.md # Documentation
# Install dependencies
pip install scikit-learn nltk pandas chainlit
# Place emails.csv (Kaggle dataset) in project root
# Run training
python smart_email_agent_train.pychainlit run app.py- Language: Python
- ML: Scikit-learn (MultinomialNB)
- NLP: NLTK (tokenization, stopwords, stemming)
- UI: Chainlit
- Dataset: Kaggle Email Dataset (Bag-of-Words format)
- Upgrade to TF-IDF vectorization for better feature representation
- Add multi-class support (Work, Personal, Spam, Promotions)
- Replace Naive Bayes with fine-tuned DistilBERT for higher accuracy
- Deploy as REST API with FastAPI
Hamza Maqsood
BS Artificial Intelligence University of Management and Technology, Lahore