Downloads · 30 days
0
rahaf088/arabic-hate-speech-marbert-lora
arabic-hate-speech-marbert-lora is a machine learning model from rahaf088. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for transformers.
A binary text classifier that flags Arabic text as hate or nothate, fine-tuned from MARBERT using LoRA (parameter-efficient fine-tuning).
Downloads · 30 days
0
Access
Public
Updated Sep 14, 2026
Repo size
1.2 MB
Likes
0
Public
Click a slice to open those files.
.safetensors1.2 MB · 99%
From the Hugging Face model README
A binary text classifier that flags Arabic text as hate or not_hate, fine-tuned from MARBERT using LoRA (parameter-efficient fine-tuning).
Classifying a single piece of Arabic text as containing hate/offensive speech or not — for research, prototyping, or as one signal in a moderation pipeline.
Content moderation triage, customer-support message flagging, or classroom anti-bullying monitoring (tracking repeated flagged messages per user rather than reading every message manually).
Not designed to identify the type, severity, or target of offensive content, and not suitable as the sole, fully automated basis for removing content or taking action against a user — see Limitations below.
not_hate examples were misclassified as hate (false positives), and about 16% of true hate examples were missed (false negatives).Use with a human-in-the-loop review step rather than as an automated final decision-maker, especially for moderation actions that affect real users.
from peft import PeftModel
from transformers import AutoModelForSequenceClassification, AutoTokenizer
base_model = AutoModelForSequenceClassification.from_pretrained("UBC-NLP/MARBERT", num_labels=2)
model = PeftModel.from_pretrained(base_model, "rahaf088/arabic-hate-speech-marbert-lora")
tokenizer = AutoTokenizer.from_pretrained("UBC-NLP/MARBERT")
text = "مثال على نص عربي"
inputs = tokenizer(text, truncation=True, padding="max_length", max_length=40, return_tensors="pt")
logits = model(**inputs).logits
prediction = logits.argmax(-1).item() # 0 = not_hate, 1 = hate
Three Arabic sources merged, de-duplicated, and relabeled into a binary schema (hate / not_hate): L-HSAB (Levantine hate speech and abusive language dataset), a general Arabic hate/offensive-speech training set, and an Arabic Twitter dataset. Text was cleaned (diacritics and elongation removed, non-Arabic characters and URLs stripped, alef variants normalized) and split 80/10/10 into train/validation/test, stratified jointly by source and label.
Diacritic removal, tatweel (elongation) removal, URL and non-Arabic character stripping, alef normalization, whitespace cleanup.
sklearn balanced class weights)296,450 trainable parameters out of 163,139,332 (0.18% of the base model). Full training run: ~4 minutes on a single Colab GPU.
A held-out 10% stratified split of the combined dataset, not seen during training or checkpoint selection.
Accuracy, precision, recall, and macro-F1, plus F1 per class (hate, not_hate).
| Metric | Score |
|---|---|
| Accuracy | 0.828 |
| Macro-F1 | 0.827 |
| F1 (not_hate) | 0.817 |
| F1 (hate) | 0.837 |
Test-set results are within ~1 point of validation-set results across all metrics, indicating the model generalizes rather than overfitting to the training data.
BERT-based encoder (MARBERT) with a linear binary classification head; class-weighted cross-entropy objective; LoRA low-rank adapters inserted into the attention layers instead of updating all base-model weights.
Google Colab GPU
transformers, peft, torch, scikit-learn, wandb
Rahaf Alruwaithi