Sub topic 8
Translate-train, translate-test and few-shot target data
This chapter assumes you have run zero-shot cross-lingual transfer, where you fine-tune XLM-R on English and evaluate on other languages. It also assumes you know what XNLI measures and can read per-language accuracy. You should be comfortable with the Hugging Face datasets and transformers libraries.
Why go beyond zero-shot
Zero-shot transfer is cheap, but it leaves accuracy on the table. The model never sees target-language text during fine-tuning, so it must rely entirely on the alignment learned in pretraining. For distant or low-resource languages, the gap to English is often large.
There are three common ways to narrow it:
- Translate-train: machine-translate the English training set into the target language and fine-tune on the translation.
- Translate-test: keep the English model, and translate each target-language input into English at inference time.
- Few-shot target data: add a small number of human-labeled target-language examples to training.
All three spend something (compute, a translation system, or annotation effort) to buy accuracy in the target language.
The three strategies at a glance
| Strategy | What changes | Extra cost | Main risk |
|---|---|---|---|
| Zero-shot | Nothing | None | Large gap for distant languages |
| Translate-train | Training data | One-time translation of the training set | Translation noise, translationese |
| Translate-test | Inference input | Translation on every request | Latency, translation errors at test time |
| Few-shot target data | Training data | Human annotation | Small sample is unrepresentative |
Translate-train
In translate-train, you run an MT system over the English training set and keep the original labels. The model then trains on target-language text, so it sees target-language tokens and syntax during fine-tuning.
XNLI ships machine-translated training sets for each of its languages, so you can try this without running any MT yourself. Only the training split is machine-translated. The test sets are human translations.
from datasets import load_dataset
en_train = load_dataset("facebook/xnli", "en", split="train")
de_train = load_dataset("facebook/xnli", "de", split="train")
print(len(en_train), len(de_train))
for i in range(2):
print("EN:", en_train[i]["premise"], "|", en_train[i]["hypothesis"])
print("DE:", de_train[i]["premise"], "|", de_train[i]["hypothesis"])
print("label:", en_train[i]["label"], de_train[i]["label"])The two splits are parallel, so the same index gives the same example in both languages with the same label. To use translate-train, replace the English training set in your fine-tuning script with de_train and evaluate on the German test set.
A common extension is translate-train-all: concatenate the English set and every translated set, and train one model on all of it. It costs more training time, but you get one model for all languages instead of one per language. In published XNLI results with XLM-R, this setup is usually the strongest of the translation-based baselines.
What goes wrong
- Translationese. Machine-translated text is more literal and more regular than natural text. A model can fit those regularities and then do worse on real, human-written target-language input. The XNLI test sets are human translations, which hides this problem somewhat.
- Label drift. Translation can change meaning, which silently changes the correct label. NLI is sensitive to this, because a hypothesis that is entailed in English may become neutral after a loose translation.
- Span and token tasks. Tasks like NER and question answering need labels attached to spans. After translation you must project those spans onto the new text with word alignment, and the projection is noisy. Translate-train is much easier for sentence-level classification than for span tasks.
Translate-test
In translate-test, you fine-tune on English as usual. At inference you translate each target-language input into English and run the English model on the result. The classifier never sees a foreign language, so it uses its full English strength.
The example below runs German NLI pairs through a German-to-English MT model and then through an English NLI classifier.
from transformers import pipeline
mt = pipeline("translation", model="Helsinki-NLP/opus-mt-de-en")
clf = pipeline("text-classification", model="roberta-large-mnli")
premise = "Das Wetter ist heute schön, und wir gehen spazieren."
hypothesis = "Es regnet stark."
premise_en = mt(premise)[0]["translation_text"]
hypothesis_en = mt(hypothesis)[0]["translation_text"]
print(premise_en, "|", hypothesis_en)
result = clf({"text": premise_en, "text_pair": hypothesis_en})
print(result)Translate the premise and hypothesis separately, as above, and use the same MT model for both. If the two sides are translated inconsistently, a shared word can end up with two different English renderings, and the model sees a contradiction that is not in the source.
What goes wrong
- Latency and cost. Every request now runs an MT model before the classifier. For high-volume services this can dominate the cost.
- Errors compound. A mistranslation cannot be recovered downstream. Names, idioms and negation are common failure points.
- Language coverage. You need a good MT system for each language pair. For many low-resource languages, MT quality is itself poor, which weakens this strategy exactly where you need it.
- Task fit. Translate-test is awkward for tasks that need output aligned to the original text, such as NER or extractive QA, because the answer span is in the translated string.
Few-shot target data
Few-shot here means fine-tuning with a small number of human-labeled target-language examples, typically tens to a few thousand. These are real examples written by native speakers, so they avoid translationese. They are also in the real test distribution, including domain and style.
The usual recipe is to mix the target examples into the English training set. If you add 100 German examples to 390,000 English ones, they are drowned out, so oversample them.
from datasets import concatenate_datasets, load_dataset
def build_mixture(k, target_lang="de", repeat=20, seed=0):
en_train = load_dataset("facebook/xnli", "en", split="train")
en_small = en_train.shuffle(seed=seed).select(range(20000))
target = load_dataset("facebook/xnli", target_lang, split="validation")
few = target.shuffle(seed=seed).select(range(k))
parts = [en_small] + [few] * repeat
return concatenate_datasets(parts).shuffle(seed=seed)
mix = build_mixture(k=100)
print(len(mix), mix[0])This sketch takes its few-shot examples from the XNLI validation split, not the test split. Keep the test set untouched: if you pick examples or tune repeat on the test set, your reported accuracy is optimistic. Pass mix to the same Trainer setup you used for zero-shot, after tokenizing it with encode.
Some practical points:
- Small k helps a lot. The first few hundred examples usually bring the biggest gain per example. Returns diminish after that.
- Sample variance is high. With 50 examples, which 50 you pick matters. Run several seeds and report mean and spread.
- Continued fine-tuning vs mixing. You can also fine-tune on English first and then on the target examples. This risks forgetting English-learned behavior, so use a low learning rate and few steps, or prefer mixing.
- Cost is annotation. If the labeling is cheap, a few hundred examples can beat a large machine-translated set. If you need experts, translation may be the only affordable route.
Choosing a strategy
Use these criteria in order:
- Do you have labeled target data? Even a small amount is worth adding, and you need some anyway to evaluate honestly.
- Is MT good for this language pair? If yes, translate-train is the default. If MT is weak, both translation strategies lose value, and few-shot data matters more.
- Is inference latency tight? If so, avoid translate-test.
- Is the task span-based? If so, prefer few-shot target data or translate-train with careful alignment, and avoid translate-test.
- How many languages? For many languages, one translate-train-all model is simpler to maintain than many per-language models or an MT service per pair.
Common errors
- Evaluating on a machine-translated test set after training on machine-translated data, which rewards translationese.
- Forgetting to translate the premise and hypothesis with the same system.
- Tuning the oversampling factor or choosing few-shot examples using the test set.
- Reporting a single average across languages and hiding per-language drops.
- Using one seed for few-shot experiments and presenting the result as stable.
Exercise
You must ship a German sentiment classifier. You have 200,000 English labeled reviews, no German labels, a good English-to-German MT model, and a strict 50 ms latency budget per request. Which strategy do you pick, and what would you add to evaluate it honestly?
Show answer
Use translate-train: translate the English reviews into German with the MT model and fine-tune the multilingual model on them. Translate-test is ruled out by the latency budget, because it adds an MT call per request. For honest evaluation, collect a small human-labeled German test set (a few hundred reviews written by native speakers) and compare against the zero-shot baseline. Those same labeled examples could later serve as few-shot training data if you split them from the test set.
Exercise
A teammate adds 50 German examples to an English training set of 390,000 and sees no change in German accuracy. Give two likely causes and one fix for each.
Show answer
First, the 50 examples are a tiny fraction of the data, so the model barely updates on them. Fix: oversample them (repeat them many times) or fine-tune on them in a short second stage. Second, 50 examples is a high-variance sample, so one draw may be unrepresentative. Fix: run several seeds with different samples and report the mean and spread, or collect more examples.