🧠 Nawah-Math-Reasoning
نموذج استدلال عربي صغير (~52M بارامتر) يفكّر خطوة بخطوة داخل وسم <think>
ثم يعطي الإجابة النهائية.
A ~52M-parameter Arabic reasoning model that thinks step by step inside
<think> before answering.
نموذج صغير بما يكفي ليعمل حتى على المعالج (CPU).
Small enough to run on a CPU — this Space uses ZeroGPU for snappier responses.
Model ·
Training code ·
Synthetic dataset ·
GSM8K-ar dataset
Weights, both datasets and the full training code are open — Apache 2.0.
"""
NOTE = """
### 📊 النتائج / Results
Number agreement, greedy decoding, on held-out splits — the same rows for every version of the
model, so the numbers are comparable.
| eval set | n | score |
|---|---:|---:|
| GSM8K-ar | 600 | **79.0%** |
| Arabic_Reasoning | 400 | **73.0%** |
| synthetic math | 1000 | **40.4%** |
| synthetic relational (`ضعف`, `نصف`, `أكثر بـ…`) | 400 | **52.2%** |
### ⚠️ حدود النموذج / Limitations
نموذج تجريبي بحجم 52M: يجيد **شكل** الاستدلال العربي ويحلّ مسائل النِّسب والحساب البسيطة،
لكنه **يخطئ في الحساب كثيرًا** — غالبًا خطوات الحل سليمة ثم تقع غلطة في عملية حسابية واحدة
ويكمل النموذج على رقمه الخاطئ. الأسئلة المفتوحة وغير الحسابية خارج نطاقه، والحوار متعدد
الأدوار كذلك.
A 52M proof of concept. It reliably produces the *shape* of Arabic step-by-step reasoning, but
**arithmetic errors are the dominant failure mode**: the derivation is usually structurally
right, one computation is wrong, and the model then stays faithful to its own bad number. The
40.4% and 52.2% above are the honest ceiling on multi-step problems. Single-turn only;
open-ended and non-mathematical questions are out of distribution.
"""
EXAMPLES = [
"إذا كان لديك 1500 ريال وأنفقت 20% منها على الكتب، فكم تبقى معك؟",
"في مصنع تم إنتاج 5000 وحدة، وكانت نسبة الوحدات المعيبة 2%، فما عدد الوحدات السليمة؟",
"في مدرسة بها 500 طالب، إذا كانت نسبة الذكور 55%، فما عدد الطالبات؟",
"لدى تاجر 240 كيلوغرامًا من الأرز، باع منها 35%، فكم كيلوغرامًا تبقى لديه؟",
"إذا كان عمر أحمد 12 سنة وعمر أخيه ضعف عمره، فما مجموع عمريهما؟",
"في حديقة 80 حيوانًا، 25% منها طيور، ونصف الطيور بيضاء. كم عدد الطيور البيضاء؟",
"جمع سامي 45 صدفة، وجمع أخوه ضعف هذا العدد. كم صدفة جمعا معًا؟",
"لدى ليلى 60 جنيهًا، ولدى ندى أقل منها بـ 18 جنيهًا. كم معهما معًا؟",
]
with gr.Blocks(title="Nawah-Math-Reasoning") as demo:
gr.HTML(DESCRIPTION)
with gr.Row():
with gr.Column(scale=3):
question = gr.Textbox(
label="السؤال / Question", rtl=True, lines=3,
placeholder="اكتب مسألة حسابية هنا…",
)
with gr.Row():
submit = gr.Button("🧮 حل / Solve", variant="primary")
clear = gr.Button("مسح / Clear")
with gr.Accordion("⚙️ إعدادات التوليد / Generation settings", open=False):
max_new_tokens = gr.Slider(32, MAX_NEW_TOKENS_CAP, value=320, step=8,
label="أقصى عدد توكنز / Max new tokens")
temperature = gr.Slider(0.0, 1.5, value=0.0, step=0.05,
label="درجة الحرارة / Temperature (0 = greedy, as evaluated)")
repetition_penalty = gr.Slider(1.0, 1.5, value=1.0, step=0.01,
label="عقوبة التكرار / Repetition penalty")
with gr.Column(scale=4):
answer_box = gr.Textbox(label="✅ الإجابة / Answer", rtl=True, lines=3)
with gr.Accordion("🧠 التفكير / Reasoning trace", open=True):
reasoning_box = gr.Textbox(label="", rtl=True, lines=12)
with gr.Accordion("🔍 المخرجات الخام / Raw output", open=False):
raw_box = gr.Textbox(label="", lines=8)
gr.Examples(examples=EXAMPLES, inputs=question, label="أمثلة / Examples")
gr.Markdown(NOTE)
inputs = [question, max_new_tokens, temperature, repetition_penalty]
outputs = [reasoning_box, answer_box, raw_box]
submit.click(solve, inputs=inputs, outputs=outputs)
question.submit(solve, inputs=inputs, outputs=outputs)
clear.click(lambda: ("", "", "", ""), outputs=[question] + outputs)
if __name__ == "__main__":
demo.queue().launch(theme=gr.themes.Soft())