179 questions
No questions match those filters.
Top-k and top-p (nucleus) sampling both restrict which...
This is one of the questions in the full AI/ML interview bank. Pro unlocks all 1789 questions; Premium includes the same bank plus the highest daily Practice limit.
See plansBoth methods exist to fix the same problem with plain (unrestricted) sampling: even a low-probability token can occasionally get drawn, and in a vocabulary of tens of thousands of tokens, that’s often enough to produce visibly bad or incoherent output. Both restrict sampling to a subset of “plausible” tokens before drawing — they differ in how that subset is defined.
Top-k sampling takes the k tokens with the highest probability, no matter what the actual shape of the distribution looks like, and samples only among those. The problem is that k is a fixed number chosen ahead of time, but the model’s confidence varies wildly by context: when the model is very certain (a sharply peaked distribution, like completing “Paris is the capital of ___”), a fixed k=40 needlessly includes many implausible tokens that shouldn’t really be in play. When the model is genuinely uncertain (a flat distribution, like continuing an open-ended creative prompt), the same k=40 may be too restrictive, excluding perfectly reasonable continuations.
Top-p sampling fixes this by defining the candidate set as the smallest set of tokens whose cumulative probability reaches a threshold p, so the set size adapts automatically — small for confident predictions, larger for uncertain ones. It generally handles both extremes more gracefully than a fixed k, which is why it’s the more common default in production systems, though it isn’t perfect: a distribution with a long, slowly-decaying tail can still let top-p admit a surprisingly large and noisy candidate set if that tail carries meaningful cumulative mass. In practice, many serving stacks combine both — a top-k cap alongside a top-p threshold — to bound the worst case of each.