--- language: - ary - ar license: cc-by-nc-4.0 library_name: transformers pipeline_tag: text-classification base_model: SI2M-Lab/DarijaBERT tags: - toxicity-detection - content-moderation - offensive-language - moroccan-darija - darija - low-resource-languages - bert datasets: - OMCD_TypicaAI_Mix metrics: - accuracy - f1 model-index: - name: DarijaToxicityDetector (binary) results: - task: type: text-classification name: Toxicity Detection (binary) dataset: name: OMCD_Typica.ai_Mix (test split) type: OMCD_Typica.ai_Mix metrics: - type: accuracy value: 0.8307 name: Accuracy - type: f1 value: 0.8308 name: Weighted F1 widget: - text: "هاد الفيديو ما عجبنيش بزاف" example_title: "Clean: content criticism" - text: "مول هاد الفيديو باسل وما مربّيش" example_title: "Offensive: personal attack" - text: "هاد الإنفلونسر مكلّخ غير كيخربق" example_title: "Offensive: personal attack" --- # DarijaToxicityDetector — Moroccan Darija Toxicity Detection (Binary) **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. 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**. > 📄 **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. ## Model Details | | | |---|---| | **Developed by** | Hicham Assoudi — Typica.ai | | **Model type** | BERT-based sequence classification (binary) | | **Language** | Moroccan Darija (`ary`), Arabic script | | **Base model** | [SI2M-Lab/DarijaBERT](https://huggingface.co/SI2M-Lab/DarijaBERT) | | **License** | CC BY-NC 4.0 (non-commercial — education & research) | | **Paper** | [arXiv:2505.04640](https://arxiv.org/abs/2505.04640) | | **Contact** | assoudi@typica.ai | ### Labels | id | label | meaning | |----|-------|---------| | 0 | `clean` | Non-toxic content | | 1 | `offensive` | Toxic content (insults, hate, obscenity, culturally embedded aggression) | ## Intended Uses **Direct intended uses:** - Research on toxicity detection and content moderation for low-resource languages and Arabic dialects. - Education: teaching NLP fine-tuning, evaluation, and culturally adapted model design. - Benchmarking against general-purpose moderation systems (see companion paper). - Prototyping moderation pipelines for Moroccan Darija user-generated content (comments, social media, forums). **Out-of-scope uses:** - ❌ Commercial deployment without a separate agreement with Typica.ai (license is non-commercial). - ❌ Fully automated moderation decisions without human review — the model produces errors, especially on sarcasm. - ❌ Text dominated by Latin script (Arabizi, French, English): such content was filtered out of training data. - ❌ Other Arabic dialects or MSA — performance is not guaranteed outside Moroccan Darija. ## How to Use ```python from transformers import pipeline classifier = pipeline( "text-classification", model="TypicaAI/DarijaToxicityDetector", ) texts = [ "هاد الفيديو ما عجبنيش بزاف", # expected: clean "مول هاد الفيديو باسل وما مربّيش", # expected: offensive "هاد الإنفلونسر مكلّخ غير كيخربق" # expected: offensive ] print(classifier(texts, truncation=True, max_length=512)) # [{'label': 'clean', 'score': ...}, {'label': 'offensive', 'score': ...}] ``` ## Training Data: OMCD_Typica.ai_Mix The model was trained on **OMCD_Typica.ai_Mix** (12,758 Moroccan Darija comments), built as follows: - **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. - **Enrichment:** Typica.ai proprietary annotations covering *culturally embedded* toxicity — indirect insults, sarcasm, euphemisms, and culturally specific aggression that general-purpose models frequently miss. - **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. - **Balancing:** random undersampling of the majority (clean) class to reach a **1:1 clean/offensive ratio**, preventing majority-class bias. ### Splits | Split | Examples | Used for | |-------|---------:|----------| | Train | 9,568 | Fine-tuning | | Validation | 2,552 | Best-checkpoint selection | | Test | 638 | Final evaluation & paper benchmark | Each example carries `sentence`, `label` (ClassLabel: `clean`/`offensive`), `idx`, and `origin` (source provenance) fields. > 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. ## Training Procedure - **Base checkpoint:** `SI2M-Lab/DarijaBERT` - **Objective:** binary sequence classification (cross-entropy) - **Tokenization:** DarijaBERT tokenizer, truncation at `max_length=512`, dynamic padding (`DataCollatorWithPadding`) **Hyperparameters:** | Hyperparameter | Value | |---|---| | Learning rate | 2e-5 | | Train batch size | 16 | | Eval batch size | 8 | | Epochs | 10 | | Weight decay | 0.01 | | Eval/save strategy | per epoch, best model restored at end | ## Evaluation ### Held-out test set (638 examples, balanced) | Metric | Score | |---|---:| | Accuracy | **0.8307** | | Weighted F1 | **0.8308** | ### Benchmark vs. commercial moderation APIs **Original benchmark** — from the [companion paper](https://arxiv.org/abs/2505.04640) (May 2025), on the OMCD_Typica.ai_Mix test split (n = 630): | Model | Accuracy | Macro F1 | Toxic F1 | Not-Toxic F1 | |---|---:|---:|---:|---:| | **Typica.ai (this line of models)** | **0.830** | **0.830** | **0.834** | **0.827** | | OpenAI (omni-moderation-latest) | 0.652 | 0.644 | 0.589 | 0.699 | | Mistral (mistral-moderation-latest) | 0.649 | 0.641 | 0.588 | 0.694 | | Anthropic Claude (claude-3-haiku-20240307) | 0.659 | 0.617 | 0.743 | 0.492 | **Updated re-run** — July 2026, same gold test set (n = 630, balanced), same inputs to all APIs, using each provider's then-current moderation endpoint (weighted precision / recall / F1): | Model | Precision | Recall | F1-score | |---|---:|---:|---:| | **Typica.ai (custom BERT-based model)** | **0.832** | **0.830** | **0.830** | | Anthropic Claude (claude-haiku-4-5-20251001) | 0.695 | 0.657 | 0.646 | | OpenAI (omni-moderation-latest) | 0.692 | 0.630 | 0.607 | | Mistral (mistral-moderation-latest) | 0.633 | 0.592 | 0.571 | Fourteen months after the original benchmark, the performance gap persists even against newer commercial models: the culturally adapted classifier still leads by ~18+ F1 points. General-purpose APIs continue to miss culturally nuanced toxicity (indirect insults, sarcasm, cultural idioms), while the specialized model maintains the best balance between catching toxic content and avoiding false positives. ## Limitations & Bias - **Cross-dialectal noise:** source data may include some non-Moroccan Arabic dialect examples. - **Annotation subjectivity:** toxicity is culturally shaped; annotator judgment introduces some variance. - **Sarcasm false positives:** highly sarcastic but benign messages can be flagged as offensive. - **Script coverage:** Arabic script only; Arabizi/Latin-script Darija is out of scope. - **Temporal drift:** online toxic language evolves; periodic re-training is recommended. ## Ethical Considerations 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. ## Citation If you use this model, please cite: ```bibtex @article{assoudi2025comparative, title = {A Comparative Benchmark of a Moroccan Darija Toxicity Detection Model (Typica.ai) and Major LLM-Based Moderation APIs (OpenAI, Mistral, Anthropic)}, author = {Assoudi, Hicham}, journal = {arXiv preprint arXiv:2505.04640}, year = {2025}, url = {https://arxiv.org/abs/2505.04640} } ``` ## Contact **Hicham Assoudi** — Founder & Applied AI Researcher, Typica.ai · PhD (AI/NLP) *Typica.ai* — Independent applied research initiative 📧 assoudi@typica.ai · [Linkedin](https://www.linkedin.com/in/assoudi) . 🌐 [typica.ai](https://typica.ai) · 🤗 [TypicaAI on Hugging Face](https://huggingface.co/TypicaAI)