Sub topic 14
Limitations: tokenization disparity, low-resource gaps and fairness
This chapter assumes you have read the earlier chapters on shared subword tokenization, XLM-R pretraining, zero-shot transfer, data imbalance and per-language evaluation. You should be comfortable with the Hugging Face transformers library and with accuracy and F1. Multilingual models work well on average, but the average hides unequal costs and unequal quality. This chapter covers where those gaps come from, how to measure them, and what you can do about them.
Where the gaps come from
Three causes interact.
- Tokenization disparity. A shared vocabulary is fitted mostly on high-resource text. Other languages get split into more, shorter pieces.
- Data imbalance. Pretraining corpora hold far more text for English, Chinese, Russian and German than for Swahili, Yoruba or Quechua. Even with temperature sampling, small languages are seen fewer times and in fewer domains.
- Evaluation blind spots. Benchmarks cover a few dozen languages, and many are translated from English. A model can look fine on the benchmark and still fail on real text in a language that was never tested.
Tokenization disparity
A subword tokenizer such as SentencePiece keeps the most useful pieces for the text it was trained on. Text in a well-covered language maps to long pieces, often whole words. Text in a poorly covered language falls back to short pieces, individual characters, or even raw bytes.
The ratio of tokens to words is called fertility. A fertility near 1 means most words are single tokens. A fertility of 4 or 5 means each word is chopped up heavily.
The next script measures fertility with the XLM-R tokenizer. It counts whitespace-separated words, so it is only a rough guide for languages written without spaces, such as Chinese or Thai. It uses a parallel sentence, meaning the same content expressed in each language, which keeps the comparison fair.
from transformers import AutoTokenizer
tok = AutoTokenizer.from_pretrained("xlm-roberta-base")
texts = {
"en": "The weather is nice today.",
"de": "Das Wetter ist heute schön.",
"hi": "आज मौसम अच्छा है।",
}
for lang, text in texts.items():
pieces = tok.tokenize(text)
words = text.split()
print(
f"{lang}: tokens={len(pieces)} words={len(words)} "
f"fertility={len(pieces) / len(words):.2f}"
)
print(" ", pieces)XLM-R covers all three of these languages reasonably well, so the differences here are modest. The effect grows for languages with little vocabulary coverage, and for scripts that are rare in the pretraining data. Run the same code on a short sentence in Amharic, Burmese or Tigrinya and compare. You will usually see more pieces per word, and some pieces will be single characters.
Why this matters in practice
- Cost. Commercial APIs charge per token. The same message can cost several times more in one language than in another. Latency and memory also grow with sequence length.
- Effective context. A fixed window of 512 tokens holds fewer words in a high-fertility language. Truncation cuts off more of the document, which hurts tasks such as question answering or summarization.
- Representation quality. When a word becomes five fragments, the model must assemble its meaning across positions. Fragments are often shared with unrelated words, so the signal is noisier.
- Truncation bias in benchmarks. With
max_length=128, as in the XNLI fine-tuning script from earlier chapters, a high-fertility language loses more of its input than English does. Part of an apparent transfer gap can come from truncation rather than from the model's understanding.
Measuring disparity on parallel data
For a fair comparison, use parallel text such as FLORES-200 sentences, and report the ratio of tokens in each language to tokens in English.
from transformers import AutoTokenizer
def token_premium(tok, parallel):
"""Return tokens-per-sentence relative to English for each language."""
counts = {
lang: sum(len(tok.tokenize(s)) for s in sents)
for lang, sents in parallel.items()
}
base = counts["en"]
return {lang: c / base for lang, c in counts.items()}
tok = AutoTokenizer.from_pretrained("xlm-roberta-base")
parallel = {
"en": ["The weather is nice today.", "I would like a cup of tea."],
"de": ["Das Wetter ist heute schön.", "Ich möchte eine Tasse Tee."],
"hi": ["आज मौसम अच्छा है।", "मुझे एक कप चाय चाहिए।"],
}
for lang, ratio in token_premium(tok, parallel).items():
print(f"{lang}: {ratio:.2f}x English")With only two sentences the numbers are illustrative. For a real audit, use a few hundred sentences per language. A ratio above 1 is a token premium: you pay more, and fit less, for the same content.
Low-resource performance gaps
The earlier chapter on transfer factors showed that pretraining data size, language similarity and script all predict transfer. Here the consequence is stated plainly: low-resource languages lose on several fronts at once.
- Less pretraining text, so weaker representations from the start.
- Greater distance from the fine-tuning language, usually English, so zero-shot transfer is weaker.
- Less labeled data, so few-shot adaptation has less to work with.
- Fewer benchmarks, so problems go unnoticed.
On XNLI, for example, XLM-R usually scores several points lower on Swahili than on German after English-only fine-tuning, and the gap is larger for languages with even less data. Running the zero-shot script from the earlier chapter on en, de and sw lets you see this on your own hardware.
Languages the model never saw
XLM-R covers about 100 languages. For a language outside that list, there are three cases.
| Situation | Typical outcome | Common response |
|---|---|---|
| Language is in pretraining, little data | Usable but weak | Few-shot data, adapters, continued pretraining |
| Language is closely related to a covered one | Partial transfer | Test carefully, consider vocabulary extension |
| Language and script both absent | Mostly byte or character fragments | Continued pretraining with a new or extended vocabulary |
Zero-shot transfer to an unseen script is particularly poor, because the embeddings for its pieces were barely trained. Transliteration into a script the model knows can help in some cases, but it loses information and needs a reliable converter.
The curse of multilinguality, revisited
Adding languages divides fixed model capacity among more of them. High-resource languages can lose accuracy, and low-resource languages gain only up to a point. Larger models reduce this effect but do not remove it. So "just add more languages" is not a free fix for low-resource gaps.
Fairness and other risks
Technical gaps become fairness problems when systems are deployed to real users.
- Unequal service quality. A moderation classifier that works in English but misses abusive text in Amharic leaves speakers of that language less protected. A translation or search feature that works poorly for a language gives its speakers a worse product.
- Unequal cost. Token premiums make the same service more expensive for speakers of high-fertility languages, often in regions with lower incomes.
- Cultural bias. Models trained on web text inherit its viewpoint. Content in many languages is often translated from English, so the model may learn English-centric assumptions even in other languages.
- Dialects and code-switching. Standard varieties dominate the data. Regional dialects, informal spelling and mixed-language text, such as Hindi written in Latin script mixed with English, are handled worse.
- Misleading benchmarks. Test sets translated from English carry translation artifacts. They also test only content that English speakers wrote, not what speakers of the target language actually say.
- Hidden failure. Models often return a confident answer in a language they handle badly. Users cannot tell that quality has dropped.
What you can do
- Report per-language results. Publish the table, not only the macro average. Include the worst language and the gap between the best and worst.
- Report token cost. Include fertility or token premium next to accuracy, so cost differences are visible.
- Test on native data. Add test sets written by native speakers when they exist, and treat translated sets as an upper bound on quality.
- Choose the tokenizer deliberately. For a target language, compare candidate models on fertility before comparing accuracy.
- Adapt where it pays. Use few-shot labeled data, language adapters, or continued pretraining with an extended vocabulary for priority languages.
- Set a quality floor. Decide a minimum acceptable score per language, and either block, warn, or route to human review when a language falls below it.
- Involve speakers. Native speakers find failure modes that automatic metrics miss.
A short helper makes the first step routine. This function takes per-language scores and reports the average, the worst language, and the spread.
def fairness_report(scores):
"""scores: dict mapping language code to a metric in [0, 1]."""
mean = sum(scores.values()) / len(scores)
worst_lang = min(scores, key=scores.get)
best_lang = max(scores, key=scores.get)
return {
"mean": round(mean, 3),
"worst": (worst_lang, scores[worst_lang]),
"best": (best_lang, scores[best_lang]),
"gap": round(scores[best_lang] - scores[worst_lang], 3),
}
# Illustrative numbers, not real benchmark results
scores = {"en": 0.84, "de": 0.76, "sw": 0.66}
print(fairness_report(scores))Common mistakes
- Treating "supports 100 languages" as "works equally well in 100 languages."
- Comparing models on accuracy alone and ignoring tokenization cost.
- Judging a language by a translated benchmark only.
- Counting words by whitespace for languages that do not use spaces, which makes fertility numbers meaningless.
- Truncating at the same token limit for all languages and reading the resulting drop as a model weakness.
Exercise
A team fine-tunes XLM-R on English sentiment data and deploys it for English, German and Amharic users. The macro-average F1 on their test set is 0.80. List three separate reasons Amharic users might still receive a clearly worse service, and name one measurement that would expose each reason.
Show answer
(1) Weaker representations because Amharic has little pretraining data and is distant from English; measure per-language F1 on a native-speaker test set. (2) Tokenization disparity, since Amharic's Ge'ez script is split into many short pieces, so inputs are truncated sooner and cost more; measure fertility or token ratio to English on parallel text, and the share of inputs truncated at the length limit. (3) Benchmark mismatch, because a test set translated from English may not reflect how Amharic speakers actually write, including dialect or informal text; compare scores on translated versus natively written data. The macro average hides all three because English and German scores pull it up.
Exercise
Why can a fixed max_length=128 setting make a low-resource language look worse than it really is, and how would you check this?
Show answer
A high-fertility language needs more tokens for the same content, so more of each input is cut off at 128 tokens and the model sees less of it. To check, compute the fraction of examples whose tokenized length exceeds 128 in each language, then re-evaluate with a larger limit such as 256 and see whether the gap shrinks.