top-p sampling (nucleus sampling)
Restricting sampling to the smallest set of top tokens whose probabilities add up to at least p, then drawing from that set.
Top-p sampling (nucleus sampling) truncates the next-token distribution to the smallest set of highest-probability tokens whose cumulative probability reaches a threshold p, then samples from that set. Unlike top-k's fixed shortlist size, top-p's shortlist grows or shrinks with how peaked or flat the distribution is at each step.
Examples
With p=0.9, a very peaked distribution might keep just 3 tokens in the sampling pool, while a flatter distribution at another step might need 200 tokens to reach that same 0.9 cumulative probability.
Point table
Graph settings
Calculator