This project implements a multi-class topic classification system that predicts the topic of a document based on its textual content. The solution uses classical machine learning techniques by combining TF-IDF feature extraction with a Linear Support Vector Machine (Linear SVM).
The project was developed as part of the IIT Gandhinagar Technical Assistant assignment. The complete machine learning pipeline includes dataset inspection, exploratory data analysis, text preprocessing, feature engineering, model development, experimentation, evaluation, error analysis, and inference.
The original dataset contains approximately 10 million documents (4 GB). During development and experimentation, a representative subset of 122,880 documents was used to enable efficient training and evaluation on CPU hardware.
| Metric | Value |
|---|---|
| Final Model | Linear Support Vector Machine (Linear SVM) |
| Feature Extraction | TF-IDF (Word Unigrams + Bigrams) |
| Development Dataset | 122,880 Documents |
| Original Dataset | 10 Million Documents |
| Number of Classes | 24 |
| Vocabulary Size | 100,000 |
| Accuracy | 92.06% |
- Multi-class topic classification for 24 predefined categories
- TF-IDF feature extraction using word unigrams and bigrams
- Linear Support Vector Machine (Linear SVM) classifier
- Logistic Regression baseline implementation
- Balanced Logistic Regression implementation
- Hybrid TF-IDF + Linear SVM implementation
- Automatic evaluation using Accuracy, Precision, Recall, and F1-score
- Confusion matrix generation
- Misclassification analysis
- Saved trained model using Joblib
- Saved TF-IDF vectorizer for inference
- Interactive command-line inference script
Topic-Classifier/
│
├── data/
│ └── dataset_10.parquet
│
├── figures/
│ └── confusion_matrix.png
│
├── models/
│ ├── baseline_lr.joblib
│ ├── balanced_lr.joblib
│ ├── hybrid_svm.joblib
│ ├── linear_svm.joblib
│ └── tfidf_vectorizer.joblib
│
├── outputs/
│ ├── baseline_metrics.csv
│ ├── balanced_lr_metrics.csv
│ ├── hybrid_svm_metrics.csv
│ ├── linear_svm_metrics.csv
│ └── misclassified_examples.csv
│
├── reports/
│ └── report.pdf
│
├── src/
│ ├── config.py
│ ├── loader.py
│ ├── preprocessing.py
│ ├── feature_engineering.py
│ ├── feature_engineering_hybrid.py
│ ├── model.py
│ ├── model_balanced_lr.py
│ ├── model_svm.py
│ ├── evaluate.py
│ ├── train_baseline.py
│ ├── train_balanced_lr.py
│ ├── train_hybrid_svm.py
│ ├── train_svm.py
│ ├── inference.py
│ ├── error_analysis.py
│ ├── plot_confusion_matrix.py
│ ├── inspect_dataset.py
│ ├── eda.py
│ └── data_profiler.py
│
├── README.md
├── requirements.txt
└── .gitignore
The dataset was provided as part of the IIT Gandhinagar Technical Assistant assignment.
| Property | Value |
|---|---|
| Format | Parquet |
| File Name | dataset_10.parquet |
| Size | Approximately 4 GB |
| Total Rows | 10,000,000 |
| Columns | DATA, TOPIC |
| Column | Description |
|---|---|
| DATA | Input text document |
| TOPIC | Target topic label |
Place the provided dataset inside the data/ directory before training.
Note: The dataset is not included in this repository because it was provided as part of the assignment.
git clone https://github.com/ayushgit9090/Topic-Classifier.git
cd Topic-Classifierpython -m venv .venv.venv\Scripts\activatesource .venv/bin/activatepip install -r requirements.txtTrain the final Linear SVM model using
python src/train_svm.pyThe training pipeline performs:
- Dataset loading
- Text preprocessing
- TF-IDF feature extraction
- Train/Test split
- Linear SVM training
- Model evaluation
- Model serialization
- TF-IDF vectorizer serialization
Saved files:
models/
├── linear_svm.joblib
└── tfidf_vectorizer.joblib
Run the trained classifier
python src/inference.pyExample
Input
Virat Kohli scored a century in today's cricket match.
Output
Predicted Topic:
sports_and_fitness
Another example
Input
Python programming using NumPy and pandas.
Output
Predicted Topic:
software_development
A single text document.
Example
Python programming using NumPy and pandas.
One predicted topic label.
Example
software_development
| Model | Accuracy |
|---|---|
| Logistic Regression | 84.90% |
| Balanced Logistic Regression | 71.50% |
| Hybrid TF-IDF + Linear SVM | 88.10% |
| Linear SVM | 92.06% |
The Linear SVM achieved the highest overall accuracy and was selected as the final model.
The project ensures reproducibility by:
- Using a fixed random seed for train/test splitting.
- Applying deterministic preprocessing.
- Using a fixed TF-IDF configuration.
- Saving both the trained model and fitted TF-IDF vectorizer.
- Providing a standalone inference script.
- Maintaining a modular project structure.
Possible future enhancements include:
- Training on the complete 10 million document dataset.
- Incremental learning for large-scale training.
- Better handling of minority classes.
- Advanced feature engineering.
- Distributed training for faster experimentation.
Ayush Das
2026