LLM Library
Running and Using LLMsAnimated
Decoding and Sampling
How the next token is chosen from the probabilities.
The idea
Greedy decoding takes the top token. Sampling draws from the distribution, shaped by temperature, top-k (keep k best) and top-p (keep the smallest set adding to p).
Watch it work
Press play, pause, or step through. Some animations have settings you can change.
- candidates kept
- chosen
The model produces a raw score (logit) for every word in its vocabulary. Only eight are shown here.
1/4
Temperature reshapes the probabilities; top-k and top-p cut the tail.
Step by step
- 1Compute logits
- 2Divide by temperature and apply softmax
- 3Cut the tail with top-k or top-p
- 4Draw one token
Where it is used
Every generated answer.
Watch out for
Low temperature is steady; high temperature is creative but less reliable.