Text Classification
Transformers
Safetensors
PyTorch
English
distilbert
spam-detection
sms
text-embeddings-inference
Instructions to use nagaananth/MLOPS_group-v4 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use nagaananth/MLOPS_group-v4 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="nagaananth/MLOPS_group-v4")# Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("nagaananth/MLOPS_group-v4") model = AutoModelForSequenceClassification.from_pretrained("nagaananth/MLOPS_group-v4", device_map="auto") - Notebooks
- Google Colab
- Kaggle
File size: 8,664 Bytes
0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 6f7c338 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 0e62f60 3641d04 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | ---
library_name: transformers
tags:
- text-classification
- spam-detection
- distilbert
- sms
- pytorch
language:
- en
license: mit
datasets:
- sms_spam
metrics:
- accuracy
- f1
pipeline_tag: text-classification
---
# SMS Spam Classifier β DistilBERT (Group 36, IIT Jodhpur)
Fine-tuned `distilbert-base-uncased` for binary SMS spam classification. Achieves **99.35% accuracy** and **0.9851 F1 Macro** on the held-out test set. This is **v2** β the best-performing version by validation loss (0.0292).
Developed as part of the MLOps course, PGD AI Program, IIT Jodhpur.
---
## Model Details
### Model Description
- **Base model:** `distilbert-base-uncased` (66M parameters)
- **Task:** Binary text classification β Ham (0) vs Spam (1)
- **Dataset:** UCI SMS Spam Collection (5,159 samples after deduplication)
- **Architecture:** DistilBERT encoder + linear classification head
- **Framework:** PyTorch + Hugging Face Transformers
- **Training platform:** Kaggle (NVIDIA T4 x2 GPU)
- **Developed by:** MLOps Group 36, IIT Jodhpur
- **Model card authors:** G25AIT2032 Duggirala Vnaga Ananth
- **Contact:** g25ait2032@iitj.ac.in
### Related Resources
| Resource | Link |
|---|---|
| GitHub Repository | [MLOps Group 36 Repository](https://github.com/g25ait2032-prog/mlops-group36-iitj) |
| Kaggle Notebook (Final) | [mlops-group36-final-v3](https://www.kaggle.com/code/g25ait2032/mlops-group36-final-v3) |
| W&B Dashboard | [MLOPS_Group](https://wandb.ai/g25ait2032-iit-jodhpur/MLOPS_Group) |
| HF Model β v1 | [nagaananth/MLOPS_group-v1](https://huggingface.co/nagaananth/MLOPS_group-v1) |
| HF Model β v2 β
Best | [nagaananth/MLOPS_group-v2](https://huggingface.co/nagaananth/MLOPS_group-v2) |
| HF Model β v3 | [nagaananth/MLOPS_group-v3](https://huggingface.co/nagaananth/MLOPS_group-v3) |
| HF Model β v4 | [nagaananth/MLOPS_group-v4](https://huggingface.co/nagaananth/MLOPS_group-v4) |
| Docker Image (GHCR) | `ghcr.io/g25ait2032-prog/mlops_group-inference:latest` |
| Docker Image (Hub) | `dvnananth/mlops-group36:v1` |
---
## How to Get Started
```python
from transformers import pipeline
classifier = pipeline(
"text-classification",
model="nagaananth/MLOPS_group-v2"
)
# Spam example
print(classifier("URGENT! You have won a free iPhone. Click here now."))
# [{'label': 'spam', 'score': 0.9804}]
# Ham example
print(classifier("Hey, are we still meeting for lunch at 12?"))
# [{'label': 'ham', 'score': 0.9982}]
```
Or with full control:
```python
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
model_name = "nagaananth/MLOPS_group-v2"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
model.eval()
def predict(text):
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=128)
with torch.no_grad():
logits = model(**inputs).logits
probs = torch.softmax(logits, dim=-1)[0]
pred_idx = probs.argmax().item()
return {
"label": model.config.id2label[pred_idx],
"score": round(probs[pred_idx].item(), 4)
}
print(predict("Free prize! Click now to claim your reward."))
# {'label': 'spam', 'score': 0.9897}
```
---
## Training Details
### Dataset
**UCI SMS Spam Collection** loaded via HuggingFace `datasets` (`sms_spam`).
| Split | Samples | Ham % | Spam % |
|---|---|---|---|
| Train (70%) | 3,611 | ~87.5 | ~12.5 |
| Validation (15%) | 774 | ~87.5 | ~12.5 |
| Test (15%) | 774 | ~87.5 | ~12.5 |
**Preprocessing steps:**
- Lowercased and whitespace normalised
- 415 duplicate messages removed (total: 5,159 unique samples)
- Stratified 70/15/15 split with zero-leakage verification
- Tokenized with `AutoTokenizer` for DistilBERT (`truncation=True, max_length=128`)
- Labels mapped: `{"ham": 0, "spam": 1}`
### Hyperparameter Comparison (All Versions)
| Version | LR | Epochs | Batch Size | Warmup | Weight Decay | Early Stopping | Val Loss | F1 Macro |
|---|---|---|---|---|---|---|---|---|
| v1 | 3e-5 | 3 | 16 | 100 | 0.01 | No | 0.0539 | 0.9849 |
| v2 β
| 2e-5 | 5 | 32 | 200 | 0.01 | Yes (p=2) | **0.0292** | **0.9851** |
| v3 | 2e-5 | 5 | 32 | 200 | 0.01 | Yes (p=2) | 0.0376 | 0.9851 |
| v4 | 1e-5 | 4 | 16 | 200 | 0.02 | Yes (p=2) | β | β |
**v2** was selected as the final deployment model due to its lowest validation loss (0.0292), indicating the best generalisation.
### Training Configuration (v2)
- **Optimizer:** AdamW
- **Learning rate:** 2e-5
- **Epochs:** 5 (with early stopping, patience=2)
- **Batch size:** 32 (train), 64 (eval)
- **Mixed precision:** fp16
- **Metric for best model:** F1 Weighted
- **Infrastructure:** Kaggle NVIDIA T4 x2 GPU
- **Average training time:** ~2 minutes per run
---
## Evaluation Results
### Test Set Performance (v2 β Best Model)
| Metric | Score |
|---|---|
| Accuracy | 0.9935 |
| F1 Weighted | 0.9935 |
| F1 Macro | 0.9851 |
| Precision | 0.9935 |
| Recall | 0.9935 |
| Validation Loss | 0.0292 |
### Adversarial Test Cases
The model was evaluated on 15 adversarial/edge-case SMS messages covering spam, ham, and ambiguous phrasing (e.g., messages mixing casual language with spam triggers). Representative examples:
| Text | True | Predicted | Confidence |
|---|---|---|---|
| "URGENT! You have won a 1-week cruise! Call now." | spam | spam | 0.9987 |
| "You won! Click here to claim your prize." | spam | spam | 0.9945 |
| "Hey, are we still meeting for lunch at 12?" | ham | ham | 0.9991 |
| "Can you send me the report by EOD?" | ham | ham | 0.9988 |
| "Meeting for lunch? I won a contest, let's talk." | ham | ham | 0.9756 |
### Inference Latency (CPU)
- Mean latency: ~30β60 ms per sample
- Suitable for CPU-only deployment
---
## Uses
### Direct Use
Binary classification of SMS or short-text messages into `ham` (legitimate) or `spam` (unsolicited/phishing). Can be directly integrated into messaging applications or notification pipelines.
### Downstream Use
Can serve as a component in broader security pipelines for filtering suspicious incoming messages, or as a baseline for transfer learning to other spam-detection domains.
### Out-of-Scope Use
- Long-form document classification
- Sentiment analysis or intent detection
- Legal or financial decision-making without human oversight
- Languages other than English
---
## Bias, Risks, and Limitations
**Data Bias:** Trained on a specific SMS corpus from the early 2010s. May struggle with modern slang, emojis, or evolved phishing techniques not present in the training data.
**False Positives:** Messages containing spam-adjacent keywords (e.g., "Urgent", "Click", "Won") in legitimate contexts may be misclassified.
**Contextual Blindness:** Processes each message independently; cannot use conversational context from prior messages.
**Phishing Sophistication:** Less reliable against highly sophisticated spear-phishing that mimics professional language.
### Recommendations
- Notify users when a message is flagged automatically.
- Provide a manual override/report mechanism for misclassifications.
- Monitor for distribution drift and retrain periodically on newer data.
---
## Technical Specifications
### Model Architecture
- **Base:** `distilbert-base-uncased` (6 transformer layers, 768 hidden dim, 12 attention heads)
- **Classification head:** Linear layer over `[CLS]` token pooled output β 2 classes
- **Total parameters:** ~66M
### Compute Infrastructure
- **Training:** Kaggle Notebooks β NVIDIA T4 x2 GPU
- **Libraries:** `transformers`, `datasets`, `evaluate`, `accelerate`, `torch`, `wandb`
- **Inference:** CPU-compatible (no GPU required)
### Environmental Impact
- **Hardware:** NVIDIA T4 GPU (Kaggle)
- **Training duration:** ~2 minutes per run
- **Carbon emitted:** < 0.01 kg COβeq (estimated via ML Impact Calculator)
---
## Citation
```bibtex
@misc{group36-sms-spam-2026,
author = {Duggirala Vnaga Ananth and Anukumar K and Shrikrishna Tripathi and Sudeb Ghosh},
title = {SMS Spam Classifier: Fine-tuned DistilBERT (Group 36, IIT Jodhpur)},
year = {2026},
publisher = {Hugging Face},
howpublished = {\url{https://huggingface.co/nagaananth/MLOPS_group-v2}}
}
```
---
## Glossary
- **Ham:** Legitimate, non-spam SMS message
- **Spam:** Unsolicited commercial or phishing message
- **DistilBERT:** Distilled version of BERT β 40% smaller, retains 97% of BERT's NLU performance
- **F1 Macro:** Unweighted mean of per-class F1 scores; useful for evaluating imbalanced datasets
- **Fine-tuning:** Adapting a pre-trained language model to a task-specific dataset with supervised training
|