Archived: V1.3Superseded by V2.9bResearch preview
MoroLMai: a 136M-parameter language model for Moroccan Darija and English
نموذج لغوي صغير للدارجة المغربية والإنجليزية
Abstract
We trained a small decoder-only language model from scratch on Moroccan Darija and English: its own tokenizer, its own training code, no borrowed weights. The model has 135,961,088 parameters, a 32,000-token vocabulary and a 1,024-token context. It was pre-trained on roughly one billion tokens on a single consumer GPU, then fine-tuned for chat. The quantized GGUF file is 145 MB, so it runs on a machine with 2 GB of graphics memory or on CPU alone.
It greets, introduces itself and writes fluent Darija and English. It does not know facts reliably. This page documents what we built, what we measured and where it fails.
Hover, tap or focus a layer to read its size.
1. Motivation
Darija is spoken every day by tens of millions of people, yet general-purpose language models handle it poorly, and almost none handle it when Arabic script and Latin letters mix in the same message.
Large models fill that gap with scale and cost money to run. We asked the opposite question: how far can a very small model go if it is trained for the language from the start, and can it run on hardware that a Moroccan student, school or small business already owns?
Target hardware. 2 GB of GPU memory, 4 CPU cores and 8 GB of RAM, served through llama.cpp.
The constraint shapes every choice below: a vocabulary that is small enough to keep the embedding table cheap, a model deep and narrow rather than wide, and a file small enough for an ordinary laptop.
2. Architecture
The model is a Llama-style decoder-only transformer. The shape is deep and narrow: 38 layers with a hidden size of only 512. That layout keeps the embedding table and the attention width small, which is where a tiny model spends its memory budget.
| Component | Value |
|---|---|
| Parameters | 135,961,088 |
| Decoder layers | 38 |
| Hidden size | 512 |
| Feed-forward (SwiGLU) size | 1,536 |
| Attention heads / key-value heads | 8 / 4 (grouped-query) |
| Position encoding | RoPE (θ = 10,000) |
| Normalization | RMSNorm (ε = 1e-5) |
| Embeddings | tied input and output |
| Vocabulary | 32,000 |
| Context window | 1,024 tokens |
Grouped-query attention halves the key and value projections, which shrinks the cache that grows with every generated token. Tying the input and output embeddings saves another 16.4M parameters. Residual output projections are initialized with a standard deviation scaled by 1/√(2·layers), a GPT-2-style rule that keeps a deep stack stable at the start of training.
Check the total. Per layer: attention 786,432 + feed-forward 2,359,296 + norms 1,024 = 3,146,752. Times 38 = 119,576,576. Add the 16,384,000-parameter embedding and the final norm (512) and you get 135,961,088.
3. Tokenizer
We train a SentencePiece BPE tokenizer with 32,000 pieces on 2 million lines, half Darija and half English, with byte fallback so that no character ever becomes an unknown token. Three reserved tokens mark the chat roles: <|system|>, <|user|> and <|assistant|>.
For V2 we tested whether retraining the tokenizer on the same corpus would help. It did not, and we report that as a negative result.
| Text | Tokens/word, original | retrained | Chars/token, original | retrained |
|---|---|---|---|---|
| Arabic script | 1.58 | 1.55 | 3.83 | 3.90 |
| Arabizi | 1.60 | 1.61 | 3.80 | 3.79 |
| English | 1.43 | 1.43 | 4.26 | 4.25 |
The best case is a 2% saving in Arabic script, which is not worth discarding a trained model. The V2 run therefore keeps the original tokenizer and continues from the V1 weights. Byte-fallback tokens are about 2% in every text type including English, which suggests they are mostly line breaks and rare symbols rather than missing Darija vocabulary.
Arabizi is Darija written with Latin letters and digits (3 for ع, 7 for ح, 9 for ق). It is how most Moroccans type on a phone.
4. Data
Pre-training corpus
The pre-training corpus has 1.4 million documents and about one billion tokens, taken from two open web-text collections.
| Source | Language | Documents | Licence |
|---|---|---|---|
FineWeb-2, subset ary_Arab | Moroccan Arabic | 1,000,000 | ODC-By 1.0 |
| FineWeb-Edu, sample-10BT | English | 400,000 | ODC-By 1.0 |
Chat data
Chat fine-tuning draws on a Darija instruction dataset (573K examples), a cleaned English instruction set, a 40K-conversation English dialogue sample and translation pairs, formatted with the three role tokens. The exact mixture changed between versions as we found and removed weak data. Loss is computed on the assistant's answer only, never on the prompt.
No private data. Everything above is openly licensed. We did not scrape private social media.
The chat template is:
5. Training
Pre-training minimises next-token cross-entropy over packed 1,024-token windows. We use AdamW (β₁ = 0.9, β₂ = 0.95, weight decay 0.1), gradient clipping at 1.0, a short warm-up, cosine decay to 10% of the peak learning rate, and bfloat16 mixed precision. By default each optimizer step covers 131,072 tokens (8 sequences × 16 accumulation steps × 1,024 tokens).
Training on a consumer GPU
The first versions trained on an RTX 3050 with 6 GB of memory. Gradient checkpointing, which recomputes activations instead of storing them, is what makes a 38-layer model fit. We later moved to an RTX 5060 Ti with 8 GB and measured the speed-up directly.
Why a speed-up matters. A small model can only be improved by running many experiments. Cutting a pass over the data from three days to under one day changes how many ideas we can test.
Without gradient checkpointing the same configuration ran at roughly 490 tokens per second on the 8 GB card, because activations spilled into system memory. Memory behaviour, not raw arithmetic, decided the result.
Chat tuning
Supervised fine-tuning ran through four versions, V1 to V1.3. Each version fixed something the previous one got wrong, such as a missing identity and broken greetings. V1.3 is the current release.
6. Results
| Stage | Loss | Perplexity | What is measured |
|---|---|---|---|
| Pre-training, V1 | 3.4177 | 30.5 | next token, web text, one pass over the data |
| Chat fine-tuning, V1.3 | 1.6235 | 5.1 | assistant answers only, chat validation set |
A perplexity of 30 after a single pass is typical for this size. We expect it to fall with more passes over the data, and the V2 run tests that.
What we observe in chat
Numbers like these say little about how the model behaves, so we also test a fixed set of prompts by hand: a greeting, a name, a general-knowledge question, a statement about feeling tired, and Darija questions about Morocco. We compare each version on the same prompts.
What works
- Fluent Darija and English sentences.
- Greets and says who it is.
- Quantization to 8 bits does not visibly change the answers.
What does not
- Facts. It answers confidently and often wrongly, for example by placing Rabat in the Middle Atlas.
- It invents names, such as “Frantenck” for a person or place.
- It garbles a user's name when asked to repeat it.
Why facts fail. A model with 136M parameters trained on about a billion tokens has little room for world knowledge. Fluency is cheap. Knowledge is not.
Fluency without knowledge is the expected outcome at this size, and it tells us where the effort should go: better data and verified facts, not a different architecture.
7. Deployment
The model is exported to GGUF and served with llama.cpp. The Hugging Face page currently hosts V1.2 in three sizes; V1.3 is the latest version and will follow. Because it is small, generation speed is limited by memory bandwidth, not arithmetic, so shrinking the file is the most direct way to make it faster.
| Format | Size | Speed | Quality |
|---|---|---|---|
| f16 | 273 MB | about 64 tokens/s | reference |
| Q8_0 | 145 MB | about 100 tokens/s | no visible difference |
| Q4_K_M | 86 MB | not measured | not yet compared |
Q4_K_M is the smallest file but we have not compared its answers yet. We recommend Q8_0: about half the size, about 1.5 times as fast, and no visible difference in our tests.
7. Deployment
The model is exported to GGUF and served with llama.cpp. The Hugging Face page currently hosts V1.2 in three sizes; V1.3 is the latest version and will follow. Because it is small, generation speed is limited by memory bandwidth, not arithmetic, so shrinking the file is the most direct way to make it faster.
| Format | Size | Speed | Quality |
|---|---|---|---|
| f16 | 273 MB | about 64 tokens/s | reference |
| Q8_0 | 145 MB | about 100 tokens/s | no visible difference |
| Q4_K_M | 86 MB | not measured | not yet compared |
Q4_K_M is the smallest file but we have not compared its answers yet. We recommend Q8_0: about half the size, about 1.5 times as fast, and no visible difference in our tests.
8. Roadmap
V2 targets the weaknesses above. Nothing in this list has results yet, and we will publish them whether or not they help.
- Test a retrained tokenizerDone. A 2% gain in Arabic script and none elsewhere, so we keep the original (Table 2).
- Continue pre-training from the V1 weightsSeveral more passes over the same corpus on the RTX 5060 Ti, at a lower peak learning rate so the restart does not erase what V1 learned.
- Add more Darija textRepeating the same text has a ceiling. New data is the larger lever.
- A verified facts set200 to 300 checked questions and answers about Morocco, in English and Darija, so the model has correct facts to learn.
- Fix name handlingTraining examples that teach it to repeat a user's name correctly.
- Compare against V1.3 on fixed promptsSame prompts, same settings, published side by side.
9. Limitations and responsible use
- MoroLMai is a research preview. It is not a reliable source of facts and should not be used for legal, medical or financial advice.
- It reflects the web text it was trained on, including its errors and biases.
- Darija written in Latin letters (Arabizi) is weaker than Darija in Arabic script, because there is less of it in the training data.
- The context window is 1,024 tokens, so long documents do not fit.
- Evaluation so far is a fixed prompt set plus held-out loss. There is no standard Darija benchmark score yet.
10. Licences and data provenance
| Source | Used for | Licence |
|---|---|---|
| FineWeb-2 (Moroccan Arabic) | Pre-training | ODC-By 1.0 |
| FineWeb-Edu | Pre-training | ODC-By 1.0 |
| Moroccan-Darija-Instruct-573K | Chat tuning | CC BY 4.0 |
| Other chat sources: English instructions, English dialogue, translation pairs | Chat tuning | see each dataset's page |
The model files on Hugging Face are published under Apache-2.0, subject to the licence terms and rights attached to the training data. Check the sources above before any commercial use.
11. Cite
@misc{morolmai2026,
title = {MoroLMai: a 136M-parameter language model
for Moroccan Darija and English},
author = {Daoud, Hamza},
year = {2026},
url = {https://morolmai.com/}
}