Sub topic 9
Unequal Data and Temperature-Based Language Sampling
This chapter assumes that you understand Transformer pretraining, masked language modeling, and basic Python. It also assumes that you can interpret training and evaluation metrics such as accuracy and F1.
Why multilingual data is unequal
Multilingual pretraining data rarely contains the same amount of text for every language. English may have billions of words, while a low-resource language may have only a few million. If training samples are drawn in proportion to the available data, high-resource languages dominate nearly every update.
Let \(n_l\) be the number of training examples or tokens for language \(l\). With ordinary sampling, the probability of selecting that language is:
p_l = \frac{n_l}{\sum_j n_j}This approach reflects the data distribution, but it can produce weak representations for languages with little data. The model may also spend capacity learning more details about languages that already have strong resources.
A simple alternative is to duplicate low-resource data until every language has the same size. This gives small languages more influence, but repeated examples can cause overfitting. Temperature-based sampling provides a smoother compromise.
How temperature-based sampling works
Temperature-based sampling changes the language probabilities with an exponent:
p_l = \frac{n_l^\alpha}{\sum_j n_j^\alpha}Here, \(\alpha\) controls how strongly the original data sizes affect sampling.
- \(\alpha = 1\) gives ordinary, data-proportional sampling.
- \(0 < \alpha < 1\) increases the relative probability of low-resource languages.
- \(\alpha = 0\) samples every language equally.
- \(\alpha > 1\) gives even more weight to high-resource languages.
Some papers describe this with a temperature \(T\), where \(\alpha = 1/T\). Under that convention, \(T > 1\) flattens the distribution. Always check the definition used by the training system.
languages = {"en": 1000, "de": 100, "sw": 10}
alpha = 0.5
weights = {lang: count ** alpha for lang, count in languages.items()}
total = sum(weights.values())
probabilities = {
lang: weight / total for lang, weight in weights.items()
}
for lang, probability in probabilities.items():
print(f"{lang}: {probability:.3f}")With proportional sampling, the approximate probabilities are 0.901, 0.090, and 0.009. With \(\alpha=0.5\), they become approximately 0.613, 0.194, and 0.194. Swahili receives much more training exposure, while English still receives the largest share.
The trade-off between exposure and repetition
A flatter distribution helps low-resource languages, but it does not create new information. If a small corpus is sampled frequently, the model sees the same sentences repeatedly. This can produce memorization, reduce variety, or make the model less effective on other languages.
The best value of \(\alpha\) depends on several factors:
- The size and quality of each language's corpus.
- How similar the languages and writing systems are.
- Whether the task needs balanced multilingual performance or strong average performance.
- The model's parameter capacity.
- Whether the training data contains duplicates or synthetic translations.
Sampling can also be staged. Early training might use a flatter distribution to establish basic representations. Later training might use more natural proportions or task-specific data.
How to evaluate the choice
Do not judge a sampling strategy only by one overall score. Report results separately for high-, medium-, and low-resource languages. Compare the average score with a macro-average, which gives every language equal weight.
A strategy that lowers English accuracy slightly but greatly improves several low-resource languages may be preferable for a multilingual product. The correct choice depends on the intended users and the cost of errors in each language.
Exercise
A corpus contains 10,000 English examples and 100 examples in Language X. Which value of alpha gives Language X a larger relative sampling probability than proportional sampling: 1.0 or 0.5?
Show answer
0.5. Because both counts are raised to a power below one, the distribution becomes flatter and Language X receives a larger share relative to English.