Nucleus Sampling › Choosing the Right p Value
Language AI HandbookAll chapters Nucleus Sampling › Choosing the Right p ValueOne section · Sections in this chapter7 / 14 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
The probability threshold controls the trade-off between creativity and coherence, and choosing it well matters more than it might initially seem. Unlike top-k's , which is difficult to reason about in the abstract, has a clear semantic meaning: it is the fraction of the probability distribution you want to sample from. Higher means you're including more of the tail, which produces more varied but potentially less coherent text. Lower means you're sampling from a more concentrated distribution, producing coherent but possibly repetitive or predictable text.
Here are practical guidelines for selecting :
-
to : General-purpose creative writing. This is the most common setting and works well for open-ended writing tasks, including story and dialogue generation. The nucleus is large enough for variety but excludes the unreliable tail.
-
to : More focused generation. Useful when you want coherent output with moderate diversity, such as paraphrasing or generating multiple options for the same intent.
-
: Very focused generation. Approaches greedy decoding behavior. Use for tasks requiring high precision, like code completion or factual responses.
-
: Very permissive. Rarely used alone because it includes many low-probability tokens. Can produce surprising but occasionally incoherent outputs.
The default of has held up surprisingly well across tasks and model sizes. Holtzman et al.'s original paper used this value in their experiments, and subsequent work has largely confirmed it as a useful starting point. The intuition is that 90% of the probability mass captures virtually all the plausible options while leaving out the long tail of noise.
In practice, the right can depend on the domain and the model's calibration. A model that is well-calibrated for a specific domain, such as a fine-tuned legal document generator, may benefit from lower because the distribution is already focused on domain-appropriate vocabulary. A general-purpose model generating creative fiction may benefit from higher to encourage novelty. The best approach is to generate several passages at candidate values of and evaluate them qualitatively, since automated metrics often fail to capture the trade-off between diversity and quality.
The value of interacts with the model's overall uncertainty, which changes over the course of a sequence. The beginning of a generation tends to have more uncertainty (the model hasn't established context yet), while later tokens tend to be more constrained by prior choices. This means the effective nucleus size varies naturally across a sequence even with a fixed . In the early tokens, might yield a nucleus of 50 tokens; in later tokens constrained by prior context, it might yield a nucleus of just 3. This dynamic adaptation is one of nucleus sampling's key strengths.
Let's visualize how affects generation diversity:
