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