---
base_model: unsloth/qwen2.5-3b-instruct-unsloth-bnb-4bit
library_name: peft
license: apache-2.0
language:
- ar
tags:
- arabic
- reasoning
- llm
- DIRA
- qwen
- unsloth
- transformers
- PEFT
pipeline_tag: text-generation
---
# Diraya-3B-Instruct-Ar

## Model Description
**Diraya-3B-Instruct-Ar** is an `Arabic` reasoning-specialized language model fine-tuned from `Qwen2.5-3B` .
This model is part of the **DIRA (Diraya Arabic Reasoning AI)** collection, which focuses on enhancing the logical inference and mathematical reasoning capabilities of **Arabic** language models.
## Key Features
- **Arabic-first reasoning**: Optimized specifically for complex reasoning tasks in Arabic
- **Structured reasoning format**: Trained to output reasoning in a clear XML format
- **Mathematical reasoning**: Enhanced ability to solve multi-step math problems
- **Instruction-tuned**: Follows instructions reliably in Arabic
- **Lightweight**: Based on the efficient 3B parameter model architecture
## Technical Details
**Base Model**: [Qwen2.5-3B](https://huggingface.co/Qwen/Qwen2.5-3B) via [unsloth/Qwen2.5-3B-Instruct-unsloth-bnb-4bit](https://huggingface.co/unsloth/Qwen2.5-3B-Instruct-unsloth-bnb-4bit)
**Model Type**: Instruction-tuned causal language model
**Architecture**:
- 36 transformer layers
- 16 attention heads for queries (GQA)
- 2 attention heads for keys/values
- Context length: 32,768 tokens
**Training Approach**:
- Fine-tuned using `GPRO`
- Training focused on structured reasoning output format using XML tags
- Optimized for mathematical reasoning using the Arabic GSM8K dataset
- Multiple reward functions including correctness, format adherence, and output structure
**LoRA Configuration**:
```json
{
"peft_type": "LORA",
"r": 64,
"lora_alpha": 64,
"lora_dropout": 0,
"target_modules": [
"k_proj", "gate_proj", "o_proj", "down_proj",
"v_proj", "up_proj", "q_proj"
],
"bias": "none",
"inference_mode": true
}
```
## Usage
The model is designed to output structured reasoning in the following format:
```
[Step-by-step reasoning process in Arabic]
[Final answer in Arabic]
```
### Example Usage
```python
from unsloth import FastLanguageModel
max_seq_length = 1024 # Can increase for longer reasoning traces
lora_rank = 64 # Larger rank = smarter, but slower
model, tokenizer = FastLanguageModel.from_pretrained(
model_name = "Omartificial-Intelligence-Space/Diraya-3B-Instruct-Ar",
max_seq_length = max_seq_length,
load_in_4bit = True, # False for LoRA 16bit
fast_inference = True, # Enable vLLM fast inference
max_lora_rank = lora_rank,
)
# System prompt to enforce XML structure
system_prompt = """
Respond in the following format in Arabic language only:
...
...
"""
# Prepare user question
user_question = "كل يوم، تُطعم وندي كل دجاجة من دجاجاتها ثلاث أكواب من العلف المختلط. تقدم الدجاجات وجباتهم في ثلاث وجبات منفصلة. في الصباح، تعطي قطيعها من الدجاج 15 كوبًا من العلف. في فترة ما بعد الظهر، تعطي دجاجاتها 25 كوبًا أخرى من العلف. كم عدد أكواب العلف التي تحتاجها لتقديمها لدجاجاتها في الوجبة الأخيرة من اليوم إذا كان حجم قطيع وندي 20 دجاجة؟"
# Prepare input for the model
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": user_question}
]
input_text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
# Generate response
inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
outputs = model.generate(
**inputs,
max_new_tokens=512,
temperature=0.7,
top_p=0.95
)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response)
```
## Training Data
This model was primarily fine-tuned on:
- [**Arabic GSM8K Dataset**](https://huggingface.co/datasets/Omartificial-Intelligence-Space/Arabic-gsm8k):
- A comprehensive collection of grade school math problems translated to Arabic, requiring multi-step reasoning
## Training and Evaluation Results
### Training Progress

*Figure: Composition of Rewards over Training Steps showing the evolution of model performance across different reward functions*
The training utilized multiple reward functions to optimize different aspects of the model's performance:
- **Correctness Reward** (red): Measures the model's ability to generate the correct final answer
- **Integer Reward** (blue): Ensures the model outputs valid numerical responses
- **Format Rewards** (purple/gray): Promote proper XML structure adherence
- **XML Count Reward** (yellow): Fine-tunes the exact XML tag placement and completeness
As shown in the visualization, the model demonstrated consistent improvement across all reward dimensions throughout the training process. The upper values in rewards indicate higher-quality outputs that simultaneously satisfy multiple optimization criteria. This multi-objective training approach resulted in a model that not only produces correct answers but does so with clear, well-structured reasoning.
The model demonstrates strong performance on Arabic mathematical reasoning tasks, with particular strengths in:
- Producing well-structured reasoning steps
- Following the required XML output format
- Arriving at correct numerical answers for multi-step problems
## Citation
If you use this model in your research, please cite:
```bibtex
@misc{diraya3b,
title={Diraya-3B-Instruct-Ar: An Arabic Reasoning-Specialized Language Model},
author={Omartificial-Intelligence-Space},
year={2025},
howpublished={\url{https://huggingface.co/Omartificial-Intelligence-Space/Diraya-3B-Instruct-Ar}}
}
```
## Acknowledgements
This model builds upon the Qwen2.5-3B model by the Qwen Team and utilizes optimization techniques from Unsloth. We acknowledge their valuable contributions to the field of language modeling.
```bibtex
@misc{qwen2.5,
title = {Qwen2.5: A Party of Foundation Models},
url = {https://qwenlm.github.io/blog/qwen2.5/},
author = {Qwen Team},
month = {September},
year = {2024}
}
@article{qwen2,
title={Qwen2 Technical Report},
author={An Yang and Baosong Yang and Binyuan Hui and Bo Zheng and Bowen Yu and Chang Zhou and Chengpeng Li and Chengyuan Li and Dayiheng Liu and Fei Huang and Guanting Dong and Haoran Wei and Huan Lin and Jialong Tang and Jialin Wang and Jian Yang and Jianhong Tu and Jianwei Zhang and Jianxin Ma and Jin Xu and Jingren Zhou and Jinze Bai and Jinzheng He and Junyang Lin and Kai Dang and Keming Lu and Keqin Chen and Kexin Yang and Mei Li and Mingfeng Xue and Na Ni and Pei Zhang and Peng Wang and Ru Peng and Rui Men and Ruize Gao and Runji Lin and Shijie Wang and Shuai Bai and Sinan Tan and Tianhang Zhu and Tianhao Li and Tianyu Liu and Wenbin Ge and Xiaodong Deng and Xiaohuan Zhou and Xingzhang Ren and Xinyu Zhang and Xipin Wei and Xuancheng Ren and Yang Fan and Yang Yao and Yichang Zhang and Yu Wan and Yunfei Chu and Yuqiong Liu and Zeyu Cui and Zhenru Zhang and Zhihao Fan},
journal={arXiv preprint arXiv:2407.10671},
year={2024}
}
```