mT5 › Worked Example: Temperature Sampling in Action
Language AI HandbookAll chapters mT5 › Worked Example: Temperature Sampling in ActionOne section · Sections in this chapter8 / 11 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Let's trace through a concrete numerical example to solidify the temperature sampling concept. Suppose we have a corpus with just three languages: English (1,000 billion tokens), Turkish (10 billion tokens), and Swahili (1 billion tokens). These numbers are round but representative of the order-of-magnitude differences in the real mC4 corpus.
With proportional sampling (), the sampling probabilities are:
Under this scheme, for every 1000 training steps, Swahili appears roughly once. A typical pre-training run involves hundreds of billions of steps, so Swahili does appear many times in absolute terms, but relative to English it is almost invisible. The model's Swahili representations will be weak.
Now apply temperature sampling with . The adjusted corpus sizes are:
The new sum is approximately , giving:
Swahili's sampling probability jumped from 0.1% to 32.3%, a boost factor of over 300. Turkish went from 1.0% to 33.1%, a 33x boost. English dropped from 98.9% to 34.6%. The distribution is now nearly uniform across the three languages, which is exactly what temperature sampling is designed to achieve at high temperatures.
The practical takeaway is striking: temperature sampling turns a situation where Swahili would be nearly invisible into one where it receives roughly equal training signal to English. The model trained with temperature sampling will develop meaningful Swahili representations, while the proportionally sampled model would produce representations so weak as to be nearly useless for Swahili tasks.