Chapter 3 · Words as numbersPuff 13 of 23
Why it answers differently each time
Ask a chatbot for a bedtime story, then press “try again”. Same question, same model, a different story. Nothing about the model changed between the two. So where does the difference come from?
Guess first
You ask a chatbot the same question twice and get different answers. Why?
Play with it
The prompt
puff looked at the sea ?
Chances for the next word where the bar ends at temperature 1
Five endings
Press “Write 5 endings” to let the model finish the prompt five times.
Slide the temperature down and the top word takes over; slide it up and the chances even out. Then write five endings and see how many come out different.
How it works
Tap a step to see it in the figure.
Check yourself
What does temperature 0 give you, if you use the same prompt again and again?
Go deeper: the mathSoftmax with temperature, top-k and top-p
Temperature
A neural network doesn’t output probabilities directly. It outputs a score zi for every token i (scores can be any number), and the softmax function turns them into probabilities. Temperature T divides the scores first:
pi = ezi / TΣj ezj / T
Our word-counting model has probabilities rather than scores, but taking zi = ln pi (the natural logarithm) gives exactly the same reshaping: raise each chance to the power 1/T, then divide by the total so they add up to 1 again.
…
At T = 1 nothing changes. Below 1, big chances grow and small ones shrink. As T goes to 0, all the chance piles onto the top word, so the page treats 0 as “always take the top word”.
Top-k and top-p
Two common extra rules cut off the long tail of unlikely words before rolling. Top-k keeps only the k likeliest words. Top-p, also called nucleus sampling, keeps the smallest set of top words whose chances add up to at least p. Either way, the kept chances are scaled up to add to 1. Right now:
…
Holtzman and colleagues (2019), who proposed top-p, showed that always taking the top word makes text dull and repetitive, while sampling from the full list lets in too many odd words. Try “the cat” at temperature 0 to see the dull, repetitive kind.
What this page simplifies
This model only knows words that actually followed the prompt’s last two words in the stories, so even a high temperature only shuffles between sensible-ish options. A real chatbot gives every one of its tokens some chance, so a high enough temperature makes it write nonsense.
And temperature 0 is not always perfectly repeatable in real systems. Big models run on hardware that adds up huge lists of numbers in parallel, and tiny rounding differences can occasionally flip a near-tie between two words. On this page, 0 means identical every time.
Sources
- A. Holtzman, J. Buys, L. Du, M. Forbes and Y. Choi, The Curious Case of Neural Text Degeneration, 2019 (published at ICLR 2020).
- G. Hinton, O. Vinyals and J. Dean, Distilling the Knowledge in a Neural Network, 2015 (temperature in the softmax).
- D. Jurafsky and J. H. Martin, Speech and Language Processing, 3rd edition draft, chapters on n-gram and large language models (sampling).
- The model is the word-counting toy from the last puff, trained on the Puff stories written for this site. The dice rolls are real random numbers in your browser.