How a Model Picks Its Next Word
What Temperature Actually Does
Last timeSearching Wider
Dividing the scores by a constant before the softmax rescales every log-ratio between tokens by the same factor. Both limits are worth knowing, and neither end is creative.
Every generation interface has a temperature setting, and the usual explanation
is that it controls creativity. It controls one arithmetic operation, and
everything else follows from that operation.
- the score the model produced for token i
- the temperature, a positive constant that is the same for every token
What it does to comparisons
Take any two tokens and look at the ratio of their probabilities. The
normalising sum cancels, and what is left is an exponential of the score gap.
- the score gap, which the model decided and the temperature never touches
- divides that gap, so it raises every ratio in the vocabulary to the power of one over the temperature
The two limits
Both ends of the dial are worth knowing exactly, because both are used.
As falls towards zero, the gaps are divided by a vanishing number, so the
largest score dominates completely and the top token takes all the probability.
Temperature zero is therefore not a separate mode with its own code path: it is
the limit of this formula, and it is greedy decoding.
As grows large, every score is divided into insignificance, the exponentials
all approach one, and the distribution approaches uniform over the whole
vocabulary. At that end the model has been switched off and what remains is a
random token generator over fifty thousand items.
The lesson stops here
3 more paragraphs to go
You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.
The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.
See the planThe contentsThis is the reading half
Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.
The contents