Every prediction drags a tail of garbage
A language model finishing “The chef seasoned the soup with ___” doesn't return one word — it returns a probability for every word it knows. Below are 15 of them, sorted. The top is sensible. The bottom is “gravel”, “sadness” and “wifi” — each near-zero, but never exactly zero. Sample from the raw distribution enough times and the tail will bite. Try it.
Probabilities are illustrative but shaped like a real LLM head: a few strong candidates, then an exponentially thin tail over the rest of a 100k-word vocabulary.
Top-k: keep the best k words, execute the rest
Top-k is the blunt fix: sort the words, keep the first k, set every other probability to zero, renormalize, then sample. Drag the slider and watch the knife move. Then sample 100 times — at k=5 the nonsense words are not just unlikely, they are impossible.
Top-p: keep words until you've banked p worth of belief
Top-p (nucleus sampling) cuts by cumulative probability mass instead of by count: walk down the sorted list adding up probabilities, and stop once the running total passes p. Each bar below shows its running cumulative total — drag p and watch the cut point find itself.
Flat vs peaked — the fight top-p won
Two prompts, two shapes. “The capital of France is ___” is peaked: one word owns almost all the mass. “My favorite color is ___” is flat: a dozen answers are all equally fine. Apply the same top-k to both, then the same top-p, and count the survivors on each side. One knife adapts. One doesn't.
The strategy race — 60 rolls, live scoreboard
Same soup prompt, four decoding strategies. Each run draws 60 samples and scores itself live on two axes that fight each other: nonsense served (tail leaks) and variety (distinct words). The perfect strategy has zero nonsense and healthy variety. See who wins.