EmbeddingGemma 2 (text) fine-tuned for Moroccan Darija in Arabic letters, Arabizi and French mix
A small text-embedding model that treats Moroccan Darija written in Arabic letters, in Arabizi (Latin letters and digits such as 3, 7, 9) and mixed with French as the same language. It is google/embeddinggemma-2 fine-tuned on 165,846 pairs of human-written Darija sentences (DODa) and Moroccan medical questions and answers (MedQA-MA, with automatically generated Arabizi for the medical questions).
It belongs to the study The Arabizi Blind Spot of Text Embeddings for Moroccan Darija and a Training Fix (see the paper for the full method, controls and limits). Other models from the same study: anaschahid/darija-arabizi-embeddinggemma2-text, anaschahid/darija-arabizi-qwen3-embedding-0.6b, anaschahid/darija-arabizi-bge-m3, and the control and ablation runs in anaschahid/darija-arabizi-embedding-controls.
What problem it fixes
Untrained embedding models read Darija in Arabic letters much better than the same text in Arabizi. On 1,000 Moroccan health questions searched against 5,000 answers, the base google/embeddinggemma-2 finds the right answer in its top ten for 20.4% of questions in Arabic letters but only 2.9% of the same questions in Arabizi. After fine-tuning the Arabizi score is 19.8%.
Typical uses: searching a collection that mixes scripts (for example social-media posts or comments) with a query in either script, health-information question answering, finding duplicates across scripts, and Arabizi-to-English search. We have not tested real social-media text.
Quick start
import torch
from transformers import AutoModel, AutoTokenizer
repo = "anaschahid/darija-arabizi-embeddinggemma2-text"
tok = AutoTokenizer.from_pretrained(repo)
model = AutoModel.from_pretrained(repo).eval()
QUERY = "task: search result | query: " # prefix for queries
DOC = "title: none | text: " # prefix for documents / answers
def embed(texts, max_len=256):
batch = tok(texts, truncation=True, max_length=max_len, padding=True, return_tensors="pt")
with torch.no_grad():
h = model(**batch).last_hidden_state
mask = batch["attention_mask"].unsqueeze(-1).to(h.dtype)
e = (h * mask).sum(1) / mask.sum(1).clamp_min(1) # mean pooling
return torch.nn.functional.normalize(e.float(), dim=-1)
queries = ["chno howa a7san 3ilaj dyal l7sas f jild?"] # Arabizi
docs = ["العلاج الأفضل للحساسية الجلدية هو تجنب المحفزات واستعمال مرطب ومضاد للهيستامين.",
"كيفاش نحبس النزيف ديال المنخار؟"]
q = embed([QUERY + t for t in queries])
d = embed([DOC + t for t in docs])
print((q @ d.T)) # cosine similarities
# Short vectors (Matryoshka): keep the first k numbers and renormalize
k = 128
q128 = torch.nn.functional.normalize(q[:, :k], dim=-1)
d128 = torch.nn.functional.normalize(d[:, :k], dim=-1)
The text-only EmbeddingGemma 2 checkpoint needs transformers>=5.22 (model type embedding_gemma2). The checkpoint contains the text tower only; audio and vision are not included.
Vectors have 768 numbers and are L2-normalized; use cosine similarity (dot product). The model was trained with a Matryoshka loss, so the first 512, 256 or 128 numbers (and 768 for 1,024-wide models) can be used as shorter vectors with a small loss in quality.
Results
All numbers come from the saved result files of the study. Base model = google/embeddinggemma-2 without fine-tuning.
| Test (Recall@10, %) | Base model | This model |
|---|---|---|
| Medical Q->A, question in Arabic letters | 20.4 | 32.1 |
| Medical Q->A, question in Arabizi | 2.9 | 19.8 |
| Medical Q->A, question in Darija+French mix | 17.1 | 27.2 |
| Medical Q->A, question in French | 18.3 | 25.5 |
| Medical Q->A, 50 Arabizi questions typed by a native speaker | 6.0 | 30.0 |
| Medical Q->A, 1,000 Arabizi questions typed by four other writers | 5.9 | 20.1 |
| Medical Q->A, 200 Darija+French mixed questions typed by those writers | 15.5 | 23.5 |
On the four writers' questions ("typed by four other writers"), the model reaches 66% of its Arabic-letter score on the same questions (20.1 against 30.5); the base model reaches 31%.
| Sentence matching | R@1 base | R@1 this model | R@10 base | R@10 this model |
|---|---|---|---|---|
| DODa held-out (2,000): Arabizi -> Arabic letters | 57.9 | 99.9 | 74.8 | 100.0 |
| DODa held-out: Arabic letters -> English | 28.1 | 79.2 | 50.3 | 94.2 |
| DODa held-out: Arabizi -> English | 4.8 | 71.7 | 8.8 | 90.1 |
| TerjamaBench (509): Arabizi -> Arabic letters | 64.8 | 99.2 | 83.5 | 100.0 |
| TerjamaBench: Arabic letters -> English | 52.8 | 85.9 | 73.3 | 96.7 |
| TerjamaBench: Arabizi -> English | 19.8 | 82.7 | 29.9 | 94.5 |
Reading these numbers:
- Each medical query has exactly one marked correct answer among 5,000, so absolute scores are low and are best used to compare models.
- The Arabizi, mixed and French versions of the 1,000 test questions were written by a language model; the 50-question and four-writer rows are human-typed. The four writers' regions and ages were not recorded.
- The sentence sets are easy once trained (Arabizi to Arabic letters is near 100%). TerjamaBench may have been seen by the base models in pre-training.
- On Arabic letters to English, this model ties the best Darija-specific baseline at Recall@1 rather than beating it (see the paper).
Training
- Data (165,846 pairs): DODa Arabizi/Arabic/English sentence triples (3 tasks, 28,075 pairs each) and MedQA-MA questions and answers (3 tasks, 27,207 pairs each: Arabic question to answer, Arabizi question to answer, Arabizi question to Arabic question). All test items and their near-duplicates are excluded from training.
- Medical Arabizi is produced by a spelling-variation generator learned from DODa's human Arabizi (4 styles, 2 spellings per question during training).
- Objective: in-batch contrastive loss (scale 20) plus one same-specialty hard negative per medical question, applied at the full width and at Matryoshka prefixes. AdamW, learning rate 2e-5, batch 96, 1,700 steps (about one pass), bf16, gradient checkpointing, one RTX 4090, about 33 minutes.
- Code, data splits, test sets and result files are described in the paper; this card's numbers are produced from them.
Limitations and responsible use
- Research use only. Training data (DODa and MedQA-MA) is non-commercial (CC BY-NC 4.0), so this model is released under CC BY-NC 4.0. Check the base model's licence too.
- Not medical advice. The model finds stored answers; it does not check that they are medically correct, and the MedQA-MA answers were not reviewed by clinicians.
- Tested on: short everyday sentences, and medical questions. Not tested on long social-media posts, other domains, other Arabic dialects or speech.
- Arabizi training slightly lowers scores on Darija-French mixed medical questions compared with an Arabic-letters-only control (about 3 to 4 points Recall@10 at matched training exposure).
- The model may reflect biases and errors in DODa and MedQA-MA (parts of MedQA-MA are machine-translated).
Citation
If you use this model, please cite the study:
@misc{darija_arabizi_embeddings_2026,
title = {The Arabizi Blind Spot of Text Embeddings for Moroccan Darija and a Training Fix},
year = {2026},
howpublished = {Hugging Face model repository \url{https://huggingface.co/anaschahid/darija-arabizi-embeddinggemma2-text}},
}