mopatik commited on
Commit
47d930e
·
verified ·
1 Parent(s): 3850802

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +532 -4
README.md CHANGED
@@ -1,8 +1,536 @@
1
  ---
2
- license: apache-2.0
3
  language:
4
  - tn
5
- base_model:
6
- - mopatik/PuoBERTa-offensive-language-detection-v2
7
  pipeline_tag: text-classification
8
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
 
2
  language:
3
  - tn
4
+ license: cc-by-4.0
5
+ library_name: transformers
6
  pipeline_tag: text-classification
7
+ tags:
8
+ - text-classification
9
+ - offensive-language-detection
10
+ - setswana
11
+ - low-resource-nlp
12
+ - digital-forensics
13
+ - explainable-ai
14
+ - rationale-learning
15
+ - masked-rationale-prediction
16
+ - puoberta
17
+ - lime
18
+ - s-lime
19
+ metrics:
20
+ - accuracy
21
+ - f1
22
+ - matthews_correlation
23
+ - roc_auc
24
+ ---
25
+
26
+ # PuoBERTa-MRP for Setswana Offensive Content Detection
27
+
28
+ ## Model Summary
29
+
30
+ This repository contains **PuoBERTa-MRP**, a rationale-aware fine-tuned version of **PuoBERTa** for binary offensive-content detection in Setswana.
31
+
32
+ The model classifies Setswana text into:
33
+
34
+ | Label ID | Label |
35
+ |---:|---|
36
+ | 0 | Non-offensive |
37
+ | 1 | Offensive |
38
+
39
+ The model was developed for research on **low-resource African language NLP**, **digital forensic investigation**, and **explainable offensive-language detection**. The MRP version extends the standard PuoBERTa fine-tuning setup by incorporating **Masked Rationale Prediction (MRP)** as a rationale-aware training and evaluation strategy.
40
+
41
+ In this work, *rationales* refer to semantically important offensive spans or trigger expressions that contribute to the offensive classification decision. These spans are used during model development to study whether the classifier relies on linguistically meaningful cues rather than shallow lexical shortcuts.
42
+
43
+ ---
44
+
45
+ ## What is MRP?
46
+
47
+ **MRP** stands for **Masked Rationale Prediction**.
48
+
49
+ The purpose of the MRP setup is to test and improve the relationship between:
50
+
51
+ - sentence-level offensive classification,
52
+ - annotated semantic trigger spans,
53
+ - masked or neutralised rationale regions,
54
+ - and explanation faithfulness.
55
+
56
+ In the MRP setting, annotated offensive rationales are used to create controlled training or diagnostic variants in which key offensive spans may be masked, removed, or neutralised. This allows the researcher to examine whether the model:
57
+
58
+ 1. depends only on explicit offensive tokens;
59
+ 2. uses broader contextual patterns;
60
+ 3. remains robust when rationale-bearing terms are masked;
61
+ 4. produces explanations aligned with annotated semantic triggers.
62
+
63
+ This makes the model useful not only for classification, but also for **forensic explainability analysis**.
64
+
65
+ ---
66
+
67
+ ## Research Motivation
68
+
69
+ Offensive-language detection in Setswana presents challenges that are not fully addressed by ordinary sentence-level classification. Offensive meaning may be expressed through:
70
+
71
+ - culturally specific insults,
72
+ - idiomatic expressions,
73
+ - indirect accusations,
74
+ - threats,
75
+ - phishing-related cues,
76
+ - sarcasm,
77
+ - dehumanising metaphors,
78
+ - and code-switched or non-standard orthography.
79
+
80
+ In small low-resource datasets, a model may overfit to obvious abusive terms while failing to capture broader discourse structures. MRP is introduced to investigate whether rationale masking can reveal or reduce such dependency.
81
+
82
+ The central research question is:
83
+
84
+ > Can rationale-aware masking improve the interpretability and robustness of Setswana offensive-language detection while preserving useful classification performance?
85
+
86
+ ---
87
+
88
+ ## Intended Use
89
+
90
+ This model is intended for:
91
+
92
+ - Setswana offensive-language detection research;
93
+ - cyberbullying and harassment detection experiments;
94
+ - digital forensic triage support;
95
+ - explainable AI experiments;
96
+ - LIME and S-LIME attribution analysis;
97
+ - masked rationale and counterfactual evaluation;
98
+ - benchmarking rationale-aware transformer models for low-resource languages.
99
+
100
+ It may be useful in research workflows where the goal is to analyse both:
101
+
102
+ - **what the model predicts**, and
103
+ - **why the model predicts it**.
104
+
105
+ ---
106
+
107
+ ## Out-of-Scope Use
108
+
109
+ This model should **not** be used for:
110
+
111
+ - fully automated legal decision-making;
112
+ - disciplinary action without human review;
113
+ - automated criminal attribution;
114
+ - autonomous social media moderation;
115
+ - profiling individuals or communities;
116
+ - deployment on non-Setswana text without validation.
117
+
118
+ The model is intended to support research and forensic triage, not replace human interpretation.
119
+
120
+ ---
121
+
122
+ ## Dataset Description
123
+
124
+ The model is based on a manually curated Setswana offensive-language corpus containing offensive and non-offensive examples.
125
+
126
+ The dataset follows a simple CSV structure compatible with common offensive-language NLP datasets such as OLID and HateCheck:
127
+
128
+ ```csv
129
+ TEXT,TARGET
130
+ ```
131
+
132
+ Where:
133
+
134
+ | Column | Description |
135
+ |---|---|
136
+ | `TEXT` | Setswana sentence or comment |
137
+ | `TARGET` | Class label: `Offensive` or `Non-offensive` |
138
+
139
+ The broader corpus contains approximately:
140
+
141
+ | Class | Count |
142
+ |---|---:|
143
+ | Non-offensive | 500 |
144
+ | Offensive | 477 |
145
+ | Total | 977 |
146
+
147
+ If using the public merged release, verify the exact row count in the dataset card and release notes, as sanitised or release-ready versions may differ slightly from the internal experimental corpus.
148
+
149
+ ---
150
+
151
+ ## Rationale and Trigger Annotation
152
+
153
+ During dataset preparation, semantically important offensive spans were annotated as rationales or trigger regions.
154
+
155
+ These rationales may include:
156
+
157
+ - direct insults;
158
+ - vulgar expressions;
159
+ - harassment phrases;
160
+ - threat expressions;
161
+ - phishing or scam cues;
162
+ - dehumanising metaphors;
163
+ - culturally grounded abusive expressions.
164
+
165
+ Example rationale-style annotation:
166
+
167
+ ```text
168
+ O tshwanetse go tlogela <TRIGGER>boaka</TRIGGER>
169
+ ```
170
+
171
+ For MRP experiments, such spans can be converted into masked variants, for example:
172
+
173
+ ```text
174
+ O tshwanetse go tlogela <MASK>
175
+ ```
176
+
177
+ or neutralised variants, depending on the experiment design.
178
+
179
+ ---
180
+
181
+ ## Evaluation Setting
182
+
183
+ A key principle of this work is that the model should be assessed under realistic conditions.
184
+
185
+ Therefore, final evaluation should be performed on:
186
+
187
+ - tag-free text,
188
+ - unmasked ordinary inputs,
189
+ - and a held-out test set not used during training or tuning.
190
+
191
+ This avoids giving the model artificial markup during deployment-like testing.
192
+
193
+ The evaluation protocol follows:
194
+
195
+ - 80/20 train-test split;
196
+ - 5-fold stratified cross-validation on the training partition;
197
+ - final evaluation on the untouched holdout test set;
198
+ - tag-free inference during final testing;
199
+ - rationale-aware analysis through masking and counterfactual evaluation.
200
+
201
+ ---
202
+
203
+ ## Model Architecture
204
+
205
+ | Component | Details |
206
+ |---|---|
207
+ | Base model | PuoBERTa |
208
+ | Architecture family | RoBERTa |
209
+ | Task | Sequence classification |
210
+ | Language | Setswana |
211
+ | ISO language code | `tn` |
212
+ | Number of labels | 2 |
213
+ | Framework | Hugging Face Transformers |
214
+ | Backend | PyTorch |
215
+
216
+ ---
217
+
218
+ ## Training Configuration
219
+
220
+ The model was fine-tuned using a transformer sequence-classification setup.
221
+
222
+ Typical configuration:
223
+
224
+ | Parameter | Value |
225
+ |---|---:|
226
+ | Maximum sequence length | 128 |
227
+ | Optimizer | AdamW |
228
+ | Learning rate | 1e-5 |
229
+ | Weight decay | 0.01 |
230
+ | Training batch size | 16 |
231
+ | Evaluation batch size | 64 |
232
+ | Loss function | Class-weighted cross-entropy |
233
+ | Class weights | `[1.0, 2.0]` |
234
+ | Model selection focus | Offensive-class recall |
235
+
236
+ The offensive class was assigned a higher loss weight to reduce the risk of missing harmful instances.
237
+
238
+ ---
239
+
240
+ ## MRP-Specific Training / Analysis Workflow
241
+
242
+ The MRP workflow may include the following steps:
243
+
244
+ 1. Train or fine-tune the classifier on labelled Setswana text.
245
+ 2. Use annotated semantic rationales to identify offensive spans.
246
+ 3. Create masked-rationale variants of selected samples.
247
+ 4. Evaluate prediction changes after masking.
248
+ 5. Compare original and masked predictions.
249
+ 6. Use LIME or S-LIME to inspect whether top-attributed tokens align with annotated rationales.
250
+ 7. Analyse flip and non-flip cases to determine whether the model depends on explicit offensive tokens or broader contextual templates.
251
+
252
+ This workflow supports both predictive evaluation and forensic interpretability.
253
+
254
+ ---
255
+
256
+ ## Test Set Results
257
+
258
+ Insert the final MRP test-set metrics below once confirmed.
259
+
260
+ | Metric | Value |
261
+ |---|---:|
262
+ | Accuracy | 0.74 |
263
+ | Macro F1-score | `0.74` |
264
+ | Recall: Offensive class | `0.81` |
265
+ | MCC | `TO_BE_ADDED` |
266
+ | ROC-AUC | `TO_BE_ADDED` |
267
+ | Loss | `1.820457` |
268
+
269
+ Example format:
270
+
271
+ ```text
272
+ accuracy = 0.xxxx
273
+ macro_f1 = 0.xxxx
274
+ recall_1 = 0.xxxx
275
+ mcc = 0.xxxx
276
+ roc_auc = 0.xxxx
277
+ ```
278
+
279
+ Do not reuse metrics from the standard PuoBERTa or train-time trigger model unless they are from the exact MRP run.
280
+
281
+ ---
282
+
283
+ ## Explainability
284
+
285
+ This model is designed to support explainability experiments, especially:
286
+
287
+ - LIME;
288
+ - S-LIME;
289
+ - token-level attribution;
290
+ - masked-rationale comparison;
291
+ - counterfactual trigger neutralisation;
292
+ - rationale-alignment analysis.
293
+
294
+ In rationale-alignment analysis, the main question is whether the model’s most influential tokens overlap with human-annotated offensive rationales.
295
+
296
+ For example, if a human-annotated rationale is:
297
+
298
+ ```text
299
+ <TRIGGER>o sematla</TRIGGER>
300
+ ```
301
+
302
+ then a faithful explanation should assign strong attribution to the same phrase or semantically related parts of the sentence.
303
+
304
+ ---
305
+
306
+ ## Interpreting Attribution Scores
307
+
308
+ For LIME and S-LIME outputs:
309
+
310
+ - Positive attribution scores support the **Offensive** class.
311
+ - Negative attribution scores support the **Non-offensive** class.
312
+ - Stable attributions across random seeds indicate more reliable explanations.
313
+ - Large changes after rationale masking may indicate strong dependence on the masked phrase.
314
+ - Non-flip cases may indicate that surrounding context still carries offensive meaning.
315
+
316
+ MRP is therefore useful for distinguishing between:
317
+
318
+ - lexical reliance,
319
+ - contextual reasoning,
320
+ - and potentially spurious shortcut learning.
321
+
322
+ ---
323
+
324
+ ## Counterfactual and Masking Analysis
325
+
326
+ The MRP model can be evaluated using counterfactual edits such as:
327
+
328
+ | Original Type | Counterfactual Operation |
329
+ |---|---|
330
+ | Offensive rationale present | Mask offensive span |
331
+ | Offensive rationale present | Replace with neutral paraphrase |
332
+ | Offensive rationale present | Remove trigger span |
333
+ | Context preserved | Re-evaluate prediction |
334
+
335
+ A prediction flip from Offensive to Non-offensive may suggest that the model relied strongly on the rationale span.
336
+
337
+ A non-flip may suggest that offensive meaning is also encoded in the surrounding context, such as accusatory templates or threat-like phrasing.
338
+
339
+ ---
340
+
341
+ ## How to Use the Model
342
+
343
+ ```python
344
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
345
+ import torch
346
+
347
+ model_name = "YOUR-USERNAME/YOUR-PUOBERTA-MRP-MODEL"
348
+
349
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
350
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
351
+
352
+ text = "Ke dumela gore re tshwanetse go bua sentle."
353
+
354
+ inputs = tokenizer(
355
+ text,
356
+ return_tensors="pt",
357
+ truncation=True,
358
+ padding=True,
359
+ max_length=128
360
+ )
361
+
362
+ with torch.no_grad():
363
+ outputs = model(**inputs)
364
+
365
+ probs = torch.softmax(outputs.logits, dim=-1)
366
+ pred = torch.argmax(probs, dim=-1).item()
367
+
368
+ label_map = {
369
+ 0: "Non-offensive",
370
+ 1: "Offensive"
371
+ }
372
+
373
+ print("Prediction:", label_map[pred])
374
+ print("Probabilities:", probs.tolist())
375
+ ```
376
+
377
+ ---
378
+
379
+ ## Optional: Masked Rationale Diagnostic Example
380
+
381
+ The following is a diagnostic workflow for research use only.
382
+
383
+ ```python
384
+ original_text = "O tshwanetse go tlogela boaka"
385
+ masked_text = "O tshwanetse go tlogela <mask>"
386
+
387
+ texts = [original_text, masked_text]
388
+
389
+ inputs = tokenizer(
390
+ texts,
391
+ return_tensors="pt",
392
+ truncation=True,
393
+ padding=True,
394
+ max_length=128
395
+ )
396
+
397
+ with torch.no_grad():
398
+ outputs = model(**inputs)
399
+
400
+ probs = torch.softmax(outputs.logits, dim=-1)
401
+
402
+ for text, prob in zip(texts, probs):
403
+ print(text)
404
+ print(prob.tolist())
405
+ ```
406
+
407
+ Use this only if your tokenizer/model configuration supports the mask token appropriately.
408
+
409
+ ---
410
+
411
+ ## Limitations
412
+
413
+ The model has several limitations:
414
+
415
+ - The dataset is relatively small.
416
+ - The model is trained primarily for Setswana.
417
+ - It may be sensitive to spelling variation and informal orthography.
418
+ - It may struggle with sarcasm, irony, and implicit abuse.
419
+ - It may underperform on unseen slang or emerging online expressions.
420
+ - It performs binary classification only.
421
+ - It does not classify offensive subtypes such as hate speech, harassment, threat, or phishing separately.
422
+ - Rationale masking can help diagnosis, but it does not prove causal reasoning.
423
+
424
+ ---
425
+
426
+ ## Ethical Considerations
427
+
428
+ This model deals with offensive and potentially harmful language. It should be used carefully and only in appropriate research or forensic contexts.
429
+
430
+ Recommended safeguards:
431
+
432
+ - human-in-the-loop review;
433
+ - calibrated confidence thresholds;
434
+ - abstention for uncertain predictions;
435
+ - careful error analysis;
436
+ - avoidance of automated punitive action;
437
+ - compliance with data protection and cybercrime legislation;
438
+ - masking or sanitisation of offensive examples in public outputs.
439
+
440
+ The model should not be used as the sole basis for legal, disciplinary, or investigative conclusions.
441
+
442
+ ---
443
+
444
+ ## Bias and Fairness Considerations
445
+
446
+ Potential sources of bias include:
447
+
448
+ - sampling bias from public social media content;
449
+ - underrepresentation of dialectal variants;
450
+ - limited coverage of emerging slang;
451
+ - ambiguity in culturally specific phrases;
452
+ - and label uncertainty in sarcastic or metaphorical cases.
453
+
454
+ Users should validate the model on their own target domain before applying it in practical settings.
455
+
456
+ ---
457
+
458
+ ## Reproducibility
459
+
460
+ Related reproducibility resources may include:
461
+
462
+ - training notebooks;
463
+ - MRP experiment notebooks;
464
+ - LIME/S-LIME explainability notebooks;
465
+ - scripts for generating tables and figures;
466
+ - sanitised output files;
467
+ - dataset card;
468
+ - model card;
469
+ - Zenodo release.
470
+
471
+ Associated GitHub repository:
472
+
473
+ ```text
474
+ https://github.com/bkekgathetse/setswana-offensive-977
475
+ ```
476
+
477
+ Associated Hugging Face dataset:
478
+
479
+ ```text
480
+ ADD_DATASET_LINK_HERE
481
+ ```
482
+
483
+ Associated Zenodo release:
484
+
485
+ ```text
486
+ ADD_ZENODO_DOI_HERE
487
+ ```
488
+
489
+ ---
490
+
491
+ ## Recommended Citation
492
+
493
+ ```bibtex
494
+ @misc{kekgathetse2025puoberta_mrp,
495
+ title={PuoBERTa-MRP for Setswana Offensive Content Detection},
496
+ author={Kekgathetse, Bernerdict},
497
+ year={2025},
498
+ publisher={Hugging Face},
499
+ howpublished={\url{https://huggingface.co/YOUR-USERNAME/YOUR-PUOBERTA-MRP-MODEL}}
500
+ }
501
+ ```
502
+
503
+ If this model is linked to a manuscript, cite the corresponding paper as well:
504
+
505
+ ```bibtex
506
+ @article{kekgathetse2025setswanaoffensive,
507
+ title={Developing Monolingual Setswana Datasets for Offensive Content Detection},
508
+ author={Kekgathetse, Bernerdict},
509
+ journal={To be updated},
510
+ year={2025}
511
+ }
512
+ ```
513
+
514
+ ---
515
+
516
+ ## License
517
+
518
+ Please refer to the license specified in this repository.
519
+
520
+ Recommended licensing structure:
521
+
522
+ - Code: MIT or Apache-2.0
523
+ - Documentation: CC-BY 4.0
524
+ - Dataset access: governed separately due to ethical considerations
525
+
526
+ ---
527
+
528
+ ## Contact
529
+
530
+ For academic queries, reproducibility questions, or collaboration requests, please refer to the associated GitHub repository or manuscript contact details.
531
+
532
+ ---
533
+
534
+ ## Model Card Notes
535
+
536
+ This model card describes the MRP version of the PuoBERTa offensive-content classifier. It should be updated with the exact final test metrics and repository links before public release.