hassoudi commited on
Commit
6b60d91
·
verified ·
1 Parent(s): 9b6d56a

Add model card (dataset docs, benchmark, citation arXiv:2505.04640)

Browse files
Files changed (1) hide show
  1. README.md +164 -150
README.md CHANGED
@@ -1,199 +1,213 @@
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
+ - ary
4
+ - ar
5
+ license: cc-by-nc-4.0
6
  library_name: transformers
7
+ pipeline_tag: text-classification
8
+ base_model: SI2M-Lab/DarijaBERT
9
+ tags:
10
+ - toxicity-detection
11
+ - content-moderation
12
+ - offensive-language
13
+ - moroccan-darija
14
+ - darija
15
+ - low-resource-languages
16
+ - bert
17
+ datasets:
18
+ - OMCD_TypicaAI_Mix
19
+ metrics:
20
+ - accuracy
21
+ - f1
22
+ model-index:
23
+ - name: DarijaToxicityDetector (binary)
24
+ results:
25
+ - task:
26
+ type: text-classification
27
+ name: Toxicity Detection (binary)
28
+ dataset:
29
+ name: OMCD_Typica.ai_Mix (test split)
30
+ type: OMCD_Typica.ai_Mix
31
+ metrics:
32
+ - type: accuracy
33
+ value: 0.8307
34
+ name: Accuracy
35
+ - type: f1
36
+ value: 0.8308
37
+ name: Weighted F1
38
+ widget:
39
+ - text: "هاد الفيديو ما عجبنيش بزاف"
40
+ example_title: "Clean: content criticism"
41
+ - text: "مول هاد الفيديو باسل وما مربّيش"
42
+ example_title: "Offensive: personal attack"
43
+ - text: "هاد الإنفلونسر مكلّخ غير كيخربق"
44
+ example_title: "Offensive: personal attack"
45
+
46
  ---
47
 
48
+ # DarijaToxicityDetector Moroccan Darija Toxicity Detection (Binary)
49
 
50
+ **DarijaToxicityDetector** is a BERT-based binary text classifier that detects toxic / offensive content in **Moroccan Darija** (Moroccan Arabic dialect, written in Arabic script). It is fine-tuned from [SI2M-Lab/DarijaBERT](https://huggingface.co/SI2M-Lab/DarijaBERT) on the **OMCD_Typica.ai_Mix** dataset, a curated blend of the public OMCD dataset and Typica.ai's proprietary culturally grounded annotations.
51
 
52
+ The model is released by [Typica.ai](https://typica.ai) as part of its applied research on **culturally localized AI for underserved languages**, and is **open-sourced for educational and research purposes**.
53
 
54
+ > 📄 **Companion paper:** [A Comparative Benchmark of a Moroccan Darija Toxicity Detection Model (Typica.ai) and Major LLM-Based Moderation APIs (OpenAI, Mistral, Anthropic)](https://arxiv.org/abs/2505.04640) — the benchmark shows that this culturally adapted model outperforms general-purpose LLM moderation APIs on Moroccan Darija toxicity detection.
55
 
56
  ## Model Details
57
 
58
+ | | |
59
+ |---|---|
60
+ | **Developed by** | Hicham Assoudi Typica.ai |
61
+ | **Model type** | BERT-based sequence classification (binary) |
62
+ | **Language** | Moroccan Darija (`ary`), Arabic script |
63
+ | **Base model** | [SI2M-Lab/DarijaBERT](https://huggingface.co/SI2M-Lab/DarijaBERT) |
64
+ | **License** | CC BY-NC 4.0 (non-commercial — education & research) |
65
+ | **Paper** | [arXiv:2505.04640](https://arxiv.org/abs/2505.04640) |
66
+ | **Contact** | assoudi@typica.ai |
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
68
+ ### Labels
69
 
70
+ | id | label | meaning |
71
+ |----|-------|---------|
72
+ | 0 | `clean` | Non-toxic content |
73
+ | 1 | `offensive` | Toxic content (insults, hate, obscenity, culturally embedded aggression) |
74
 
75
+ ## Intended Uses
76
 
77
+ **Direct intended uses:**
78
+ - Research on toxicity detection and content moderation for low-resource languages and Arabic dialects.
79
+ - Education: teaching NLP fine-tuning, evaluation, and culturally adapted model design.
80
+ - Benchmarking against general-purpose moderation systems (see companion paper).
81
+ - Prototyping moderation pipelines for Moroccan Darija user-generated content (comments, social media, forums).
82
 
83
+ **Out-of-scope uses:**
84
+ - ❌ Commercial deployment without a separate agreement with Typica.ai (license is non-commercial).
85
+ - ❌ Fully automated moderation decisions without human review — the model produces errors, especially on sarcasm.
86
+ - ❌ Text dominated by Latin script (Arabizi, French, English): such content was filtered out of training data.
87
+ - ❌ Other Arabic dialects or MSA — performance is not guaranteed outside Moroccan Darija.
88
 
89
+ ## How to Use
90
 
91
+ ```python
92
+ from transformers import pipeline
93
 
94
+ classifier = pipeline(
95
+ "text-classification",
96
+ model="TypicaAI/DarijaToxicityDetector",
97
+ )
98
 
99
+ texts = [
100
+ "هاد الفيديو ما عجبنيش بزاف", # expected: clean
101
+ "مول هاد الفيديو باسل وما مربّيش", # expected: offensive
102
+ "هاد الإنفلونسر مكلّخ غير كيخربق" # expected: offensive
103
+ ]
104
+ print(classifier(texts, truncation=True, max_length=512))
105
+ # [{'label': 'clean', 'score': ...}, {'label': 'offensive', 'score': ...}]
106
+ ```
107
 
108
+ ## Training Data: OMCD_Typica.ai_Mix
109
 
110
+ The model was trained on **OMCD_Typica.ai_Mix** (12,758 Moroccan Darija comments), built as follows:
111
 
112
+ - **Backbone:** [OMCD Offensive Moroccan Comments Dataset](https://doi.org/10.1007/s10579-023-09663-2) (Essefar et al., 2023), a widely cited, well-annotated public resource for Darija toxicity research.
113
+ - **Enrichment:** Typica.ai proprietary annotations covering *culturally embedded* toxicity — indirect insults, sarcasm, euphemisms, and culturally specific aggression that general-purpose models frequently miss.
114
+ - **Preprocessing:** sentences with >50% Latin-script characters were removed (to exclude French/English/Arabizi-dominated code-switching); Latin characters, symbols, and punctuation were cleaned while preserving linguistic meaning.
115
+ - **Balancing:** random undersampling of the majority (clean) class to reach a **1:1 clean/offensive ratio**, preventing majority-class bias.
116
 
117
+ ### Splits
118
 
119
+ | Split | Examples | Used for |
120
+ |-------|---------:|----------|
121
+ | Train | 9,568 | Fine-tuning |
122
+ | Validation | 2,552 | Best-checkpoint selection |
123
+ | Test | 638 | Final evaluation & paper benchmark |
124
 
125
+ Each example carries `sentence`, `label` (ClassLabel: `clean`/`offensive`), `idx`, and `origin` (source provenance) fields.
126
 
127
+ > The test split is publicly available for reproducibility in the [benchmark GitHub repository](https://github.com/assoudi-typica-ai/darija-toxicity-benchmark). The proprietary training annotations are not released.
128
 
129
+ ## Training Procedure
130
 
131
+ - **Base checkpoint:** `SI2M-Lab/DarijaBERT`
132
+ - **Objective:** binary sequence classification (cross-entropy)
133
+ - **Tokenization:** DarijaBERT tokenizer, truncation at `max_length=512`, dynamic padding (`DataCollatorWithPadding`)
134
 
135
+ **Hyperparameters:**
136
 
137
+ | Hyperparameter | Value |
138
+ |---|---|
139
+ | Learning rate | 2e-5 |
140
+ | Train batch size | 16 |
141
+ | Eval batch size | 8 |
142
+ | Epochs | 10 |
143
+ | Weight decay | 0.01 |
144
+ | Eval/save strategy | per epoch, best model restored at end |
 
 
 
 
 
 
 
 
145
 
146
  ## Evaluation
147
 
148
+ ### Held-out test set (638 examples, balanced)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
 
150
+ | Metric | Score |
151
+ |---|---:|
152
+ | Accuracy | **0.8307** |
153
+ | Weighted F1 | **0.8308** |
154
 
155
+ ### Benchmark vs. commercial moderation APIs
156
 
157
+ From the [companion paper](https://arxiv.org/abs/2505.04640), on the same OMCD_Typica.ai_Mix test split:
158
 
159
+ | Model | Accuracy | Macro F1 | Toxic F1 | Not-Toxic F1 |
160
+ |---|---:|---:|---:|---:|
161
+ | **Typica.ai (this line of models)** | **0.830** | **0.830** | **0.834** | **0.827** |
162
+ | OpenAI (omni-moderation-latest) | 0.652 | 0.644 | 0.589 | 0.699 |
163
+ | Mistral (mistral-moderation-latest) | 0.649 | 0.641 | 0.588 | 0.694 |
164
+ | Anthropic Claude (claude-3-haiku-20240307) | 0.659 | 0.617 | 0.743 | 0.492 |
165
 
166
+ The culturally adapted model achieves the best balance between catching toxic content and avoiding false positives — the general-purpose APIs miss much culturally nuanced toxicity (indirect insults, sarcasm, cultural idioms), while prompt-driven LLM moderation tends to over-flag benign content.
167
 
168
+ ## Limitations & Bias
169
 
170
+ - **Cross-dialectal noise:** source data may include some non-Moroccan Arabic dialect examples.
171
+ - **Annotation subjectivity:** toxicity is culturally shaped; annotator judgment introduces some variance.
172
+ - **Sarcasm false positives:** highly sarcastic but benign messages can be flagged as offensive.
173
+ - **Script coverage:** Arabic script only; Arabizi/Latin-script Darija is out of scope.
174
+ - **Temporal drift:** online toxic language evolves; periodic re-training is recommended.
175
 
176
+ ## Ethical Considerations
177
 
178
+ This model deals with offensive content by design. It should support — not replace — human moderation. Misclassification can silence legitimate speech (false positives) or expose users to harm (false negatives). Deployers should implement human-in-the-loop review, appeal mechanisms, and threshold calibration appropriate to their community norms.
179
 
180
+ ## Citation
181
 
182
+ If you use this model, please cite:
183
 
184
+ ```bibtex
185
+ @article{assoudi2025comparative,
186
+ title = {A Comparative Benchmark of a Moroccan Darija Toxicity Detection Model (Typica.ai) and Major LLM-Based Moderation APIs (OpenAI, Mistral, Anthropic)},
187
+ author = {Assoudi, Hicham},
188
+ journal = {arXiv preprint arXiv:2505.04640},
189
+ year = {2025},
190
+ url = {https://arxiv.org/abs/2505.04640}
191
+ }
192
+ ```
193
 
194
+ Please also cite the OMCD dataset the training data builds upon:
195
 
196
+ ```bibtex
197
+ @article{essefar2023omcd,
198
+ title = {OMCD: Offensive Moroccan Comments Dataset},
199
+ author = {Essefar, Kabil and Ait Baha, Hassan and El Mahdaouy, Abdelkader and El Mekki, Abdellah and Berrada, Ismail},
200
+ journal = {Language Resources and Evaluation},
201
+ volume = {57},
202
+ number = {4},
203
+ pages = {1745--1765},
204
+ year = {2023},
205
+ doi = {10.1007/s10579-023-09663-2}
206
+ }
207
+ ```
208
 
209
+ ## Contact
210
 
211
+ **Hicham Assoudi** — Founder & Applied AI Researcher, Typica.ai · PhD (AI/NLP)
212
+ *Typica.ai* — Independent applied research initiative
213
+ 📧 assoudi@typica.ai · [Linkedin](https://www.linkedin.com/in/assoudi) . 🌐 [typica.ai](https://typica.ai) · 🤗 [TypicaAI on Hugging Face](https://huggingface.co/TypicaAI)