HassanB4 commited on
Commit
e0f6779
·
verified ·
1 Parent(s): 2daee25

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +116 -0
  2. adapter_config.json +48 -0
  3. adapter_model.safetensors +3 -0
README.md ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - ar
5
+ base_model: Qwen/Qwen2.5-7B-Instruct
6
+ datasets:
7
+ - HassanB4/sawb-arabic-hallucination-dataset
8
+ tags:
9
+ - text-generation
10
+ - arabic
11
+ - hallucination-detection
12
+ - cultural-hallucination
13
+ - lora
14
+ - sft
15
+ - peft
16
+ - icaire
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-Instruct (LoRA SFT)** is an Arabic-language generative model for detecting and *explaining* cultural hallucinations in LLM outputs. A cultural hallucination occurs when an LLM produces a response that is factually or culturally incorrect within Arab/Islamic contexts.
26
+
27
+ This model is a LoRA adapter fine-tuned from [Qwen/Qwen2.5-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-7B-Instruct) (7B parameters) using supervised fine-tuning (SFT) on the [Sawb Arabic Cultural Hallucination Dataset](https://huggingface.co/datasets/HassanB4/sawb-arabic-hallucination-dataset).
28
+
29
+ Qwen2.5-7B-Instruct fine-tuned with LoRA for Arabic cultural hallucination detection and explanation. Produces structured JSON output with hallucination label, category, and Arabic explanation.
30
+
31
+ ## Model Architecture
32
+
33
+ | Property | Value |
34
+ |---|---|
35
+ | Base model | `Qwen/Qwen2.5-7B-Instruct` |
36
+ | Fine-tuning method | LoRA (Low-Rank Adaptation) |
37
+ | LoRA rank (r) | 8 |
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 | `CAUSAL_LM` |
42
+ | Parameters (base) | 7B |
43
+
44
+ ## Training
45
+
46
+ | Hyperparameter | Value |
47
+ |---|---|
48
+ | Training examples | 1,828 |
49
+ | Method | Supervised Fine-Tuning (SFT) |
50
+ | Framework | PEFT 0.19.1 + TRL 0.24.0 |
51
+ | Transformers version | 5.5.0 |
52
+ | PyTorch | 2.4.1+cu124 |
53
+
54
+ ## Output Format
55
+
56
+ The model is trained to produce structured JSON output:
57
+
58
+ ```json
59
+ {
60
+ "is_hallucination": true,
61
+ "category": "dialectal_confusion",
62
+ "explanation_ar": "النموذج أجاب بالفصحى بينما طُلب منه اللهجة النجدية، وهذا يمثّل ارتباكاً لهجياً واضحاً.",
63
+ "confidence": 0.9
64
+ }
65
+ ```
66
+
67
+ ## Usage
68
+
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="auto", device_map="auto")
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": system_prompt},
93
+ {"role": "user", "content": user_msg},
94
+ ]
95
+
96
+ inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to(model.device)
97
+ outputs = model.generate(inputs, max_new_tokens=256, temperature=0.1, do_sample=True)
98
+ response = tokenizer.decode(outputs[0][inputs.shape[-1]:], skip_special_tokens=True)
99
+ print(response)
100
+ ```
101
+
102
+ ## Dataset
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
+ Part of the [Sawb Arabic Cultural Hallucination Detection](https://huggingface.co/collections/HassanB4/sawb-arabic-cultural-hallucination-detection) collection.
adapter_config.json ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alora_invocation_tokens": null,
3
+ "alpha_pattern": {},
4
+ "arrow_config": null,
5
+ "auto_mapping": null,
6
+ "base_model_name_or_path": "Qwen/Qwen2.5-7B-Instruct",
7
+ "bias": "none",
8
+ "corda_config": null,
9
+ "ensure_weight_tying": false,
10
+ "eva_config": null,
11
+ "exclude_modules": null,
12
+ "fan_in_fan_out": false,
13
+ "inference_mode": true,
14
+ "init_lora_weights": true,
15
+ "layer_replication": null,
16
+ "layers_pattern": null,
17
+ "layers_to_transform": null,
18
+ "loftq_config": {},
19
+ "lora_alpha": 8,
20
+ "lora_bias": false,
21
+ "lora_dropout": 0.05,
22
+ "lora_ga_config": null,
23
+ "megatron_config": null,
24
+ "megatron_core": "megatron.core",
25
+ "modules_to_save": null,
26
+ "peft_type": "LORA",
27
+ "peft_version": "0.19.1",
28
+ "qalora_group_size": 16,
29
+ "r": 8,
30
+ "rank_pattern": {},
31
+ "revision": null,
32
+ "target_modules": [
33
+ "q_proj",
34
+ "v_proj",
35
+ "up_proj",
36
+ "o_proj",
37
+ "down_proj",
38
+ "k_proj",
39
+ "gate_proj"
40
+ ],
41
+ "target_parameters": null,
42
+ "task_type": "CAUSAL_LM",
43
+ "trainable_token_indices": null,
44
+ "use_bdlora": null,
45
+ "use_dora": false,
46
+ "use_qalora": false,
47
+ "use_rslora": false
48
+ }
adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:91a752a8163be2fc1b4de6b02b5bfb03451ba94c60df799eb74437f6f0fade61
3
+ size 80792096