Sub topic 13
Multilingual generative models and prompting across languages
This chapter assumes you know the earlier chapters on shared subword tokenization, multilingual pretraining, and zero-shot transfer. It also assumes you can load a model with Hugging Face transformers. The earlier chapters mostly used encoders such as XLM-R, which classify or tag text. Here we move to models that write text, and we look at what changes when the prompt, the task, and the output are in different languages.
From encoders to generators
Multilingual generative models follow the same recipe as XLM-R. They train one model on text from many languages with a shared vocabulary, and they hope that representations line up. The difference is the training objective and the output. The model must produce tokens in a chosen language, not just a label.
| Family | Architecture | Pretraining objective | Notes |
|---|---|---|---|
| mT5 | Encoder-decoder | Span corruption on mC4 | Covers 101 languages |
| mBART | Encoder-decoder | Denoising (reconstruct corrupted text) | Strong for translation |
| BLOOM / BLOOMZ | Decoder-only | Next-token prediction | 46 natural languages, plus code. BLOOMZ adds multitask fine-tuning on xP3 |
| Aya | Encoder-decoder (Aya 101) or decoder-only | Instruction tuning on multilingual data | Aya 101 covers 101 languages |
| Recent general LLMs | Decoder-only | Next-token prediction, then instruction tuning | Multilingual ability varies a lot by language |
Many general-purpose LLMs are not "multilingual models" by design. They see mostly English, plus a smaller share of other languages. Their multilingual ability appears anyway, and it is uneven. Always check the model card for the languages it was trained on, and test your target language yourself.
Two new failure modes
An encoder classifier always returns one of its labels. A generator can fail in more ways. Two are specific to multilingual use.
- Off-target language. You ask for a Hindi answer and get English, or a mix of both. This is sometimes called language confusion. It is more common for low-resource languages and when the instruction is in a different language than the requested output.
- Fluent but wrong content. Low-resource output can look grammatical and still be inaccurate. Generation quality in a language depends on how much of that language the model saw, and surface fluency can hide factual errors.
A third issue comes from tokenization. Generation cost grows with the number of tokens, and the earlier tokenization chapter showed that some scripts need many more tokens for the same meaning. The next snippet measures this for a decoder tokenizer.
from transformers import AutoTokenizer
tok = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-0.5B-Instruct")
texts = {
"en": "The weather is nice today, so we will walk to the market.",
"de": "Das Wetter ist heute schön, also gehen wir zum Markt.",
"sw": "Hali ya hewa ni nzuri leo, kwa hiyo tutatembea hadi sokoni.",
"hi": "आज मौसम अच्छा है, इसलिए हम बाज़ार तक पैदल जाएँगे।",
}
base = len(tok.tokenize(texts["en"]))
for lang, text in texts.items():
n = len(tok.tokenize(text))
print(f"{lang}: {n} tokens, {n / base:.2f}x English, {n / len(text):.2f} tokens/char")A language with a higher ratio costs more per request. It also fills the context window faster and takes longer to generate. Exact numbers depend on the tokenizer, so measure with the tokenizer of the model you plan to use.
Prompting across languages
When you prompt a generative model, three languages are involved, and they can all differ.
- The language of the instruction (for example, "Summarize the text").
- The language of the input (the document or question).
- The language of the output you want.
A common first question is whether to write the instruction in English or in the user's language. There is no universal answer. Many models follow English instructions most reliably, because instruction tuning data is mostly English. Native-language instructions can improve output language control and cultural fit. Studies of reasoning benchmarks such as MGSM (grade-school math problems translated into ten languages) often find that English prompts or English reasoning give better accuracy on some models. The size of the gap depends on the model and the language, so treat it as something to measure.
The script below sends the same request with an English instruction and with a Hindi instruction. It then measures how much of each reply is in Devanagari script. This gives a rough off-target check for Hindi without needing a language-identification model.
from transformers import pipeline
generator = pipeline("text-generation", model="Qwen/Qwen2.5-0.5B-Instruct")
text = "भारत में मानसून जून से सितंबर तक रहता है और खेती के लिए बहुत ज़रूरी है।"
prompts = {
"english_instruction": f"Summarize this text in one sentence. Answer in Hindi.\n\n{text}",
"hindi_instruction": f"इस पाठ का एक वाक्य में सारांश दीजिए। हिंदी में उत्तर दें।\n\n{text}",
}
def devanagari_share(s):
letters = [c for c in s if c.isalpha()]
if not letters:
return 0.0
return sum("\u0900" <= c <= "\u097f" for c in letters) / len(letters)
for name, content in prompts.items():
messages = [{"role": "user", "content": content}]
out = generator(messages, max_new_tokens=80, do_sample=False)
reply = out[0]["generated_text"][-1]["content"]
print(name, round(devanagari_share(reply), 2))
print(reply, "\n")A share near 1.0 means the reply is almost entirely in Hindi. A low share means the model drifted into English or another script. A 0.5B model is small, so expect imperfect results. That makes the failure mode easy to see. Greedy decoding (do_sample=False) keeps the comparison repeatable, but a single example proves little. Run it over many inputs before drawing conclusions.
Prompting strategies
The transfer strategies from earlier chapters have direct counterparts in prompting.
- Direct prompting. Give the instruction and input in the target language. This is the simplest option and the baseline to beat.
- Translate-test, as a pipeline. Translate the input to English, run the task in English, then translate the answer back. It works well when the model is much stronger in English, but adds cost and translation errors, and can lose language-specific nuance.
- English instruction, native input and output. Keep the instruction in English and leave the data in the target language. This often balances instruction-following quality and output fidelity.
- Few-shot examples. Put a few worked examples in the prompt. Examples in the target language show the desired output language and format. Examples in English can still help the task but give a weaker signal about output language.
- English chain of thought. Ask the model to reason step by step in English, then give the final answer in the target language. This can help reasoning tasks, but it may change tone or drop details that depend on the source language.
Instruction tuning and transfer
Cross-lingual transfer also works for instruction following. If you fine-tune a multilingual model on instructions in a few languages, it often follows instructions in other languages too. This is the same zero-shot effect as in classification. BLOOMZ is an example, as it was fine-tuned on xP3, a multitask collection covering many languages. Aya expanded this with human-written and translated instruction data for many more languages.
Transfer here has the same limits as before. Gains are largest for languages that are well represented in pretraining and similar to the tuned ones. Machine-translated instruction data can carry translation artifacts and miss local context, so mix in native data where you can.
Evaluating generation
Accuracy does not apply to open-ended output. You have a few options.
- Reference-based metrics. BLEU and chrF compare output to reference text. chrF works on character n-grams, which suits languages without clear word boundaries or with rich morphology. BLEU depends on tokenization of the reference, so scores can be misleading across languages.
- Task-based accuracy. For tasks with a checkable answer, such as MGSM math, compare the final answer directly.
- Model-based and human judgment. Judge models are usually weaker in low-resource languages, so their scores need validation by native speakers.
As in the evaluation chapter, report results per language. An average over languages hides the low-resource gap. Also report the rate of off-target-language outputs as its own number.
Common mistakes
- Assuming a model that handles French well handles Amharic equally well.
- Comparing cost across languages by request count when token counts differ by a large factor.
- Testing only with English instructions and then deploying with native users.
- Using BLEU scores to compare quality between languages.
- Judging fluency without checking factual accuracy.
Exercise
Your team deploys an instruction-tuned LLM for Swahili customer support. The replies read fluently, but a reviewer finds that some answers contain wrong policy details. Name two checks you would add, and explain why a Devanagari-style script check would not help here.
Show answer
Add (1) a review of a sample of replies by fluent Swahili speakers, comparing the content to the actual policy, and (2) an automatic language-identification check for off-target language, since Swahili replies can drift into English. You could also compare against the same questions asked in English to see whether the error rate is language-specific. A script check cannot work because Swahili and English both use the Latin alphabet, so a reply in the wrong language looks identical at the character level. The script check also says nothing about factual accuracy.
Exercise
A tokenizer produces 30 tokens for an English sentence and 90 tokens for the same sentence in another language. The model charges per token and has a 4,096-token context window. Roughly how do cost and usable context compare between the two languages, ignoring the output?
Show answer
The second language costs about 3 times as much per sentence (90 / 30). The context window holds about a third as many sentences of that language: roughly 136 sentences (4096 / 30) in English against roughly 45 (4096 / 90). Generation is also slower, because the model must produce about 3 times as many tokens for the same content.