Nucleus sampling (top-p)
A sampling method (also "top-p") where the model may only choose among the smallest set of top-candidate tokens whose combined probability reaches a threshold p (e.g. 0.9). It prunes the unlikely "tail" dynamically — the number of candidates adapts to how confident the model is.
Mechanic: sort tokens by probability, sum from the top, and keep only those that together make up p of the mass (e.g. 90%); then sample among them. The clever part: when the model is very confident (one token has 95%) the nucleus is small (nearly deterministic); when it's uncertain (many equally sized alternatives) the nucleus is large (more variation) → dynamic adaptation. Distinct from top-k (which always keeps exactly k tokens, regardless of whether they're likely or not). Win: it avoids the model accidentally picking a very unlikely token (which gives nonsense) while keeping natural variation. Often combined with temperature. The most common sampling method in modern LLMs. Related to top-k and temperature.