How it works · 16 of 37 Foundation
How does next-token prediction work, and what does temperature do?
One piece at a time
Next-token prediction & temperature: A model writes one token at a time, each time sampling from scored options; temperature controls how adventurous the pick is.
Loading the animation…
Say it like this A model writes by scoring every possible next piece and picking one, again and again; temperature sets how often it picks a less likely one.
Under the hood — for builders
- What temperature does
- It changes how many times likelier the top pick is than the long shot. The card's wheel, Paris against Lyon:
- Trim the wheel first
- Most products also cut off the long shots before spinning. Two ways, on the card's wheel:
- Which way writes best?
- How much of GPT-2's writing got stuck repeating, by how the next piece was picked:
- Each piece
- A token: a word or part of one (A4). The wheel spins once per token.
- Temperature 0
- No spin: always the biggest slice (“greedy”). Same prompt, same answer.
- Why spin at all?
- People don't write the likeliest words either (§4.3: “Natural Language Does Not Maximize Probability”).
- Starting points
- Facts, extraction, code: temperature 0. Writing and ideas: spin, trimmed to top 95%.
- Watch out
- Spinning gives different answers to the same prompt: judge on several runs, not one.
- Sources
- Holtzman, Buys, Du, Forbes & Choi, The Curious Case of Neural Text Degeneration (arXiv 1904.09751v2, 2020).
What happens in the next-token prediction & temperature animation, step by step?
- A model writes one piece at a time, and before each piece it has to choose. What comes after "The capital of France is"?
- Your turn: tap the word you think comes next.
- The model scores every possible next piece. Make the scores slices of a wheel: Paris gets 82%.
- Then it spins. A bigger slice is more likely to win, not certain to. It lands on Paris and adds it.
- Then it does it all again for the next piece, and the next. That's all writing is, for a model.
- Your turn: drag the temperature. Low makes the big slice bigger; high evens the wheel out. Watch the five spins.
- Low temperature for facts and code: the same pick every time. Higher for brainstorming: more variety, and more slips like Lyon.
What everyday example explains next-token prediction & temperature?
Phone autocomplete trained on a huge library.
Why should a team care about next-token prediction & temperature?
The creativity setting in every AI product.