Views
No views yet
| 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 |
pip install transformers torch1from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
2import torch
3
4# Method 1: Using pipeline (Recommended)
5classifier = pipeline(
6 "text-classification",
7 model="sabaridsnfuji/arabic-ai-text-detector",
8 tokenizer="sabaridsnfuji/arabic-ai-text-detector"
9)
10
11# Test with Arabic text
12arabic_text = "هذا مثال على نص باللغة العربية"
13result = classifier(arabic_text)
14
15print(f"Prediction: {result[0]['label']}")
16print(f"Confidence: {result[0]['score']:.2%}")1# Method 2: Manual prediction with probabilities
2model_name = "sabaridsnfuji/arabic-ai-text-detector"
3tokenizer = AutoTokenizer.from_pretrained(model_name)
4model = AutoModelForSequenceClassification.from_pretrained(model_name)
5
6def predict_arabic_text(text):
7 # Tokenize
8 inputs = tokenizer(
9 text,
10 return_tensors="pt",
11 truncation=True,
12 max_length=512,
13 padding=True
14 )
15
16 # Predict
17 with torch.no_grad():
18 outputs = model(**inputs)
19 probabilities = torch.nn.functional.softmax(outputs.logits, dim=-1)
20
21 # Get results
22 predicted_class = torch.argmax(probabilities, dim=1).item()
23 confidence = torch.max(probabilities, dim=1)[0].item()
24
25 labels = {0: "HUMAN", 1: "AI"}
26
27 return {
28 "prediction": labels[predicted_class],
29 "confidence": confidence,
30 "probabilities": {
31 "human": probabilities[0][0].item(),
32 "ai": probabilities[0][1].item()
33 }
34 }
35
36# Example usage
37text = "النص العربي المراد تصنيفه هنا"
38result = predict_arabic_text(text)
39print(result)1# Process multiple texts efficiently
2texts = [
3 "النص الأول باللغة العربية",
4 "النص الثاني للتصنيف",
5 "المزيد من النصوص العربية"
6]
7
8results = classifier(texts)
9for text, result in zip(texts, results):
10 print(f"Text: {text[:50]}...")
11 print(f"Prediction: {result['label']} ({result['score']:.2%})")
12 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 |
1# Input
2{
3 "text": "النص العربي المراد تصنيفه",
4 "max_length": 512
5}
6
7# Output
8{
9 "label": "HUMAN" | "AI",
10 "score": 0.95, # Confidence score
11 "probabilities": {
12 "HUMAN": 0.95,
13 "AI": 0.05
14 }
15}1news_text = '''
2أعلنت وزارة التعليم عن إطلاق برنامج جديد لتطوير المناهج الدراسية
3في المرحلة الثانوية، والذي يهدف إلى تعزيز مهارات الطلاب في التفكير
4النقدي والإبداع. ويأتي هذا البرنامج ضمن رؤية 2030 لتطوير التعليم.
5'''
6
7result = classifier(news_text)
8# Expected: HUMAN (news articles are typically human-written)1ai_text = '''
2في هذا المقال، سنناقش موضوع التكنولوجيا. التكنولوجيا مهمة جداً في
3حياتنا. يجب أن نفهم التكنولوجيا بشكل صحيح. التكنولوجيا تساعدنا كثيراً.
4'''
5
6result = classifier(ai_text)
7# Expected: AI (repetitive patterns typical of AI generation)1@misc{sabaridsnfuji-arabic-ai-detector-20250730,
2 title={Arabic AI Text Detection Model},
3 author={sabaridsnfuji},
4 year={2025},
5 publisher={Hugging Face},
6 journal={Hugging Face Model Hub},
7 howpublished={\url{https://huggingface.co/sabaridsnfuji/arabic-ai-text-detector}}
8}