nagaananth commited on
Commit
4dbed66
·
verified ·
1 Parent(s): df1751a

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +183 -124
README.md CHANGED
@@ -1,199 +1,258 @@
1
  ---
2
  library_name: transformers
3
- tags: []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  ---
5
 
6
- # Model Card for Model ID
7
 
8
- <!-- Provide a quick summary of what the model is/does. -->
9
 
 
10
 
 
11
 
12
  ## Model Details
13
 
14
  ### Model Description
15
 
16
- <!-- Provide a longer summary of what this model is. -->
17
-
18
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
-
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
-
28
- ### Model Sources [optional]
29
-
30
- <!-- Provide the basic links for the model. -->
31
-
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
-
36
- ## Uses
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
- [More Information Needed]
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
- [More Information Needed]
51
 
52
- ### Out-of-Scope Use
 
53
 
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
 
 
 
55
 
56
- [More Information Needed]
 
 
57
 
58
- ## Bias, Risks, and Limitations
 
 
 
59
 
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
 
62
- [More Information Needed]
 
 
63
 
64
- ### Recommendations
 
 
 
65
 
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
 
 
 
 
 
 
 
 
 
67
 
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
 
 
69
 
70
- ## How to Get Started with the Model
71
-
72
- Use the code below to get started with the model.
73
-
74
- [More Information Needed]
75
 
76
  ## Training Details
77
 
78
- ### Training Data
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
- ### Training Procedure
85
 
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
 
 
 
 
87
 
88
- #### Preprocessing [optional]
 
 
 
 
 
89
 
90
- [More Information Needed]
91
 
 
 
 
 
 
 
92
 
93
- #### Training Hyperparameters
94
 
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
 
97
- #### Speeds, Sizes, Times [optional]
 
 
 
 
 
 
 
98
 
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
 
101
- [More Information Needed]
102
 
103
- ## Evaluation
104
 
105
- <!-- This section describes the evaluation protocols and provides the results. -->
 
 
 
 
 
 
 
106
 
107
- ### Testing Data, Factors & Metrics
108
 
109
- #### Testing Data
110
 
111
- <!-- This should link to a Dataset Card if possible. -->
 
 
 
 
 
 
112
 
113
- [More Information Needed]
114
 
115
- #### Factors
 
116
 
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
 
119
- [More Information Needed]
120
 
121
- #### Metrics
122
 
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
 
125
- [More Information Needed]
126
 
127
- ### Results
128
 
129
- [More Information Needed]
130
 
131
- #### Summary
 
 
 
132
 
 
133
 
 
134
 
135
- ## Model Examination [optional]
136
 
137
- <!-- Relevant interpretability work for the model goes here -->
138
 
139
- [More Information Needed]
140
 
141
- ## Environmental Impact
142
 
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
 
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
 
 
146
 
147
- - **Hardware Type:** [More Information Needed]
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 [optional]
154
 
155
- ### Model Architecture and Objective
156
 
157
- [More Information Needed]
 
 
158
 
159
  ### Compute Infrastructure
160
 
161
- [More Information Needed]
162
-
163
- #### Hardware
164
-
165
- [More Information Needed]
166
 
167
- #### Software
168
 
169
- [More Information Needed]
 
 
170
 
171
- ## Citation [optional]
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
- [More Information Needed]
192
 
193
- ## Model Card Authors [optional]
 
 
 
 
 
 
 
 
194
 
195
- [More Information Needed]
196
 
197
- ## Model Card Contact
198
 
199
- [More Information Needed]
 
 
 
 
 
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