← LLM Core & Architecture
Top-P Sampling
Also known as: nucleus sampling
Top-P sampling — also called nucleus sampling — selects the next token by restricting the candidate set to the smallest subset of tokens whose cumulative probability mass equals or exceeds a threshold P, then sampling uniformly from that subset. Unlike top-K, which uses a fixed count, top-P adapts the candidate set size to the model's confidence: for peaked distributions the nucleus is small, and for flat distributions it is large. Values around 0.9–0.95 are common in practice.