UDHOV commited on
Commit
b6ee1da
·
verified ·
1 Parent(s): a5a21ee

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +196 -122
README.md CHANGED
@@ -1,199 +1,273 @@
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
+ language:
3
+ - ne
4
+ tags:
5
+ - text-classification
6
+ - hate-speech-detection
7
+ - offensive-language
8
+ - nepali
9
+ - devanagari
10
+ - low-resource-nlp
11
+ - bert
12
+ - nepali-bert
13
+ datasets:
14
+ - niraula2021nepali
15
+ metrics:
16
+ - f1
17
+ - accuracy
18
+ license: mit
19
+ pipeline_tag: text-classification
20
+ base_model: Rajan/NepaliBERT
21
+ paper: https://aclanthology.org/2021.woah-1.7
22
  ---
23
 
24
+ # NepaliBERT Nepali Hate Content Classification
25
 
26
+ Fine-tuned [NepaliBERT](https://huggingface.co/Rajan/NepaliBERT) for multi-class hate content classification of Nepali social media text. The model is specifically optimized for Devanagari script Nepali and handles mixed-script inputs through a comprehensive preprocessing pipeline.
27
 
28
+ ## Model Description
29
 
30
+ This model was developed as part of a Bachelor of Computer Engineering final project at Khwopa College of Engineering, Tribhuvan University (February 2026). It classifies Nepali social media comments into four categories targeting different types of offensive content.
31
 
32
+ **Base model:** `Rajan/NepaliBERT` (110M parameters, 12 transformer layers, pre-trained on a large Nepali corpus using masked language modelling)
33
 
34
+ **Task:** Multi-class text classification (4 classes)
35
 
36
+ **Languages:** Nepali (Devanagari primary), Romanized Nepali, code-mixed
37
 
38
+ > **Compared to XLM-RoBERTa Large (our other model):** NepaliBERT's Nepali-specific pre-training gives it stronger Devanagari understanding and the best OR (Offensive-Racist) class F1 (0.4833) among all evaluated models. However, it has limited exposure to Romanized Nepali and English, making XLM-RoBERTa more robust on heavily code-mixed inputs.
39
 
40
+ ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
+ ## Labels
43
 
44
+ | ID | Label | Description |
45
+ |----|-------|-------------|
46
+ | 0 | `NON_OFFENSIVE` | Text containing no offensive content |
47
+ | 1 | `OTHER_OFFENSIVE` | General offensive content not targeting specific groups |
48
+ | 2 | `OFFENSIVE_RACIST` | Content targeting individuals/groups based on ethnicity, race, or caste |
49
+ | 3 | `OFFENSIVE_SEXIST` | Content targeting individuals based on gender |
50
 
51
+ ---
52
 
53
+ ## Usage
54
 
55
+ ```python
56
+ from transformers import pipeline
57
 
58
+ classifier = pipeline(
59
+ "text-classification",
60
+ model="UDHOV/nepalibert-nepali-hate-classification"
61
+ )
62
 
63
+ # Devanagari input
64
+ classifier("यो राम्रो छ")
65
 
66
+ # Romanized Nepali (will be preprocessed via transliteration ideally)
67
+ classifier("yo ramro cha")
68
+ ```
69
 
70
+ Or manually:
71
 
72
+ ```python
73
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
74
+ import torch
75
 
76
+ tokenizer = AutoTokenizer.from_pretrained("UDHOV/nepalibert-nepali-hate-classification")
77
+ model = AutoModelForSequenceClassification.from_pretrained("UDHOV/nepalibert-nepali-hate-classification")
78
 
79
+ text = "तिमी देखी घृणा लाग्छ"
80
+ inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=128)
81
 
82
+ with torch.no_grad():
83
+ logits = model(**inputs).logits
84
 
85
+ predicted_class = logits.argmax().item()
86
+ print(model.config.id2label[predicted_class])
87
+ ```
88
 
89
+ ---
90
 
91
+ ## Preprocessing Pipeline
92
 
93
+ The model was trained on text processed through a 5-stage pipeline:
94
 
95
+ 1. **Script Detection** — Unicode-based confidence scoring to classify input as Devanagari, Romanized Nepali, or English
96
+ 2. **Script Unification** — Romanized Nepali transliterated to Devanagari via ITRANS; English translated to Nepali via Deep Translator API
97
+ 3. **Emoji Processing** — 180+ emojis semantically mapped to Nepali equivalents; unknown emojis preserved; 18-dimensional emoji feature vector extracted
98
+ 4. **Text Cleaning** — URL removal, @mention removal, hashtag handling, whitespace normalization
99
+ 5. **Feature Extraction** — Script metadata, emoji features, and text statistics merged with cleaned text
100
 
101
+ > **Note:** NepaliBERT's WordPiece tokenizer is optimized for Devanagari. For best results, pre-process Romanized or English inputs through the transliteration/translation pipeline before passing to this model.
102
 
103
+ ---
104
 
105
+ ## Training Data
106
 
107
+ - **Source:** Niraula et al. (2021) — *Offensive Language Detection in Nepali Social Media* ([ACL Anthology](https://aclanthology.org/2021.woah-1.7))
108
+ - **Platform:** Facebook and YouTube comments
109
+ - **Total samples:** 7,625
110
 
111
+ | Split | NO | OO | OR | OS | Total |
112
+ |-------|----|----|----|----|-------|
113
+ | Train | 3,206 (57.7%) | 1,759 (31.6%) | 376 (6.8%) | 214 (3.8%) | 5,555 |
114
+ | Validation | 356 (57.5%) | 195 (31.5%) | 42 (6.8%) | 27 (4.4%) | 620 |
115
+ | Test | 896 (62.1%) | 486 (33.7%) | 49 (3.4%) | 19 (1.3%) | 1,450 |
116
 
117
+ **Class imbalance:** NO vs OS imbalance ratio = 14.98×. Addressed via class-weighted cross-entropy loss with weights capped in the range [0.5, 3.0] to prevent extreme gradient updates from the severely under-represented OS class.
118
 
119
+ ---
120
 
121
+ ## Training Configuration
122
+
123
+ | Hyperparameter | Value |
124
+ |----------------|-------|
125
+ | Optimizer | AdamW |
126
+ | Learning rate | 2e-5 (discriminative LR strategy) |
127
+ | Weight decay | 0.01 |
128
+ | Warmup steps | 10% of total steps |
129
+ | LR schedule | Linear decay |
130
+ | Batch size | 16 (grad accum × 2 = effective 32) |
131
+ | Max epochs | 5 |
132
+ | Early stopping patience | 2 epochs |
133
+ | Max sequence length | 128 tokens |
134
+ | Dropout (classification head) | 0.3 |
135
+ | Label smoothing | 0.05 |
136
+ | Class weight capping | [0.5, 3.0] |
137
+ | Gradient clipping | 1.0 |
138
+ | Loss | Class-weighted cross-entropy |
139
+
140
+ Training took approximately 3,759 seconds (~62.7 minutes) on a single GPU.
141
 
142
+ ---
143
 
144
+ ## Evaluation Results
145
 
146
+ ### Test Set Performance
147
 
148
+ | Class | Precision | Recall | F1-Score | Support |
149
+ |-------|-----------|--------|----------|---------|
150
+ | NON_OFFENSIVE | 0.7805 | 0.7701 | 0.7753 | 896 |
151
+ | OTHER_OFFENSIVE | 0.6102 | 0.5926 | 0.6013 | 486 |
152
+ | OFFENSIVE_RACIST | 0.4085 | 0.5918 | **0.4833** | 49 |
153
+ | OFFENSIVE_SEXIST | 0.1739 | 0.2105 | 0.1905 | 19 |
154
+ | **Macro Avg** | **0.4933** | **0.5413** | **0.5126** | 1,450 |
155
+ | **Weighted Avg** | 0.7029 | 0.6972 | 0.6994 | 1,450 |
156
+ | **Accuracy** | | | **0.6972** | 1,450 |
157
 
158
+ ### Validation Set Performance (Best Checkpoint)
159
 
160
+ | Class | Precision | Recall | F1-Score | Support |
161
+ |-------|-----------|--------|----------|---------|
162
+ | NON_OFFENSIVE | 0.7961 | 0.8118 | 0.8039 | 356 |
163
+ | OTHER_OFFENSIVE | 0.6609 | 0.5897 | 0.6233 | 195 |
164
+ | OFFENSIVE_RACIST | 0.6727 | 0.8810 | 0.7629 | 42 |
165
+ | OFFENSIVE_SEXIST | 0.8214 | 0.8519 | 0.8364 | 27 |
166
+ | **Macro Avg** | **0.7378** | **0.7836** | **0.7566** | 620 |
167
+ | **Accuracy** | | | **0.7484** | 620 |
168
 
169
+ > NepaliBERT achieved the **highest validation macro F1 (0.7566)** among all evaluated models, outperforming even XLM-RoBERTa Large (0.7392 val macro F1). The validation-to-test gap is primarily explained by distributional shift in the OR and OS minority classes, not overfitting (train-val loss gap = 0.066).
170
 
171
+ > **Primary metric:** Macro F1-score. Accuracy is misleading given class imbalance; macro F1 weights all classes equally, making it the appropriate metric for evaluating minority hate class performance.
172
 
173
+ ---
174
 
175
+ ## Training Dynamics
176
 
177
+ Training proceeded over approximately 1,000 gradient steps in three phases:
178
 
179
+ - **Phase 1 (steps 0–300):** Rapid co-descent of train and validation loss (1.50 → 1.00), faster than XLM-RoBERTa due to Nepali-specific pre-training. Validation F1 rises from 0.26 to 0.47.
180
+ - **Phase 2 (steps 300–600):** Training loss continues declining (~0.90); validation loss stabilizes around 1.00–1.02. Validation F1 improves to 0.65 as OO and OR class discrimination refines.
181
+ - **Phase 3 (steps 600–1000):** Validation F1 peaks near 0.75 at step 700, then settles at 0.72. Post-step-600 divergence between F1 and accuracy reflects a trade-off between majority class accuracy and minority class precision.
182
 
183
+ The final train-validation loss gap of 0.066 confirms minimal overfitting; poor OS test performance is a data distribution issue rather than model overfitting.
184
 
185
+ ---
186
 
187
+ ## Comparison with Other Models
188
 
189
+ | Approach | Model | Accuracy | Macro F1 |
190
+ |----------|-------|----------|----------|
191
+ | Classical ML | Logistic Regression (TF-IDF) | 0.7538 | 0.5701 |
192
+ | Classical ML | SVM | 0.7552 | 0.5502 |
193
+ | Deep Learning | GRU + Word2Vec | — | 0.3307 (test) |
194
+ | Transformer | XLM-RoBERTa Large | 0.7034 | 0.5465 |
195
+ | **Transformer** | **NepaliBERT (this model)** | **0.6972** | **0.5126** |
196
 
197
+ ### Per-Class F1 Comparison (Test Set)
198
 
199
+ | Model | Macro F1 | NO | OO | OR | OS |
200
+ |-------|----------|----|----|----|----|
201
+ | Logistic Regression | 0.5701 | 0.8225 | 0.6722 | 0.5000 | 0.2857 |
202
+ | SVM | 0.5502 | 0.8288 | 0.6659 | 0.4660 | 0.2400 |
203
+ | XLM-RoBERTa Large | 0.5465 | 0.7825 | 0.6306 | 0.3731 | **0.4000** |
204
+ | **NepaliBERT (this model)** | 0.5126 | 0.7753 | 0.6013 | **0.4833** | 0.1905 |
205
 
206
+ > **Key finding:** NepaliBERT achieves the best OR class F1 (0.4833) among all models, outperforming XLM-RoBERTa Large (0.3731), confirming that Nepali domain pre-training provides a meaningful advantage for ethnicity/caste-related hate content. XLM-RoBERTa Large outperforms NepaliBERT on the OS class (0.4000 vs 0.1905).
207
 
208
+ ---
209
 
210
+ ## Limitations
211
 
212
+ - **Romanized Nepali coverage:** NepaliBERT's pre-training corpus is predominantly Devanagari, limiting its ability to handle Romanized Nepali without prior transliteration. The OR test set contains 59.2% Romanized script vs 46.1% in training, contributing to the validation-to-test gap.
213
+ - **OS class collapse:** With only 19 OS test samples, high length mismatch (train avg 13.1 words vs test avg 19.9 words), and narrow training vocabulary, OS results (F1 = 0.1905) should be interpreted with significant caution.
214
+ - **Optimal checkpoint sensitivity:** NepaliBERT shows a more pronounced F1 peak-and-drop than XLM-RoBERTa, making it more sensitive to early stopping checkpoint selection.
215
+ - **Preprocessing dependency:** Performance on Romanized or English inputs degrades without prior transliteration/translation through the preprocessing pipeline.
216
+ - **Language scope:** Optimized specifically for Nepali. Not evaluated on other South Asian languages.
217
 
218
+ ---
219
 
220
+ ## Intended Use
221
 
222
+ - Automated hate content moderation on Nepali social media platforms, especially where content is primarily in Devanagari script
223
+ - Research on Nepali-specific NLP and low-resource hate speech detection
224
+ - Comparative study of language-specific vs multilingual transformer models
225
+ - Explainable AI integration — this model was evaluated with LIME, SHAP, and Captum-based Integrated Gradients for token-level attribution
226
 
227
+ **Out-of-scope uses:** This model should not be used as the sole decision-making system for content removal without human review. OS class predictions carry particularly high uncertainty due to extremely limited test support.
228
 
229
+ ---
230
 
231
+ ## Explainability
232
 
233
+ The deployment system integrates three complementary XAI methods for token-level explanation of predictions:
234
 
235
+ - **LIME** — Local surrogate model via word masking perturbations
236
+ - **SHAP** — Shapley value attribution (KernelSHAP)
237
+ - **Integrated Gradients (Captum)** — Gradient-based attribution along input-to-baseline path
238
 
239
+ ---
240
 
241
+ ## Citation
242
 
243
+ If you use this model, please cite the original dataset:
244
 
245
+ ```bibtex
246
+ @inproceedings{niraula2021offensive,
247
+ title={Offensive Language Detection in Nepali Social Media},
248
+ author={Niraula, Nobal B. and Dulal, Saurav and Koirala, Diwa},
249
+ booktitle={Proceedings of the 5th Workshop on Online Abuse and Harms (WOAH 2021)},
250
+ pages={67--75},
251
+ year={2021}
252
+ }
253
+ ```
254
 
255
+ And the base model:
256
 
257
+ ```bibtex
258
+ @article{thapa2024nepali,
259
+ title={Development of Pre-trained Transformer-based Models for the Nepali Language},
260
+ author={Thapa, Prashant and Sharma, Prajwal and Kharel, Aman},
261
+ journal={Transactions on Asian and Low-Resource Language Information Processing},
262
+ year={2024}
263
+ }
264
+ ```
265
 
266
+ ---
267
 
268
+ ## Authors
269
 
270
+ **Uddav Rajbhandari**
271
 
272
+ Department of Computer and Electronics Engineering
273
+ Khwopa College of Engineering, Tribhuvan University, Nepal (2026)