Quick start
from transformers import AutoModelForCausalLM, AutoTokenizer repo = "superMohammad/llama-75m-arabic-english-dpo"tokenizer = AutoTokenizer.from_pretrained(repo)model = AutoModelForCausalLM.from_pretrained(repo) messages = [{"role": "user", "content": "ما عاصمة المملكة العربية السعودية؟"}]input_ids = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt")output = model.generate(input_ids, max_new_tokens=128) # greedy + repetition_penalty=1.1 from generation_config.jsonprint(tokenizer.decode(output[0, input_ids.shape[1]:], skip_special_tokens=True))# عاصمة المملكة العربية السعودية هي الرياض.
Chat format (stored in the tokenizer, so apply_chat_template handles it):
<bos><|user|>QUESTION<|assistant|>ANSWER<eos>
The model supports single‑turn conversations and was not trained on system prompts or multi‑turn chats.
Recommended decoding (already the default in generation_config.json): greedy decoding, repetition_penalty=1.1, max_new_tokens ≤ 256. Avoid no_repeat_ngram_size: it also blocks words from the question, which breaks answers like "The capital of Saudi Arabia is …".
Real test examples
These are unedited outputs of this exact model with the default settings above. None of these questions appears verbatim in the SFT or DPO training prompts. The examples were chosen to show strengths and weaknesses, not filtered to look good.
Table with columns: #, Question, Model answer, Verdict| # | Question | Model answer | Verdict |
|---|
| 1 | ما عاصمة المملكة العربية السعودية؟ | عاصمة المملكة العربية السعودية هي الرياض. | ✅ Correct |
| 2 | اكتب ثلاث نصائح للمحافظة على الصحة. | 1. تناول نظام غذائي متوازن وممارسة الرياضة بانتظام.2. الحصول على قسط كافٍ من النوم.3. ممارسة التمارين الرياضية بانتظام.4. الحصول على قسط كافٍ من الراحة. | ✅ Good tips · ⚠️ gives 4 instead of 3 |
| 3 | ما هي فوائد القراءة؟ | القراءة هي طريقة رائعة للبقاء صحيًا وممتعًا. يمكن أن يساعد القراءة على تحسين المزاج، وتحسين التركيز، وتقليل التوتر، وتوفير الطاقة اللازمة للنوم. كما يمكن أن تساعد القراءة على تقليل التوتر والقلق، وتحسين التركيز، وتقوية العادات اليومية. | ✅ Fluent, on topic · ⚠️ some repetition |
| 4 | ترجم إلى الإنجليزية: أنا أحب تعلم اللغات. | أنا أحب تعلم اللغة العربية. | ❌ Does not translate |
| 5 | What is the capital of Saudi Arabia? | The capital of Saudi Arabia is Saudi Arabia. | ❌ Wrong fact (correct in Arabic, #1) |
| 6 | Give three tips for staying healthy. | 1. Eat a balanced diet: Eating a variety of foods can help reduce the risk of chronic diseases such as heart disease, diabetes, and certain types of cancer.2. Eat a balanced diet: Eating a variety of foods can help you get enough sleep, which is essential for overall health and well-being.3. Eat a balanced diet: … | ⚠️ Good format and first tip, then repeats |
| 7 | What are the benefits of reading? | The benefits of reading include:* Exponential Power: Reading helps individuals understand their thoughts, feelings, and behaviors, making it easier to understand and appreciate the material.* Cultural Importance: Reading enhances social interactions with people around the world, fostering a sense of belonging and understanding. | ✅ Fluent, structured · ⚠️ odd heading |
| 8 | Write one sentence about the sun. | The sun is a golden glow that brings light to our lives. | ✅ Good |
All 8 answers stopped on their own with <eos> and were written in the language of the question (#4 asked for an English translation, and the model answered in Arabic instead).
Evaluation
Pretraining: held‑out test perplexity (base model)
Table with columns: Language, Test perplexity, Test documents| Language | Test perplexity | Test documents |
|---|
| Arabic (FineWeb2‑HQ) | 19.94 | 1,500 |
| English (FineWeb‑Edu) | 17.36 | 1,500 |
The documents were split by SHA‑256 hash, so no test document was seen during training. The context is 512 tokens and the numbers only compare to models that use this tokenizer.

Alignment: 64 held‑out Aya prompts, greedy decoding
Table with columns: Model, Reward ↑, Win rate vs SFT ↑, Answer in user's language ↑, Stops with <eos> ↑, Mean answer tokens, KL to SFT| Model | Reward ↑ | Win rate vs SFT ↑ | Answer in user's language ↑ | Stops with <eos> ↑ | Mean answer tokens | KL to SFT |
|---|
| SFT | −0.26 | — | 100% | 69% | 35.3 | 0.00 |
| DPO (this model) | +0.21 | 55% | 100% | 83% | 30.9 | 0.75 |
| RL (PPO‑style, β = 0.1), not released | +0.43 | 64% | 100% | 94% | 20.2 | 4.04 |
- Reward comes from a separate Bradley–Terry reward model, normalised to mean 0 and std 1. That reward model reaches 98.3% pair accuracy on held‑out preference pairs.
- Win rate is the share of prompts where the reward model scores this model's answer above the SFT answer.
- DPO improves every metric over SFT while staying very close to it (KL 0.75), which is why it was chosen for release. The RL policy scores higher on the reward model, but it was optimised against that same reward model and gives shorter answers.

Training pipeline
FineWeb2-HQ (ar) + FineWeb-Edu (en) ──► Pretraining (750M tokens) ──► base modelAya + CIDAR + smol-smoltalk ──► SFT (27,615 examples) ──► chat modelAya preference pairs + on-policy ──► DPO (9,421 pairs) ──► this model
1 · Pretraining from random initialisation
Table with columns: Setting, Value| Setting | Value |
|---|
| Data | 50/50 Arabic–English in every micro‑batch; 437M Arabic + 527M English unique training tokens available |
| Tokens seen | 750,026,752 (0.86 passes over Arabic, 0.71 over English, so nothing is repeated) |
| Batch | 32 × 2 accumulation × 512 = 32,768 tokens / update, 22,889 updates |
| Optimiser | AdamW (β = 0.9, 0.95, weight decay 0.1 on matrices), peak LR 6e‑4, 2% warmup, cosine decay |
| Precision | bf16 autocast, FP32 master weights |
| Hardware | 1 × RTX 3090, 4.3 h at ~50.5k tokens/s |
| Cleaning | NFC normalisation, Arabic tatweel and bidi control characters removed, exact SHA‑256 dedup, 98/1/1 hash split |
2 · Supervised fine‑tuning
Table with columns: Setting, Value| Setting | Value |
|---|
| Data | Aya (4,328 Arabic + 3,405 English human‑written answers) + CIDAR (9,882 Arabic) + smol‑smoltalk (10,000 English, single‑turn, code subsets excluded) |
| Loss | Next‑token cross‑entropy on answer tokens only (prompt masked with −100) |
| Schedule | Full fine‑tune, 3 epochs, batch 32, LR 1e‑4, cosine, 3% warmup |
| Validation | 300 held‑out Aya examples, answer‑token loss 2.230 |
3 · Direct Preference Optimization
Table with columns: Setting, Value| Setting | Value |
|---|
| Reference model | The SFT model (frozen) |
| Synthetic pairs (7,732) | Chosen = the real Aya answer. Rejected = one of five failure types: off‑topic answer, wrong language, degenerate (truncated + repeated), no stop (repeats after the answer, no <eos>), too short (empty or 2 words) |
| On‑policy pairs (1,689) | The SFT model answered 2,000 training prompts 4 times each. Best vs worst answer, ranked by reward model score minus penalties for no <eos>, wrong language and repeated 3‑grams |
| Hyper‑parameters | β = 0.3, LR 5e‑6, 1 epoch, batch 16 |
Earlier attempts taught useful lessons. With only three easy rejected types, DPO drifted away from SFT and stopped answers less often (31%), and RL collapsed to empty answers. Adding the no‑stop, too‑short and on‑policy pairs fixed both problems.
Limitations
- Knowledge: at 75M parameters the model knows very few facts. It can state wrong facts fluently, and it may give different answers in Arabic and English (example #5).
- Skills it does not have: translation, arithmetic, reasoning, coding, long documents (context 512), multi‑turn chat.
- Repetition: long answers can repeat a sentence or a list item.
- Dialects: trained on Modern Standard Arabic. Gulf, Egyptian, Levantine and other dialects are not covered.
- Safety: not safety‑tuned or red‑teamed. It may produce biased, offensive or incorrect text. Do not use it for medical, legal, financial or any other high‑stakes decision.
Intended uses: education, research on small bilingual models, alignment experiments, and a starting point for further fine‑tuning.
Data and licences
Thanks to the authors of these datasets. The model weights are released under Apache‑2.0.
Architecture
Llama: RMSNorm (ε = 1e‑5), SwiGLU MLP (intermediate size 1,408), rotary position embeddings (θ = 10,000), grouped‑query attention (8 query heads, 4 key/value heads, head dim 64), no biases, tied input/output embeddings. Compatible with LlamaForCausalLM in 🤗 Transformers ≥ 4.46.
Citation
@misc{llama75m_ar_en_dpo_2026, title = {Llama-75M Arabic-English DPO: a small bilingual chat model trained from scratch}, author = {superMohammad}, year = {2026}, url = {https://huggingface.co/superMohammad/llama-75m-arabic-english-dpo}}