MoroLMai

Latest chat model: V2.9bOn Hugging Face: V2.9b (Q8_0)V3 data and tools in preparationResearch 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. The V1 base was pre-trained on roughly one billion tokens; the V2 base saw about 2.1 billion. Both ran on a single consumer GPU, and the V2 base was 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. V2.9b answers the Moroccan facts it was taught even when the question is reworded, writes out its working for three-digit sums, and says it does not know for many invented names, but it still fails some of each. This page documents what we built, what we measured and where it fails.

Hover, tap or focus a layer to read its size.

Figure 1. Where the 136M parameters live, drawn to scale. The dark block is the tied token embedding (16.4M, 12.1%). Each of the 38 columns is one decoder layer (3.15M): the saffron part is attention (25%), the blue part is the SwiGLU feed-forward network (75%). Widths are computed from the model configuration, not drawn by hand.

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.

Table 1. Model configuration.
ComponentValue
Parameters135,961,088
Decoder layers38
Hidden size512
Feed-forward (SwiGLU) size1,536
Attention heads / key-value heads8 / 4 (grouped-query)
Position encodingRoPE (θ = 10,000)
NormalizationRMSNorm (ε = 1e-5)
Embeddingstied input and output
Vocabulary32,000
Context window1,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.

Table 2. Original and retrained tokenizer on 300 documents per text type. Lower tokens per word is better.
TextTokens/word, originalretrainedChars/token, originalretrained
Arabic script1.581.553.833.90
Arabizi1.601.613.803.79
English1.431.434.264.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 V1 pre-training corpus has 1.4 million documents and about one billion tokens, taken from two open web-text collections (Table 3). The V2 corpus was rebuilt in November 2026 and is larger, about 2.1 billion tokens; the V2 base was trained for about one pass over it (16,000 optimizer steps of 131,072 tokens). Its source table has not been published yet, so Table 3 describes V1 only. The tokenizer did not change.

Table 3. Pre-training sources.
SourceLanguageDocumentsLicence
FineWeb-2, subset ary_ArabMoroccan Arabic1,000,000ODC-By 1.0
FineWeb-Edu, sample-10BTEnglish400,000ODC-By 1.0

Chat data

V1 chat fine-tuning drew 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. From V2 we added training sets written for this project, mostly by program from checked fact lists: capitals, currencies and continents for more than 200 countries; Moroccan geography, football, culture and history in English, Latin-letter Darija and Arabic script; vocabulary lists; maths with the working written out; the model's identity; examples of saying I don't know for invented people, places and titles; greetings and short conversations. Loss is computed on the assistant's answer only, never on the prompt.

Table 4. Chat-tuning mixture of V2.9b, in training rows. Smaller sets are repeated so that each fact is seen in several wordings and more than once.
SourceRows keptRepeats
Earlier V1 instruction and chat mix14,6891
Project-written facts, translations, names, vocabulary, identity, "I don't know", short conversations35,8902
Moroccan facts (extra copy)6,0832
Vocabulary (extra copy)7,9492
Identity and "I don't know" (extra copy)9,0001
Maths with working20,0001
Chat extras and general chat1,9072
Multi-domain conversation examples7,2151
Total after repeats154,562

Every test sentence we report below was checked by program against the training rows, and any training row that equals a test question is removed before training. The V2.9b run used 152,123 examples after 1,931 that were too long were skipped.

Private data. The pre-training text is openly licensed web text. The chat mixture also contains examples written for this project and conversations used with the consent of their authors. None of them is uploaded or published.

The chat template is:

<|system|> …system message… <|user|> …question… <|assistant|> …answer…</s>

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.

Figure 2. Measured training throughput with gradient checkpointing. One billion tokens takes about 2.8 days on the RTX 3050 and about 18.5 hours on the RTX 5060 Ti (computed from the throughput).

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 for V1 (V1 to V1.3) and then through a series of short runs for V2, each starting again from the same pre-trained V2 base so that versions stay comparable. Each run fixed something the previous one got wrong, such as a lost name, a confused writer and director, or a wrong carry in a sum. V2.9b is the current release.

V2.9b used AdamW, bfloat16, an effective batch of 32 sequences (8 per step, 4 accumulation steps), a peak learning rate of 1e-4 decaying to 1e-5, and 2 epochs: 9,508 optimizer steps, about 6 hours 50 minutes on the RTX 5060 Ti. The speed fell from about 1.2 to about 2.7 seconds per step during the run, which we attribute to the CPU, since a model this deep and narrow is limited by how fast the CPU can launch work for the GPU. We have not confirmed the cause.

6. Results

For chat tuning we no longer report held-out loss. The validation examples share their templates with the training examples, so the number mostly measures memory and says little about behaviour. We use fixed probes instead, run at temperature 0 with repeat penalty 1.1, one fresh chat per item.

V1 pre-training reached a held-out loss of 3.4177 (perplexity 30.5) after one pass; we have not yet published a V2 pre-training loss.

Fixed probes

The probes ask taught facts in wordings that never appear in training: 16 Moroccan facts about football, geography and heritage, 8 about writers and films, name copying, identity, invented entities, and three-digit sums. They measure whether a taught fact survives rewording. They do not measure general knowledge: a fact that was never taught is not tested.

Table 5. Fixed probes, scored with the strict scorer (it also checks every step of the written-out working). Versions 2.8a and 2.9a were re-scored with the same scorer.
Probe (items)V2.8aV2.9aV2.9b
Frozen set (50)504850
Moroccan facts, three wordings each (48)434345
Writers and films, three wordings each (24)112123
Copying a user's name (12)91010
Identity (10)9910
Invented entities and unknowable questions (12)9119
Three-digit sums with working (12)9911

The V2.9b value for invented entities is 9: the scorer gave 10, and we corrected one item by hand (it said it could not know who wins in 2035 and then named a winner). The frozen set contains seven chat items and two translations that a person reads rather than scores automatically.

What we observe in chat

What works

  • Taught Moroccan facts survive rewording: the writer of Chanson douce, the director of The Blue Caftan, the 22 Wydad titles, the 2025-26 champion.
  • Greets, says who built it and does not claim to be another model.
  • Writes the working of a three-digit sum step by step, and gets 11 of 12 right.
  • Says it does not know for many invented people, places and titles.
  • Quantization to 8 bits does not visibly change the answers.

What does not

  • Some invented names still get a confident made-up fact. It answers a capital for an invented country that sounds like a real one.
  • A rare spelling of a user's name can be garbled when it is repeated.
  • One sum still carries wrongly inside its working.
  • Short conversations drift: a reply such as “I'm fine, and you?” in Darija can get an unrelated answer, and it is sensitive to how Darija is spelled in Latin letters.
  • Outside the facts it was taught, it is not a reliable source.

Why facts fail. A model with 136M parameters has little room for world knowledge. Fluency is cheap. Knowledge is not. Adding many wordings of the same fact helped far more than adding more facts, which is why the writers-and-films result rose from 11 to 23 of 24 between two runs.

The probe wordings are never trained on, but the facts are. These numbers show that rewording is handled for the facts we wrote. They are not a benchmark score.

Try the chat

You can talk to MoroLMai in your browser, with no install: a small chat site runs the Q4_K_M version of V2.9b on our own server.

Ask in English, Moroccan Darija (Latin letters or Arabic script) or Arabic. The chat can be used in English, French and Arabic, and it works on a phone.

Research demo. This is a 136M-parameter model. It answers the facts it was taught but it makes mistakes, can be confidently wrong, and is weak at long calculations. Please do not use it for medical, legal or financial advice.

  • Guest mode: try it with no account, a few messages per day.
  • Account: sign up with email or Google to keep your chat history.
  • Helping the model learn is optional. If you tick a separate box that is off by default, a person may review your chats and corrections and use them to improve MoroLMai. If you don't, your chats are never used for training. You can change this at any time and delete your account and chats from Settings.
  • Feedback: every answer has 👍, 👎 and a "write a better answer" box. Please do not type personal information.

7. Deployment

The model is exported to GGUF and served with llama.cpp. The Hugging Face page hosts V2.9b as a Q8_0 file (145 MB); earlier versions are listed there as well. 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.

Figure 3. File size by format. The 32-bit size is computed from the parameter count; the GGUF sizes are the exported files.
Table 6. GGUF variants in a local test on the developer's PC.
FormatSizeSpeedQuality
f16273 MBabout 64 tokens/sreference
Q8_0145 MBabout 100 tokens/sno visible difference
Q4_K_M86 MBnot measurednot 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.

$ llama-server -m MoroLMai-135m-v2.9b-Q8_0.gguf -c 1024

8. Roadmap

V3 targets the weaknesses in Section 6. We publish results whether or not they help.

  1. Test a retrained tokenizerDone. A 2% gain in Arabic script and none elsewhere, so we keep the original (Table 2).
  2. More pre-training dataDone for V2: a corpus of about 2.1 billion tokens and about one pass over it.
  3. A verified facts setDone and much larger than planned: thousands of checked facts about Morocco and the world, each in many wordings and three writing styles.
  4. Fix name handlingPartly done. Common names are copied correctly; rare spellings still fail.
  5. Say "I don't know" more reliablyAsk the model about thousands of invented entities, find where it answers confidently, and train on exactly those cases.
  6. Robust Darija spelling and short conversationsTrain on the many ways Moroccans type the same Darija word, and on two- to four-turn exchanges.
  7. A native review of the Darija wordingMuch of the new chat data was generated; a native speaker must read it.
  8. Tools instead of memory for maths and factsLet the model call a calculator and look facts up, instead of storing them.
  9. Compare Q4_K_M with Q8_0The smaller file is built but its answers are not yet compared.

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 is a set of fixed probes on facts we taught the model, not a standard Darija benchmark. The probes show that rewording is handled for those facts and say little about anything else.
  • Much of the V2 chat data was generated from templates and fact lists, and its Darija wording has not been fully reviewed by native speakers.
  • Moroccan facts, such as sports results, change with time. The model knows only what it was taught, up to November 2026.

10. Licences and data provenance

Table 7. Sources and their licences, as published by their authors. Check each source before any commercial use.
SourceUsed forLicence
FineWeb-2 (Moroccan Arabic)Pre-trainingODC-By 1.0
FineWeb-EduPre-trainingODC-By 1.0
Moroccan-Darija-Instruct-573KChat tuningCC BY 4.0
Other chat sources: English instructions, English dialogue, translation pairsChat tuningsee each dataset's page
Facts, vocabulary, maths and conversation examples written for this projectChat tuningproject-written

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/}
}