One model, many languages: mBART, mT5, XLM and XLM-R
Multilingual models share one vocabulary and one set of weights across languages. See how training data is balanced between languages, how parallel text helps, and why one accuracy number hides the languages that do worst.
What runs in CodeSplash
- LNG027mBART Explained here
- LNG028mT5 Explained here
- LNG029XLM cross-lingual language model Explained here
- LNG030XLM-R Partly runs in CodeSplash
- Text encoder (MiniLM + linear head) Not verified yet
You will be able to
- Explain temperature-based sampling of languages and what it does for rare languages
- Describe translation language modeling and why parallel text helps alignment
- Report per-language results with macro and data-weighted averages
- Use a multilingual encoder in CodeSplash and check it against an English one
Balancing the training mix
ReadWeb text is dominated by a few languages. Sampling in proportion to size would barely train the rest. mT5 and XLM-R sample a language with probability proportional to its data size raised to a power α below one:
With three languages of 1,000, 100 and 10 documents and α = 0.3, the reference program samples them with probabilities 0.571, 0.286 and 0.143. In proportion to size the smallest would get under 1%. This language samplingLanguage sampling (multilingual training)Choosing training text by language with probability proportional to data size^α (α < 1), so rare languages are seen more often. upsamples rare languages, at the risk of repeating their little text many times.
Parallel text and language codes
ReadXLM added translation language modeling: join a sentence and its translation, mask tokens in both, and predict them. To recover a masked word the model can look across to the other language, which pulls the two languages' representations together. With two masked targets at probabilities 0.6 and 0.8, the reference program's loss is 0.367.
mBART pretrains a BART-style denoiser on many languages, each text tagged with a language code; mixing per-language losses with weights gives the reference program a training loss of 1.635. A wrong language code at use time makes it write the wrong language.
One number hides the worst language
PredictPredict first
A multilingual classifier scores 90% on 1,000 English rows, 60% on 100 Swahili rows and 40% on 50 Quechua rows. How should you report it?
Reveal
Report each language, and the macro average beside the weighted one. The reference program gets a weighted accuracy of 85.2% but a macro average of 63.3%. The weighted figure mostly reports English.
A multilingual encoder in CodeSplash
ReadText encoder offers multilingual-E5-small, an encoder built on XLM-R's architecture and SentencePiece vocabulary, read by CodeSplash's own tokenizer in Python and R. On English product reviews, frozen with a linear head, its cross-validated log loss is 0.827, against 0.616 for English-only MiniLM with the same settings. Lower is better: on English text, the multilingual model loses here.
Use a multilingual encoder when your texts mix languages, and report results per language. mBART, mT5 and XLM are explained here.
Where it stands in CodeSplash
Read| Entry | In CodeSplash |
|---|---|
| mBART, mT5, XLM (LNG027–LNG029) | Explained here |
| XLM-R (LNG030) | Partly runs in CodeSplash: Encoder: multilingual-E5-small, built on XLM-R's architecture and vocabulary |
Check: multilingual models
CheckpointCheck yourself
What does mBART's language code tell the model?
Show the answer
Answer: b
Each text is tagged with a language code during pretraining and use. A wrong code steers the decoder toward the wrong language.
Check yourself
mBART's training loss mixes per-language losses with weights. What do those weights decide?
Show the answer
Answer: a
The mixing weights (or sampling rates) set each language's share of the training signal, trading high-resource quality against coverage of rare languages.
Check yourself
mT5 samples languages with probability proportional to size^α. What does lowering α toward 0 do?
Show the answer
Answer: b
α = 1 samples by size; α = 0 samples every language equally. Values between trade coverage of rare languages against repeating their little text.
Check yourself
What is the risk of a very low sampling exponent for a language with little text?
Show the answer
Answer: b
Upsampling a tiny corpus means many epochs over the same text, which invites memorization rather than generalization.
Check yourself
How does translation language modeling help align two languages?
Show the answer
Answer: b
With a sentence and its translation side by side, the cheapest way to fill a blank is often to look across languages.
Check yourself
What kind of data does translation language modeling need that ordinary masked language modeling doesn't?
Show the answer
Answer: a
Masked language modeling runs on monolingual text; translation language modeling needs aligned sentence pairs.
Check yourself
A multilingual model's data-weighted accuracy is high, its macro average much lower. What does the gap mean?
Show the answer
Answer: b
The weighted average is dominated by large languages. The macro average gives each language equal say, exposing weak ones.
Check yourself
On English-only reviews, an English encoder beats multilingual-E5-small. Why is that plausible?
Show the answer
Answer: b
Shared capacity is the cost of coverage. Pick the multilingual encoder when your texts actually mix languages.
Recap
Recap- Multilingual models share one vocabulary and one set of weights; capacity per language shrinks as languages are added.
- Sampling by size^α upsamples rare languages; too much upsampling repeats their text.
- XLM used parallel text to align languages; mBART tags texts with language codes.
- Report per-language and macro results. Text encoder runs multilingual-E5-small frozen, fine-tuned or with LoRA.
Concepts in this lesson