Finetuned from
oddadmix/Emhotob-5M,
a tiny Llama-architecture base (hidden size 128, 5 layers, 4 heads, tied embeddings).
Short, common sentences come out well; longer inputs lose coherence. 20 samples per direction
with references are 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/Emhotob-5M-English-MSA-v1"
5tok = AutoTokenizer.from_pretrained(model_id)
6model = AutoModelForCausalLM.from_pretrained(model_id, dtype=torch.bfloat16).to("cuda").eval()
7
8SYS_TO_MSA = "أنت مترجم محترف. ترجم النص الإنجليزي إلى اللغة العربية الفصحى."
9SYS_TO_EN = "You are a professional translator. Translate the Modern Standard Arabic text into English."
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("Thank you very much, you are so kind.", SYS_TO_MSA))
Apache-2.0, inherited from the base model.