Finetuned from
oddadmix/50M-2048-Emhotob,
a tiny Arabic base model trained from scratch.
Both directions are genuinely hard: Darija has no single standardized orthography, is
heavily borrowed/code-switched (French/Amazigh), and appears in the data in both Arabic
script and Latin (Arabizi) script. The saved weights are the best checkpoint by validation
loss (eval_loss=1.032, epoch 2 of 3).
A larger set of 20 examples per direction (with references) is in
eval_bidirectional.json.
ChatML format. Pick the system prompt for the direction you want:
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4model_id = "oddadmix/50M-Darija-English-v1"
5tok = AutoTokenizer.from_pretrained(model_id)
6model = AutoModelForCausalLM.from_pretrained(model_id, dtype=torch.bfloat16).to("cuda").eval()
7
8SYS_TO_EN = "You are a professional translator. Translate the Moroccan Darija text into English."
9SYS_TO_DAR = "أنت مترجم محترف. ترجم النص الإنجليزي إلى الدارجة المغربية."
10
11def translate(text: str, system: str) -> str:
12 prompt = (
13 f"<|im_start|>system\n{system}<|im_end|>\n"
14 f"<|im_start|>user\n{text.strip()}<|im_end|>\n"
15 f"<|im_start|>assistant\n"
16 )
17 ids = tok(prompt, return_tensors="pt", add_special_tokens=False).to(model.device)
18 if tok.bos_token_id is not None: # training prepends BOS
19 bos = torch.tensor([[tok.bos_token_id]], device=model.device)
20 ids["input_ids"] = torch.cat([bos, ids["input_ids"]], dim=1)
21 ids["attention_mask"] = torch.cat([torch.ones_like(bos), ids["attention_mask"]], dim=1)
22 out = model.generate(**ids, max_new_tokens=256, do_sample=False,
23 eos_token_id=tok.eos_token_id, pad_token_id=tok.pad_token_id)
24 return tok.decode(out[0, ids["input_ids"].size(1):], skip_special_tokens=True).strip()
25
26print(translate("walakin hadi awal tsafira ftyyara lia o ana khayfa chwiya", SYS_TO_EN))
27# → But it's my first flight and I'm a little scared
28print(translate("I dare you to object to this topic", SYS_TO_DAR))
29# → نتحداك تعارض هاد الموضوع
Apache-2.0 (model weights, inherited from the base model). Note the training dataset
aggregates several community corpora — check their individual licenses for downstream use.