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
aubmindlab/bert-base-arabertv2