Text Generation
PEFT
Safetensors
Arabic
arabic
hallucination-detection
cultural-hallucination
lora
sft
icaire
Instructions to use HassanB4/sawb-qwen25 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use HassanB4/sawb-qwen25 with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-7B-Instruct") model = PeftModel.from_pretrained(base_model, "HassanB4/sawb-qwen25") - Notebooks
- Google Colab
- Kaggle
Update model card: fix numbers, improve clarity, add role description
Browse files
README.md
CHANGED
|
@@ -18,15 +18,17 @@ pipeline_tag: text-generation
|
|
| 18 |
library_name: peft
|
| 19 |
---
|
| 20 |
|
| 21 |
-
# Sawb — Qwen2.5-7B-Instruct (LoRA SFT)
|
|
|
|
|
|
|
| 22 |
|
| 23 |
## Overview
|
| 24 |
|
| 25 |
-
**Sawb — Qwen2.5-7B
|
| 26 |
|
| 27 |
-
|
| 28 |
|
| 29 |
-
|
| 30 |
|
| 31 |
## Model Architecture
|
| 32 |
|
|
@@ -38,7 +40,7 @@ Qwen2.5-7B-Instruct fine-tuned with LoRA for Arabic cultural hallucination detec
|
|
| 38 |
| LoRA alpha (α) | 8 |
|
| 39 |
| LoRA dropout | 0.05 |
|
| 40 |
| Target modules | `q_proj`, `k_proj`, `v_proj`, `o_proj`, `gate_proj`, `up_proj`, `down_proj` |
|
| 41 |
-
| Task type |
|
| 42 |
| Parameters (base) | 7B |
|
| 43 |
|
| 44 |
## Training
|
|
@@ -47,13 +49,19 @@ Qwen2.5-7B-Instruct fine-tuned with LoRA for Arabic cultural hallucination detec
|
|
| 47 |
|---|---|
|
| 48 |
| Training examples | 1,828 |
|
| 49 |
| Method | Supervised Fine-Tuning (SFT) |
|
| 50 |
-
| Framework | PEFT
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
## Output Format
|
| 55 |
|
| 56 |
-
The model is trained to
|
| 57 |
|
| 58 |
```json
|
| 59 |
{
|
|
@@ -69,32 +77,28 @@ The model is trained to produce structured JSON output:
|
|
| 69 |
```python
|
| 70 |
from peft import PeftModel
|
| 71 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
|
| 72 |
|
| 73 |
base_model = "Qwen/Qwen2.5-7B-Instruct"
|
| 74 |
adapter = "HassanB4/sawb-qwen25"
|
| 75 |
|
| 76 |
tokenizer = AutoTokenizer.from_pretrained(base_model)
|
| 77 |
-
model = AutoModelForCausalLM.from_pretrained(base_model, torch_dtype=
|
| 78 |
model = PeftModel.from_pretrained(model, adapter)
|
| 79 |
-
|
| 80 |
-
system_prompt = (
|
| 81 |
-
"أنت نظام متخصص في اكتشاف الهلوسة الثقافية في مخرجات نماذج اللغة العربية. "
|
| 82 |
-
"مهمتك: تحليل زوج (سؤال، إجابة) وتحديد ما إذا كانت الإجابة تحتوي على هلوسة ثقافية. "
|
| 83 |
-
"أخرج إجابتك بتنسيق JSON فقط."
|
| 84 |
-
)
|
| 85 |
|
| 86 |
question = "اشرح مفهوم النموذج اللغوي باللهجة النجدية"
|
| 87 |
answer = "النموذج اللغوي هو نظام يستخدم الذكاء الاصطناعي لفهم اللغة..."
|
| 88 |
|
| 89 |
-
user_msg = f"السؤال: {question}\n\nإجابة النموذج: {answer}"
|
| 90 |
-
|
| 91 |
messages = [
|
| 92 |
-
{"role": "system", "content":
|
| 93 |
-
{"role": "user", "content":
|
| 94 |
]
|
| 95 |
|
| 96 |
inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to(model.device)
|
| 97 |
-
|
|
|
|
|
|
|
| 98 |
response = tokenizer.decode(outputs[0][inputs.shape[-1]:], skip_special_tokens=True)
|
| 99 |
print(response)
|
| 100 |
```
|
|
@@ -103,14 +107,6 @@ print(response)
|
|
| 103 |
|
| 104 |
Trained on [HassanB4/sawb-arabic-hallucination-dataset](https://huggingface.co/datasets/HassanB4/sawb-arabic-hallucination-dataset).
|
| 105 |
|
| 106 |
-
The dataset covers 6 hallucination categories:
|
| 107 |
-
- `ethical_framework_mismatch`
|
| 108 |
-
- `religious_misrepresentation`
|
| 109 |
-
- `historical_inaccuracy`
|
| 110 |
-
- `social_norms_violation`
|
| 111 |
-
- `dialectal_confusion`
|
| 112 |
-
- `regional_context_errors`
|
| 113 |
-
|
| 114 |
## Collection
|
| 115 |
|
| 116 |
-
|
|
|
|
| 18 |
library_name: peft
|
| 19 |
---
|
| 20 |
|
| 21 |
+
# Sawb — Qwen2.5-7B-Instruct (LoRA SFT — Research Baseline)
|
| 22 |
+
|
| 23 |
+
Part of the **[Sawb Arabic Cultural Hallucination Detection Collection](https://huggingface.co/collections/HassanB4/sawb-arabic-cultural-hallucination-detection)** for ICAIRE 2026 Track 3.
|
| 24 |
|
| 25 |
## Overview
|
| 26 |
|
| 27 |
+
**Sawb — Qwen2.5-7B** is a LoRA adapter fine-tuned from [Qwen/Qwen2.5-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-7B-Instruct) (7B parameters) for Arabic cultural hallucination detection and explanation. This model is released as a **research baseline** evaluated during the Sawb system development.
|
| 28 |
|
| 29 |
+
It achieved a macro F1 of **0.5556** on the 457-example validation set — significantly below the Arabic BERT encoder models (F1 = 0.9246–0.9647) and below the DeepSeek-based pipeline. The underperformance is attributed to Qwen2.5-7B lacking the deep Arabic dialectal and Islamic cultural knowledge needed for the most challenging hallucination categories (dialectal confusion, religious misrepresentation).
|
| 30 |
|
| 31 |
+
For production use, see the primary detection model: [HassanB4/sawb](https://huggingface.co/HassanB4/sawb) (AraBERT-Large + Glossary, F1=0.9246).
|
| 32 |
|
| 33 |
## Model Architecture
|
| 34 |
|
|
|
|
| 40 |
| LoRA alpha (α) | 8 |
|
| 41 |
| LoRA dropout | 0.05 |
|
| 42 |
| Target modules | `q_proj`, `k_proj`, `v_proj`, `o_proj`, `gate_proj`, `up_proj`, `down_proj` |
|
| 43 |
+
| Task type | Causal Language Modeling |
|
| 44 |
| Parameters (base) | 7B |
|
| 45 |
|
| 46 |
## Training
|
|
|
|
| 49 |
|---|---|
|
| 50 |
| Training examples | 1,828 |
|
| 51 |
| Method | Supervised Fine-Tuning (SFT) |
|
| 52 |
+
| Framework | PEFT + TRL |
|
| 53 |
+
|
| 54 |
+
## Evaluation Results
|
| 55 |
+
|
| 56 |
+
| Metric | Value |
|
| 57 |
+
|---|---|
|
| 58 |
+
| Macro F1 (validation) | **0.5556** |
|
| 59 |
+
| Task | Binary classification (hallucination / not) |
|
| 60 |
+
| Evaluation set | 457 Arabic (question, LLM answer) pairs |
|
| 61 |
|
| 62 |
## Output Format
|
| 63 |
|
| 64 |
+
The model is trained to output structured JSON:
|
| 65 |
|
| 66 |
```json
|
| 67 |
{
|
|
|
|
| 77 |
```python
|
| 78 |
from peft import PeftModel
|
| 79 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 80 |
+
import torch
|
| 81 |
|
| 82 |
base_model = "Qwen/Qwen2.5-7B-Instruct"
|
| 83 |
adapter = "HassanB4/sawb-qwen25"
|
| 84 |
|
| 85 |
tokenizer = AutoTokenizer.from_pretrained(base_model)
|
| 86 |
+
model = AutoModelForCausalLM.from_pretrained(base_model, torch_dtype=torch.float16, device_map="auto")
|
| 87 |
model = PeftModel.from_pretrained(model, adapter)
|
| 88 |
+
model.eval()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
question = "اشرح مفهوم النموذج اللغوي باللهجة النجدية"
|
| 91 |
answer = "النموذج اللغوي هو نظام يستخدم الذكاء الاصطناعي لفهم اللغة..."
|
| 92 |
|
|
|
|
|
|
|
| 93 |
messages = [
|
| 94 |
+
{"role": "system", "content": "أنت محكم متخصص في الكشف عن الهلوسة الثقافية. أخرج JSON فقط."},
|
| 95 |
+
{"role": "user", "content": f"السؤال: {question}\n\nإجابة النموذج: {answer}"},
|
| 96 |
]
|
| 97 |
|
| 98 |
inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to(model.device)
|
| 99 |
+
with torch.no_grad():
|
| 100 |
+
outputs = model.generate(inputs, max_new_tokens=256, temperature=0.1, do_sample=True)
|
| 101 |
+
|
| 102 |
response = tokenizer.decode(outputs[0][inputs.shape[-1]:], skip_special_tokens=True)
|
| 103 |
print(response)
|
| 104 |
```
|
|
|
|
| 107 |
|
| 108 |
Trained on [HassanB4/sawb-arabic-hallucination-dataset](https://huggingface.co/datasets/HassanB4/sawb-arabic-hallucination-dataset).
|
| 109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
## Collection
|
| 111 |
|
| 112 |
+
[Sawb Arabic Cultural Hallucination Detection](https://huggingface.co/collections/HassanB4/sawb-arabic-cultural-hallucination-detection)
|