Arabic AI vs Human Text Detection Model - Fine-tuned AraBERT
This model is specifically designed to detect AI-generated text in Arabic language. It's fine-tuned from aubmindlab/bert-base-arabertv2 and can distinguish between:
The model was trained using advanced validation techniques with early stopping to ensure optimal performance and prevent overfitting.
| Metric | Score | Description |
|---|---|---|
| 🎯 Accuracy | 95.0% | Overall classification accuracy |
| ⚖️ Precision | 95.0% | Precision across both classes |
| 🎪 Recall | 94.0% | Recall across both classes |
| 🏆 F1 Score | 94.0% | Harmonic mean of precision and recall |
Evaluated on a balanced validation set with equal human and AI-generated Arabic texts.
pip install transformers torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
import torch
# Method 1: Using pipeline (Recommended)
classifier = pipeline(
"text-classification",
model="sabaridsnfuji/arabic-ai-text-detector",
tokenizer="sabaridsnfuji/arabic-ai-text-detector"
)
# Test with Arabic text
arabic_text = "هذا مثال على نص باللغة العربية"
result = classifier(arabic_text)
print(f"Prediction: {result[0]['label']}")
print(f"Confidence: {result[0]['score']:.2%}")
# Method 2: Manual prediction with probabilities
model_name = "sabaridsnfuji/arabic-ai-text-detector"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
def predict_arabic_text(text):
# Tokenize
inputs = tokenizer(
text,
return_tensors="pt",
truncation=True,
max_length=512,
padding=True
)
# Predict
with torch.no_grad():
outputs = model(**inputs)
probabilities = torch.nn.functional.softmax(outputs.logits, dim=-1)
# Get results
predicted_class = torch.argmax(probabilities, dim=1).item()
confidence = torch.max(probabilities, dim=1)[0].item()
labels = {0: "HUMAN", 1: "AI"}
return {
"prediction": labels[predicted_class],
"confidence": confidence,
"probabilities": {
"human": probabilities[0][0].item(),
"ai": probabilities[0][1].item()
}
}
# Example usage
text = "النص العربي المراد تصنيفه هنا"
result = predict_arabic_text(text)
print(result)
# Process multiple texts efficiently
texts = [
"النص الأول باللغة العربية",
"النص الثاني للتصنيف",
"المزيد من النصوص العربية"
]
results = classifier(texts)
for text, result in zip(texts, results):
print(f"Text: {text[:50]}...")
print(f"Prediction: {result['label']} ({result['score']:.2%})")
print("-" * 50)
AraBERT-v2 Base Architecture
├── 📥 Input: Arabic text (max 512 tokens)
├── 🔤 Tokenizer: AraBERT Arabic tokenizer
├── 🧠 Encoder: 12-layer Transformer (110M parameters)
├── 🎯 Classifier: Linear layer (768 → 2 classes)
└── 📤 Output: [Human, AI] classification + probabilities
| Model | Accuracy | Notes |
|---|---|---|
| This Model | 95.0% | Step-by-step trained AraBERT |
| GPTZero | 62.7% | On AIRABIC benchmark |
| Random Baseline | 50.0% | Random classification |
# Input
{
"text": "النص العربي المراد تصنيفه",
"max_length": 512
}
# Output
{
"label": "HUMAN" | "AI",
"score": 0.95, # Confidence score
"probabilities": {
"HUMAN": 0.95,
"AI": 0.05
}
}
news_text = '''
أعلنت وزارة التعليم عن إطلاق برنامج جديد لتطوير المناهج الدراسية
في المرحلة الثانوية، والذي يهدف إلى تعزيز مهارات الطلاب في التفكير
النقدي والإبداع. ويأتي هذا البرنامج ضمن رؤية 2030 لتطوير التعليم.
'''
result = classifier(news_text)
# Expected: HUMAN (news articles are typically human-written)
ai_text = '''
في هذا المقال، سنناقش موضوع التكنولوجيا. التكنولوجيا مهمة جداً في
حياتنا. يجب أن نفهم التكنولوجيا بشكل صحيح. التكنولوجيا تساعدنا كثيراً.
'''
result = classifier(ai_text)
# Expected: AI (repetitive patterns typical of AI generation)
If you use this model in your research or applications, please cite:
@misc{sabaridsnfuji-arabic-ai-detector-20250730,
title={Arabic AI Text Detection Model},
author={sabaridsnfuji},
year={2025},
publisher={Hugging Face},
journal={Hugging Face Model Hub},
howpublished={\url{https://huggingface.co/sabaridsnfuji/arabic-ai-text-detector}}
}
This model is released under the Apache 2.0 license. You are free to:
🌟 If this model helps your work, please give it a ⭐ star! 🌟
Built with ❤️ for the Arabic NLP community
Last updated: 2025-07-30