Graph
Nucleus Sampling

🧪Nucleus Sampling

NEW

Also known as: Top-p Sampling

Sampling from the smallest set of tokens whose cumulative probability exceeds p.

DESCRIPTION

Nucleus sampling selects from the minimal set of tokens whose cumulative probability mass exceeds threshold p. Unlike Top-k, the candidate set adapts to distribution shape, improving fluency in heavy-tailed contexts. Proper p balances creativity and coherence; values around 0.8–0.95 are common. It often pairs with temperature to refine randomness. Introduced to combat neural text degeneration from low-probability tails.

ALTERNATIVE DEFINITIONS

arXiv

We propose nucleus sampling, which considers the smallest set of tokens whose cumulative probability mass exceeds the threshold p.

Original paper defining the core idea and motivation.

Source

Hugging Face

Nucleus (top-p) sampling chooses from the smallest set of tokens with cumulative probability ≥ p.

Matches paper definition and clarifies cumulative mass criterion.

Source

Temperature Greedy Decoding Beam Search Language Model Probability Mass Entropy Decoding Strategies

COMPETING TERMS

Top-k Sampling

RELATIONS

KNOWLEDGE AREAS

AI Data Science

TARGET AUDIENCE

AI Engineer Data Scientist MLOps Engineer

EXTERNAL SOURCES

TOP QUESTIONS

How does Nucleus Sampling work?

It dynamically selects the smallest token set whose cumulative probability exceeds p, then samples from that set.

Category: Definition

Why use Nucleus instead of Top-k?

It adapts to distribution shape, avoiding degenerate tails when the top probabilities are diffuse or peaked.

Category: Comparison

How should I pick p?

Start around 0.9 and adjust: lower p for coherence, higher p for diversity, validating against your task metrics.

Category: How-to

Can I combine p with temperature?

Yes. Temperature modulates randomness within the nucleus; tune jointly for desired style and accuracy.

Category: Application

Does Top-p ensure factuality?

No. It shapes diversity, not truthfulness. Use retrieval, constraints, or post-hoc verification for factuality.

Category: Misunderstanding

What risks does Nucleus Sampling have?

Too high p can introduce rambling or off-topic content. Calibrate carefully per domain.

Category: Risk

Is Nucleus deterministic?

No. It is stochastic; outputs vary across runs even with the same p.

Category: Definition

How to evaluate Top-p outputs?

Use human and automated metrics. Compare across p values, with baselines like greedy or Top-k.

Category: Evaluation

Where did Nucleus Sampling originate?

It was proposed by Holtzman et al. in 2019 to mitigate neural text degeneration.

Category: Origin