A language model does not pick its next token by itself. It produces logits, softmax turns them into probabilities, and a separate step called sampling chooses one token. That token is added to the text, and the whole process runs again.
The simplest choice is to always take the most likely token, known as greedy decoding. Sampling instead rolls weighted dice, so likely tokens usually win but others sometimes do.
Temperature controls how much the ranking matters. It divides every logit by a number T before softmax. A low T stretches the gaps, so the top token dominates; a high T squashes them, so the distribution flattens. Temperature never changes the order of the tokens.
A real vocabulary has tens of thousands of tokens, and most are nonsense in context. Each has a tiny probability, but together they add up, so filters cut that tail before the dice roll:
- Top-k keeps a fixed number of the most likely tokens.
- Top-p, or nucleus sampling, keeps the smallest set of top tokens whose probabilities add up to at least p.
- Min-p keeps any token whose probability is at least a set fraction of the top token’s.
Top-p and min-p adapt to how sure the model is; top-k does not. Runtimes also differ in the order they apply these steps, which changes the result. The explainer lets you set each control and see which tokens survive.