Instructions to use rafiulbiswas/arabertv02-arabic-offensive-detection with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use rafiulbiswas/arabertv02-arabic-offensive-detection with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="rafiulbiswas/arabertv02-arabic-offensive-detection")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("rafiulbiswas/arabertv02-arabic-offensive-detection") model = AutoModelForSequenceClassification.from_pretrained("rafiulbiswas/arabertv02-arabic-offensive-detection", device_map="auto") - Notebooks
- Google Colab
- Kaggle
AraBERTv0.2 for Arabic Offensive Language Detection
This model is fine-tuned from AraBERTv0.2 for binary offensive-language detection in Arabic text.
The model was trained on an Arabic Offensive Language Superset compiled from nine publicly available dataset sources, including Hugging Face and research repositories. After cleaning and deduplication, the combined dataset contains 30,605 Arabic comments, covering offensive and non-offensive language.
Dataset
| Split | Not Offensive | Offensive | Total |
|---|---|---|---|
| Train | 14,401 | 7,022 | 21,423 |
| Validation | 3,086 | 1,505 | 4,591 |
| Test | 3,087 | 1,504 | 4,591 |
| Total | 20,574 | 10,031 | 30,605 |
The dataset was divided using a stratified 70/15/15 split.
Evaluation Results
The model was evaluated on 4,591 held-out test samples.
| Metric | Score |
|---|---|
| Accuracy | 86.67% |
| Macro-F1 | 84.87% |
| Weighted-F1 | 86.67% |
| Offensive Precision | 79.65% |
| Offensive Recall | 79.65% |
| Offensive F1 | 79.65% |
| Non-Offensive F1 | 90.09% |
Training Configuration
The model was fine-tuned using Hugging Face Transformers with a learning rate of 2e-5, batch size of 16, maximum sequence length of 128, and up to 5 epochs. The best checkpoint was selected using validation macro-F1.
Usage
import torch
from transformers import pipeline
from arabert.preprocess import ArabertPreprocessor
model_id = "rafiulbiswas/arabertv02-arabic-offensive-detection"
preprocessor = ArabertPreprocessor(
model_name="aubmindlab/bert-base-arabertv02",
keep_emojis=True,
apply_farasa_segmentation=False
)
classifier = pipeline(
"text-classification",
model=model_id,
device=0 if torch.cuda.is_available() else -1
)
text = "أنت شخص غبي ولا تفهم شيئا"
result = classifier(
preprocessor.preprocess(text),
truncation=True,
max_length=128
)
print(result)
Use the preprocessing shown above if it matches the saved checkpoint's training setup.
Limitations
Performance may vary across Arabic dialects, platforms, and linguistic contexts. The model may misclassify sarcasm, implicit insults, or context-dependent expressions. It is intended for research and human-assisted content moderation rather than fully automated moderation decisions.
Author
Md. Rafiul Biswas, PhD
Hamad Bin Khalifa University, Qatar
- Downloads last month
- 15
Model tree for rafiulbiswas/arabertv02-arabic-offensive-detection
Base model
aubmindlab/bert-base-arabertv02