oddadmix commited on
Commit
b98ebd3
·
verified ·
1 Parent(s): c81511a

Darija-English 5M SFT + card + eval

Browse files
README.md ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - ar
5
+ - en
6
+ base_model: oddadmix/Emhotob-5M-v2
7
+ pipeline_tag: text-generation
8
+ library_name: transformers
9
+ tags:
10
+ - translation
11
+ - darija
12
+ - moroccan-arabic
13
+ - english
14
+ - arabic
15
+ - small-language-model
16
+ - slm
17
+ - tiny-lm
18
+ - chatml
19
+ - scaling-study
20
+ metrics:
21
+ - bleu
22
+ - chrf
23
+ ---
24
+
25
+ # Emhotob-5M-Darija-English-v1 — Bidirectional Moroccan Darija ↔ English (~5.1M params)
26
+
27
+ A **5.1M-parameter** model that translates **both ways** between **Moroccan Darija (الدارجة المغربية)** and **English**.
28
+ A single set of weights serves both directions; a direction-specific system prompt selects
29
+ which way to translate.
30
+
31
+ Finetuned from [`oddadmix/Emhotob-5M-v2`](https://huggingface.co/oddadmix/Emhotob-5M-v2), a tiny Llama-architecture
32
+ base (hidden 128, 5 layers, 4 heads, vocab 32000, tied embeddings).
33
+
34
+ > **Scaling study.** This is one rung of a from-scratch Arabic scaling study that runs an
35
+ > identical SFT + eval recipe across bases from 0.5M to 50M parameters to locate where
36
+ > translation *emerges*. On the headline MSA↔Egyptian pair, output is degenerate at ≤1M,
37
+ > becomes real-but-rough at 5M, and usable at 10M+. See the sibling
38
+ > [`oddadmix/50M-Darija-English-v1`](https://huggingface.co/oddadmix/50M-Darija-English-v1) for the fluent reference.
39
+
40
+ ## Evaluation
41
+
42
+ Deterministic held-out set of **3,000 pairs** (`seed=42`),
43
+ decoded **greedily** (`do_sample=False`, no repetition penalty), scored with sacreBLEU:
44
+
45
+ | Direction | sacreBLEU | chrF |
46
+ |---|---:|---:|
47
+ | **Darija → English** | **13.45** | 23.93 |
48
+ | **English → Darija** | **11.80** | 20.87 |
49
+
50
+ Saved weights are the best checkpoint by validation loss (`eval_loss = 2.690`). 20 samples
51
+ per direction with references are in [`eval_bidirectional.json`](./eval_bidirectional.json).
52
+
53
+ ### Example translations
54
+
55
+ Real greedy-decoded outputs from the held-out set:
56
+
57
+ **Darija → English**
58
+
59
+ | Source | Model output | Reference |
60
+ |---|---|---|
61
+ | لا، عندنا تذاكر يا حبيبة | No, I'm sorry to be a bit | No, we have tickets darling |
62
+ | غطّا وجهو و بكا | do you want to say | He covered his face and wept |
63
+
64
+ **English → Darija**
65
+
66
+ | Source | Model output | Reference |
67
+ |---|---|---|
68
+ | No, we have tickets darling | لا، غادي نديرو | لا، عندنا تذاكر يا حبيبة |
69
+ | He covered his face and wept | هوا شي حاجة و لكن | غطّا وجهو و بكا |
70
+
71
+ ## Usage
72
+
73
+ ChatML format. **Pick the system prompt for the direction you want:**
74
+
75
+ ```python
76
+ import torch
77
+ from transformers import AutoModelForCausalLM, AutoTokenizer
78
+
79
+ model_id = "oddadmix/Emhotob-5M-Darija-English-v2"
80
+ tok = AutoTokenizer.from_pretrained(model_id)
81
+ model = AutoModelForCausalLM.from_pretrained(model_id, dtype=torch.bfloat16).to("cuda").eval()
82
+
83
+ SYSTEM = "You are a professional translator. Translate the Moroccan Darija text into English."
84
+
85
+ def translate(text, system=SYSTEM):
86
+ prompt = (f"<|im_start|>system\n{system}<|im_end|>\n"
87
+ f"<|im_start|>user\n{text.strip()}<|im_end|>\n<|im_start|>assistant\n")
88
+ ids = tok(prompt, return_tensors="pt", add_special_tokens=False).to(model.device)
89
+ if tok.bos_token_id is not None:
90
+ bos = torch.tensor([[tok.bos_token_id]], device=model.device)
91
+ ids["input_ids"] = torch.cat([bos, ids["input_ids"]], dim=1)
92
+ ids["attention_mask"] = torch.cat([torch.ones_like(bos), ids["attention_mask"]], dim=1)
93
+ out = model.generate(**ids, max_new_tokens=256, do_sample=False,
94
+ eos_token_id=tok.eos_token_id, pad_token_id=tok.pad_token_id)
95
+ return tok.decode(out[0, ids["input_ids"].size(1):], skip_special_tokens=True).strip()
96
+ ```
97
+
98
+ ## Training
99
+
100
+ - **Base model:** `oddadmix/Emhotob-5M-v2` (Llama arch, hidden 128, 5 layers, 4 heads, vocab 32000, tied embeddings;
101
+ **5,080,704 params** after resizing for 2 ChatML tokens)
102
+ - **Dataset:** `oddadmix/darija_english_msa_parallel_dataset`
103
+ - **Method:** HuggingFace `Trainer`, ChatML, **prompt-masked cross-entropy** (loss only on the
104
+ assistant turn). Each row is exploded into **two** training examples (one per direction).
105
+ - **Hyperparameters:** 3 epochs · effective batch 64 · LR 3e-4 (cosine, 5% warmup) ·
106
+ bf16 · max length 1024 · `load_best_model_at_end` on `eval_loss`.
107
+ - **Eval split:** 3,000 deterministic held-out pairs (`seed=42`), scored both directions.
108
+
109
+ ## Limitations
110
+
111
+ A ~5.1M model: reliable on short/common sentences, but drift, repetition, and errors appear
112
+ on long or rare inputs. Gender is disambiguated only from context. For fluent translation use the
113
+ 50M sibling.
114
+
115
+ ## License
116
+
117
+ Apache-2.0, inherited from the base model.
config.json ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "LlamaForCausalLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 0,
8
+ "dtype": "bfloat16",
9
+ "eos_token_id": 32001,
10
+ "head_dim": 32,
11
+ "hidden_act": "silu",
12
+ "hidden_size": 128,
13
+ "initializer_range": 0.02,
14
+ "intermediate_size": 384,
15
+ "max_position_embeddings": 2048,
16
+ "mlp_bias": false,
17
+ "model_type": "llama",
18
+ "num_attention_heads": 4,
19
+ "num_hidden_layers": 5,
20
+ "num_key_value_heads": 2,
21
+ "pad_token_id": 1,
22
+ "pretraining_tp": 1,
23
+ "rms_norm_eps": 1e-06,
24
+ "rope_parameters": {
25
+ "rope_theta": 10000,
26
+ "rope_type": "default"
27
+ },
28
+ "tie_word_embeddings": true,
29
+ "transformers_version": "5.12.1",
30
+ "use_cache": false,
31
+ "vocab_size": 32002
32
+ }
eval_bidirectional.json ADDED
@@ -0,0 +1,223 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "eval_size": 3000,
3
+ "seed": 42,
4
+ "generation": {
5
+ "do_sample": false,
6
+ "repetition_penalty": 1.0,
7
+ "no_repeat_ngram_size": 0
8
+ },
9
+ "directions": {
10
+ "dar2en": {
11
+ "bleu": 13.446299302555513,
12
+ "chrf": 23.93451764854585,
13
+ "samples": [
14
+ {
15
+ "source": "لا، عندنا تذاكر يا حبيبة",
16
+ "reference": "No, we have tickets darling",
17
+ "hypothesis": "No, I'm sorry to be a bit"
18
+ },
19
+ {
20
+ "source": "غطّا وجهو و بكا",
21
+ "reference": "He covered his face and wept",
22
+ "hypothesis": "do you want to say"
23
+ },
24
+ {
25
+ "source": "كانتسنّا فيك ت دي هادشي و تستاهلو",
26
+ "reference": "I'm waiting for you to deserve this",
27
+ "hypothesis": "I'm waiting for you to be a bit"
28
+ },
29
+ {
30
+ "source": "\n\nلجدوال ديال الترتيب\n\nشوف حتى \n\n بوطولا 1\n بوطولا 2\n لهيكلة لهرمية د لبوطولات ديال كورة ف لمغريب\n\nعيون لكلام \n\nبوطولا 1\nمقالات فيها مصدر و 3000 بايت",
31
+ "reference": "For the dawn of the arrangement\n\nLook even\n\n Potola 1\n Potola 2\n For the structure of the pyramid D for Diyal Koura's Boutra\n\nEyes of words\n\nPotola 1\nArticles with a source and 3000 bytes",
32
+ "hypothesis": "For the dawn of the arrangement\n\nLook even\n\n Potola 1\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Potola 2\n Pot"
33
+ },
34
+ {
35
+ "source": "راهوم معشششين هنا و بان ليا قريب يخرجو لفراخ ديالهوم من لبيض",
36
+ "reference": "They're nesting over there and it looks as if the babies will hatch out soon.",
37
+ "hypothesis": "he is not someone here and someone"
38
+ },
39
+ {
40
+ "source": "أفادت التقارير أنه يوجد في المنطقة حوالي 9400 منزل بدون ماء وحوالي 100 منزل بلا كهرباء.",
41
+ "reference": "It is reported that some 9400 homes in the region are without water and approximately 100 without electricity. The previous text is in English. Here is a translation to Moroccan Arabic:",
42
+ "hypothesis": "The same year in the earthquake side of the country, the earthquake side of the country. The previous text is in English. Here is a translation to Moroccan Arabic:"
43
+ },
44
+ {
45
+ "source": "نتحداك تعتارد على هاد الموضوع",
46
+ "reference": "I dare you to object to this topic",
47
+ "hypothesis": "I dare you to be a lot"
48
+ },
49
+ {
50
+ "source": "walakin hadi awal tsafira ftyyara lia o ana khayfa chwiya",
51
+ "reference": "but it's my first flight ever and I'm a little scared",
52
+ "hypothesis": "Do you know what you're not sure you're not sure you're not sure"
53
+ },
54
+ {
55
+ "source": "شرف ليا نعاونك",
56
+ "reference": "Glad to help",
57
+ "hypothesis": "you are too late to yourself"
58
+ },
59
+ {
60
+ "source": "معرفتش من إمتا كايفكرو فهاد شي",
61
+ "reference": "i dont know why they think",
62
+ "hypothesis": "I don't know what to do"
63
+ },
64
+ {
65
+ "source": "سير دير شي حاجة تنافعك",
66
+ "reference": "do something that will benefit you",
67
+ "hypothesis": "go to see you"
68
+ },
69
+ {
70
+ "source": "وسبحسام",
71
+ "reference": "thirty five past",
72
+ "hypothesis": "And they're her"
73
+ },
74
+ {
75
+ "source": "هوا كايدحاك بزاف.",
76
+ "reference": "That is so funny.",
77
+ "hypothesis": "He is a good idea."
78
+ },
79
+ {
80
+ "source": "ناسّ كاتعجبهوم شيكاغو",
81
+ "reference": "people love chicago",
82
+ "hypothesis": "It's a lot of them"
83
+ },
84
+ {
85
+ "source": "ش† كاينين أختي وماهات",
86
+ "reference": "there are some mothers",
87
+ "hypothesis": "i took her"
88
+ },
89
+ {
90
+ "source": "ghadi ykhSona sway3 bach nrj3o mnin jina, f DDlam, o f wsT ga3 had lghiss ...",
91
+ "reference": "It will take us hours to get back the way we came, in the dark, and through all that mud ...",
92
+ "hypothesis": "It's a good phone, friend, friend, and friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, friend, fri"
93
+ },
94
+ {
95
+ "source": "تقدر تعتامد عليا أ الشاف!",
96
+ "reference": "You can count on me, boss!",
97
+ "hypothesis": "You're not sure I'm sorry!"
98
+ },
99
+ {
100
+ "source": "خلينا غير نبقاو ف روكك",
101
+ "reference": "Let's just stay rock",
102
+ "hypothesis": "Let's started in God"
103
+ },
104
+ {
105
+ "source": "ولا غادي يخاساك تخدام دروج",
106
+ "reference": "Otherwise you’ll have to use the stairs",
107
+ "hypothesis": "I'll take the two day"
108
+ },
109
+ {
110
+ "source": "شحال ديال لواقت ايخاسنا باش نجاهزو تاجريبا؟",
111
+ "reference": "How long do we have to prepare the experiment?",
112
+ "hypothesis": "What do you think often do you have to do together?"
113
+ }
114
+ ]
115
+ },
116
+ "en2dar": {
117
+ "bleu": 11.79660565975206,
118
+ "chrf": 20.86721324211251,
119
+ "samples": [
120
+ {
121
+ "source": "No, we have tickets darling",
122
+ "reference": "لا، عندنا تذاكر يا حبيبة",
123
+ "hypothesis": "لا، غادي نديرو"
124
+ },
125
+ {
126
+ "source": "He covered his face and wept",
127
+ "reference": "غطّا وجهو و بكا",
128
+ "hypothesis": "هوا شي حاجة و لكن"
129
+ },
130
+ {
131
+ "source": "I'm waiting for you to deserve this",
132
+ "reference": "كانتسنّا فيك ت دي هادشي و تستاهلو",
133
+ "hypothesis": "كانتسنّا فيك ت قاسح ليا"
134
+ },
135
+ {
136
+ "source": "For the dawn of the arrangement\n\nLook even\n\n Potola 1\n Potola 2\n For the structure of the pyramid D for Diyal Koura's Boutra\n\nEyes of words\n\nPotola 1\nArticles with a source and 3000 bytes",
137
+ "reference": "لجدوال ديال الترتيب\n\nشوف حتى \n\n بوطولا 1\n بوطولا 2\n لهيكلة لهرمية د لبوطولات ديال كورة ف لمغريب\n\nعيون لكلام \n\nبوطولا 1\nمقالات فيها مصدر و 3000 بايت",
138
+ "hypothesis": "لجدوال ديال الترتيب\n\nشوف حتى \n\n بوطولا 1\n بوطولا 2\n لهيكلة لهرمية د لبوطولات ديال كورة ف لمغريب\n\nعيون لكلام \n\nبوطولا 1\nمقالات فيها مصدر و 3000 بايت"
139
+ },
140
+ {
141
+ "source": "They're nesting over there and it looks as if the babies will hatch out soon.",
142
+ "reference": "راهوم معشششين هنا و بان ليا قريب يخرجو لفراخ ديالهوم من لبيض",
143
+ "hypothesis": "كاينين بزاف ديال ليا غادي تاخد شي حاجة باش نديرو شي حاجة."
144
+ },
145
+ {
146
+ "source": "It is reported that some 9400 homes in the region are without water and approximately 100 without electricity. The previous text is in English. Here is a translation to Moroccan Arabic:",
147
+ "reference": "أفادت التقارير أنه يوجد في المنطقة حوالي 9400 منزل بدون ماء وحوالي 100 منزل بلا كهرباء.",
148
+ "hypothesis": "كاين 9400 واحد، واحد واحد من 100 من 100 من 100 من 100 من 100 من 100 من 100 من 100 من 100 من 100 من 100 من 100 من 100."
149
+ },
150
+ {
151
+ "source": "I dare you to object to this topic",
152
+ "reference": "نتحداك تعتارد على هاد الموضوع",
153
+ "hypothesis": "نتحداك ت تڭولّا هادشي لي كاتستاهل"
154
+ },
155
+ {
156
+ "source": "but it's my first flight ever and I'm a little scared",
157
+ "reference": "walakin hadi awal tsafira ftyyara lia o ana khayfa chwiya",
158
+ "hypothesis": "walakin kayn 3lih 3la lmakhir"
159
+ },
160
+ {
161
+ "source": "Glad to help",
162
+ "reference": "شرف ليا نعاونك",
163
+ "hypothesis": "l7al l7al"
164
+ },
165
+ {
166
+ "source": "i dont know why they think",
167
+ "reference": "معرفتش من إمتا كايفكرو فهاد شي",
168
+ "hypothesis": "مانضنش غادي نديرو"
169
+ },
170
+ {
171
+ "source": "do something that will benefit you",
172
+ "reference": "سير دير شي حاجة تنافعك",
173
+ "hypothesis": "ماتبقاش نديرو هادشي"
174
+ },
175
+ {
176
+ "source": "thirty five past",
177
+ "reference": "وسبحسام",
178
+ "hypothesis": "هادشي كايعجبك"
179
+ },
180
+ {
181
+ "source": "That is so funny.",
182
+ "reference": "هوا كايدحاك بزاف.",
183
+ "hypothesis": "هادش�� غادي نديرو."
184
+ },
185
+ {
186
+ "source": "people love chicago",
187
+ "reference": "ناسّ كاتعجبهوم شيكاغو",
188
+ "hypothesis": "راه خدام بزاف"
189
+ },
190
+ {
191
+ "source": "there are some mothers",
192
+ "reference": "ش† كاينين أختي وماهات",
193
+ "hypothesis": "كاينين بزاف"
194
+ },
195
+ {
196
+ "source": "It will take us hours to get back the way we came, in the dark, and through all that mud ...",
197
+ "reference": "ghadi ykhSona sway3 bach nrj3o mnin jina, f DDlam, o f wsT ga3 had lghiss ...",
198
+ "hypothesis": "غادي نديرو شي حاجة فهادشي، فهادشي، و كاين شي حاجة فهادشي، و كاين شي حاجة فهادشي، و كاين شي حاجة فهادشي، و كاين شي حاجة فهادشي، و كاين شي حاجة فهادشي، و كاين شي حاجة فهادشي، و كاين شي حاجة فهادشي، و كاين شي حاجة فهادشي، و كاين شي حاجة فهادشي، و كاين شي حاجة فهادشي، و كاين شي حاجة فهادشي، و كاين شي حاجة فهادشي، و كاين شي حاجة فهادشي، و كاين شي حاجة فهادشي، و كاين شي حاجة فهادشي، و كاين شي حاجة فهادشي، و كاين شي حاجة فهادشي، و كاين شي حاجة فهادشي، و كاين شي حاجة فهادشي، و كاين شي حاجة فهادشي، و كاين شي حاجة فهادشي، و كاين شي حاجة فهادشي، و كاين شي حاجة فهادشي، و كاين شي حاجة فهادشي، و كاين شي حاجة فهادشي، و كاين شي حاجة فهادشي، و كاين شي حاجة فهاد"
199
+ },
200
+ {
201
+ "source": "You can count on me, boss!",
202
+ "reference": "تقدر تعتامد عليا أ الشاف!",
203
+ "hypothesis": "مابقيتش باغي نديرو ليا، غادي نديرو"
204
+ },
205
+ {
206
+ "source": "Let's just stay rock",
207
+ "reference": "خلينا غير نبقاو ف روكك",
208
+ "hypothesis": "خليني نديرو"
209
+ },
210
+ {
211
+ "source": "Otherwise you’ll have to use the stairs",
212
+ "reference": "ولا غادي يخاساك تخدام دروج",
213
+ "hypothesis": "واخا تاخد شي حاجة"
214
+ },
215
+ {
216
+ "source": "How long do we have to prepare the experiment?",
217
+ "reference": "شحال ديال لواقت ايخاسنا باش نجاهزو تاجريبا؟",
218
+ "hypothesis": "شحال هادشي لي كانو كاين شي حاجة؟"
219
+ }
220
+ ]
221
+ }
222
+ }
223
+ }
generation_config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 0,
4
+ "eos_token_id": 32001,
5
+ "output_attentions": false,
6
+ "output_hidden_states": false,
7
+ "pad_token_id": 1,
8
+ "transformers_version": "5.12.1",
9
+ "use_cache": true
10
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:842feddaee7e3d349a6f78dda751811ef4113c6788c278a8d41f45f8d8018c6b
3
+ size 10166472
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "backend": "tokenizers",
3
+ "bos_token": "<s>",
4
+ "eos_token": "<|im_end|>",
5
+ "extra_special_tokens": [
6
+ "<|im_start|>",
7
+ "<|im_end|>"
8
+ ],
9
+ "is_local": false,
10
+ "local_files_only": false,
11
+ "model_max_length": 1000000000000000019884624838656,
12
+ "pad_token": "<pad>",
13
+ "tokenizer_class": "TokenizersBackend",
14
+ "unk_token": "<unk>"
15
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:57c0be99e00ec7643b955aa7a9fc22b97be9fca1f154754c865615d8078fa8ce
3
+ size 4792