Sampling and Temperature

The highest-scoring token is not the only token a model could produce. Sampling and temperature control how we choose from its predictions, changing the output without changing the learned weights.

10 sections · 9 questions · 4 coding challenges

1 / 10

Why Does Always Choosing the Favourite Produce Dull Text?

BOTIE

A sentence can have several reasonable continuations. Always selecting the highest-scoring option sounds safe, but repeated local choices can produce repetitive or uninteresting passages. Sampling indiscriminately has the opposite problem: very unlikely tokens can derail the continuation.

Holtzman and colleagues examined this difficulty in work first released in 2019. They showed that decoding choices could strongly change text quality with the same underlying language model, and proposed nucleus sampling to retain a changing set of plausible candidates.

Temperature adjusts how concentrated the probability distribution is before sampling. A lower positive temperature emphasises the larger scores; a higher one spreads probability more broadly. Top-k and nucleus sampling instead restrict which candidates remain available. These controls change how we use the learned distribution. They do not add knowledge or make randomness a substitute for a well-trained model.

Sources for this history