Sub topic 10
The Curse of Multilinguality
This chapter assumes you know how a multilingual masked language model is pretrained (mBERT, XLM-R), what a shared subword vocabulary is, and how zero-shot transfer is evaluated. You should also be able to read basic Python with transformers.
The observation
Adding languages to a multilingual model helps at first. Low-resource languages gain from related high-resource ones, and cross-lingual alignment improves. If you keep adding languages while the model size stays fixed, average quality eventually drops, and it drops on the languages you already had.
Conneau et al. (2020) named this the curse of multilinguality in the XLM-R paper. They trained models on 7, 15, 30, 60 and 100 languages with fixed capacity and measured XNLI accuracy. Accuracy rose and then fell as the language count grew. Larger models, with more hidden units and layers, pushed the turning point further out.
The curse is a capacity trade-off. It is not a bug. A model with a fixed number of parameters has to cover every language's vocabulary, morphology, syntax and world knowledge.
Why it happens
Three mechanisms contribute. Their relative weight is still debated, so treat them as working explanations.
- Limited parameters. Each added language needs some capacity of its own, such as script handling, rare word forms and idioms. The shared Transformer layers must serve all languages at once.
- Vocabulary pressure. A fixed-size vocabulary is divided among all scripts. With more languages, each one gets fewer dedicated subwords. Text is then split into more, shorter pieces. This raises sequence length and weakens the signal per token.
- Negative interference. Gradients from different languages can conflict. Wang et al. (2020) found that sharing parameters can hurt a language when other languages pull the same weights in different directions. The effect is stronger for dissimilar languages and for low-resource languages.
The opposite effect is positive transfer. Related languages (Spanish and Portuguese, say) share vocabulary and structure, so training on one helps the other. Whether a language pair helps or hurts depends on similarity, script overlap and data size.
Where the parameters go
In a multilingual encoder, much of the capacity is not in the Transformer layers. It is in the embedding matrix. The following script compares an English-only model with XLM-R.
from transformers import AutoModel
for name in ["bert-base-uncased", "xlm-roberta-base"]:
model = AutoModel.from_pretrained(name)
total = sum(p.numel() for p in model.parameters())
emb = model.get_input_embeddings().weight.numel()
print(f"{name}: total={total / 1e6:.0f}M, "
f"embeddings={emb / 1e6:.0f}M ({100 * emb / total:.0f}%), "
f"transformer and other={(total - emb) / 1e6:.0f}M")You should see roughly 110M total parameters for BERT-base, of which about 23M are embeddings. For XLM-R base you should see roughly 278M total, of which about 192M are embeddings. The vocabulary has about 250,000 entries, against about 30,000 for English BERT. The Transformer body is almost the same size in both models, roughly 85M parameters.
This has a practical meaning. XLM-R base is "bigger" mostly because it has a bigger lookup table. The layers that do the contextual computation are no larger than in English BERT. Those layers must still serve 100 languages. Per language, they are stretched thin.
Levers for reducing the curse
| Lever | What it changes | Cost or risk |
|---|---|---|
| Larger model | More parameters for all languages | Training and inference cost |
| Larger vocabulary | More subwords per script, shorter sequences | Bigger embedding and output matrices |
| Language sampling | Balance between high- and low-resource languages | Over-sampled low-resource data is repeated and can be overfit |
| Fewer, better-chosen languages | Less competition for capacity | Languages left out get no direct support |
| Language-specific modules (adapters, X-MOD) | Dedicated parameters per language | More components to train and store |
| Targeted continued pretraining | Specializes a model to a language group | Can forget other languages |
Larger models are the most direct fix, and XLM-R large (about 560M parameters) shows much smaller losses than the base size when languages are added. The other levers work on how the fixed capacity is spent.
Sampling and the curse
Pretraining corpora are very unbalanced. English can have hundreds of times more text than Swahili. If you sample batches in proportion to corpus size, low-resource languages almost never appear and the model learns them poorly. If you sample uniformly, small languages are repeated many times and the model overfits them, while high-resource languages are under-trained.
The standard compromise is exponentiated sampling. The probability of drawing language i is proportional to its share raised to a power α between 0 and 1. XLM-R used α = 0.3, and mBERT used 0.7 for its smoothing. A smaller α flattens the distribution. The next chapter-level topic, unequal data, treats this in detail. Here the relevant point is that sampling shifts where the curse bites. It does not remove the curse.
sizes = {"en": 300.0, "de": 60.0, "ur": 6.0, "sw": 2.0} # illustrative sizes in GB
def sampling_probs(sizes, alpha):
total = sum(sizes.values())
weights = {lang: (n / total) ** alpha for lang, n in sizes.items()}
norm = sum(weights.values())
return {lang: w / norm for lang, w in weights.items()}
for alpha in (1.0, 0.7, 0.3):
probs = sampling_probs(sizes, alpha)
row = ", ".join(f"{lang}={p:.3f}" for lang, p in probs.items())
print(f"alpha={alpha}: {row}")At α = 1.0 English is drawn about 81% of the time and Swahili about half a percent. At α = 0.3 the shares are much closer. Lowering α helps the small languages, but it takes capacity and training steps away from English. At fixed capacity, that is the curse in miniature.
Practical consequences
- Compare against a monolingual baseline. If a language has a decent monolingual model, check whether the multilingual model beats it. For high-resource languages it often does not.
- Choose model size with the language count. A base-size model covering 100 languages is under more pressure than a base-size model covering 10.
- Prefer a smaller language set when you can. If your application only needs 10 related languages, a model trained on those can outperform a 100-language model of the same size.
- Check per-language results, not the average. An improving average can hide a language that got worse. Report each language separately, as the evaluation chapter recommends.
- Watch sequence length. A language that is split into many pieces uses more of the context window and costs more compute. This is a symptom of vocabulary pressure.
Common mistakes
- Reading the average XNLI score of a 100-language model and assuming each language is served equally.
- Counting only Transformer layers when estimating capacity. The embedding matrix is a large share of the parameters but does little contextual computation.
- Assuming that raising the sampling exponent α is free. Each change redistributes a fixed training budget.
- Treating the curse as a purely vocabulary problem. Increasing vocabulary size reduces over-fragmentation but does not remove interference in the shared layers.
Exercise
A team pretrains two base-size encoders with the same number of Transformer layers and hidden size. Model A covers 10 related European languages. Model B covers 100 languages from many scripts. On a German task, Model A scores higher than Model B even though both received the same German data. Give two mechanisms that could explain this, and name one change that would most directly narrow the gap without reducing the language set.
Show answer
Possible mechanisms: (1) capacity dilution, since Model B's shared layers must serve 100 languages and have fewer parameters effectively available for German; (2) negative interference, since gradients from dissimilar languages conflict with those from German. Vocabulary pressure is a valid third answer, because a vocabulary shared by many scripts leaves fewer dedicated subwords for German. The most direct change is to increase model capacity, for example moving from base to large size. Adding language-specific modules such as adapters is also acceptable.