Skip to content
Query Feedz
  • News
  • Business
    • Digital Marketing
      • Marketing & Sales
      • SEO
      • Content Marketing
      • AEO and GEO
    • Startups
      • Founder Stories
      • Funding & VC
      • Product & Growth
    • Money
      • Investing
      • Markets & Economy
      • Saving & Budgeting
  • AI & Technology
    • Technology
      • Consumer Tech
      • CRM
      • Cyber Security
      • Software Engineering
      • WordPress
      • Hardware
    • Artificial IntelligenceAI Glossary
      • LLMs
      • Machine Learning
      • AI Fundamentals
      • Generative AI
      • Deep Learning
    • AI Use Cases
      • Automation
      • Content
      • Customer Support
      • Finance
      • Marketing
      • View All
  • Tools & Software
  • Account
    • Submit Guest Post
    • Submit a tool
    • My listing
  • Contact
QueryFeedz
  • News
  • Business
    • Digital Marketing
      • Marketing & Sales
      • SEO
      • Content Marketing
      • AEO and GEO
    • Startups
      • Founder Stories
      • Funding & VC
      • Product & Growth
    • Money
      • Investing
      • Markets & Economy
      • Saving & Budgeting
  • AI & Technology
    • Technology
      • Consumer Tech
      • CRM
      • Cyber Security
      • Software Engineering
      • WordPress
      • Hardware
    • Artificial IntelligenceAI Glossary
      • LLMs
      • Machine Learning
      • AI Fundamentals
      • Generative AI
      • Deep Learning
    • AI Use Cases
      • Automation
      • Content
      • Customer Support
      • Finance
      • Marketing
      • View All
  • Tools & Software
  • Account
    • Submit Guest Post
    • Submit a tool
    • My listing
  • Contact
QueryFeedz
  1. Home /
  2. AI Glossaries /
  3. LLMs /
  4. What is Top-p Sampling (Nucleus Sampling)?
LLMs

What is Top-p Sampling (Nucleus Sampling)?

Updated September 26, 2026 Read 2 min

Top-p sampling, also called nucleus sampling, keeps the smallest group of tokens whose probabilities add up to p, then samples from that group. The shortlist adapts automatically to how confident the model is.

Contents 11
  1. 01Key takeaways
  2. 02Top-p sampling explained in simple terms
  3. 03How it works
  4. 04A worked example with p = 0.9
  5. 05Why it beats a fixed k
  6. 06Typical settings
  7. 07Combining with other settings
  8. 08Limitations
  9. 09Common Use Cases
  10. 10Frequently Asked Questions
  11. 11Related Terms

Top-p sampling, also called nucleus sampling, keeps the smallest group of tokens whose probabilities add up to at least p, then samples from that group. Unlike top-k sampling, which uses a fixed shortlist size, top-p adapts: when the model is confident the shortlist is tiny, and when many continuations are plausible the shortlist grows. It was introduced by Ari Holtzman and colleagues in 2019 in work on neural text degeneration.

Key takeaways

  • p is a probability threshold, commonly 0.9 or 0.95.
  • The shortlist, or “nucleus”, changes size at every step.
  • It avoids both bland repetition and nonsensical rare tokens.
  • p = 1.0 means no filtering; very low p approaches greedy decoding.
  • Most providers suggest tuning either top-p or temperature, not both.

Top-p sampling explained in simple terms

Instead of always shortlisting five restaurants, you shortlist however many it takes to cover 90% of what you would actually consider. On a night when one place is clearly right, the shortlist has one entry. When many appeal equally, it has fifteen. The rule adapts to the situation.

How it works

  1. Sort tokens by probability, highest first.
  2. Add them up until the running total reaches p.
  3. Discard everything else.
  4. Renormalise the kept probabilities.
  5. Sample one token from that nucleus.

A worked example with p = 0.9

Confident case, after “The capital of Japan is”:

TokenProbabilityRunning total
” Tokyo”0.950.95 ✓ reached

The nucleus contains one token. Output is effectively deterministic.

Uncertain case, after “She picked up the”:

TokenProbabilityRunning total
” phone”0.200.20
” book”0.150.35
” bag”0.120.47
” pen”0.100.57
… several more …0.90 ✓ reached after about 12 tokens

Here the nucleus holds around a dozen tokens, giving natural variety.

Why it beats a fixed k

Human text is not the most probable text, but it is also not random. Holtzman’s research showed that maximisation methods such as beam search produce repetitive, unnatural output, while unrestricted sampling produces incoherence. Nucleus sampling targets the middle: sample from the meaningful mass of probability and cut the long tail.

Typical settings

TaskSuggested p
Data extraction, structured output0.1–0.5, or greedy
Factual answers and code0.5–0.8
General chat and writing0.9–0.95
Creative brainstorming0.95–1.0

Combining with other settings

Many APIs apply temperature first, then top-p filtering, then sampling, sometimes with top-k and penalties as well. Since temperature and top-p both control randomness, adjusting one at a time makes behaviour easier to reason about.

Limitations

  • Does not prevent factual errors or hallucination.
  • Very low p can cause repetition, like greedy decoding.
  • Interacts with temperature in ways that can be confusing.
  • Optimal values differ between models and tasks.

Common Use Cases

01

General chat

Produce natural, varied replies at p around 0.9–0.95.

02

Content drafting

Generate multiple distinct drafts of the same brief.

03

Structured output

Use low p for consistent, predictable formats.

04

Code generation

Balance correctness and variety at moderate p.

05

Dialogue variety

Avoid repeating identical phrasing across turns.

06

A/B copy testing

Create several wording variants for testing.

Frequently Asked Questions

A decoding method that keeps the smallest set of tokens whose probabilities reach p, then samples from that set.

Yes. Nucleus sampling is the original name for top-p sampling.

Around 0.9–0.95 for general writing, lower for factual or structured tasks.

Top-p adapts the shortlist size to the model's confidence; top-k always keeps a fixed number of tokens.

Most providers suggest adjusting one at a time, since both control randomness.

Related Terms

  • Top-k Sampling
  • Temperature in LLMs
  • Greedy Decoding
  • Beam Search
  • Probability Distribution in an LLM
  • LLM Inference

Related AI Terms

What is Multi-Head Attention?Multi-head attention runs several attention operations in parallel, each with its own learned projections, so a model can…What is Prefix Tuning?Prefix tuning is a parameter-efficient fine-tuning method that learns trainable vectors inserted into the attention keys and values…What is an Encoder-Decoder Model?An encoder-decoder model, also called a sequence-to-sequence model, uses one component to read and understand the input and…What is an Attention Mechanism?An attention mechanism is a technique that lets a neural network focus on the most relevant parts of…What is Self-Attention?Self-attention is a mechanism where each position in a sequence attends to every other position in the same…What is Positional Encoding?Positional encoding is the method transformers use to represent the order of tokens in a sequence, because the…

Contents

  1. 01Key takeaways
  2. 02Top-p sampling explained in simple terms
  3. 03How it works
  4. 04A worked example with p = 0.9
  5. 05Why it beats a fixed k
  6. 06Typical settings
  7. 07Combining with other settings
  8. 08Limitations
  9. 09Common Use Cases
  10. 10Frequently Asked Questions
  11. 11Related Terms

AI Topic

  • LLMs

Related Terms

  • What is Multi-Head Attention?
  • What is Prefix Tuning?
  • What is an Encoder-Decoder Model?
  • What is an Attention Mechanism?
  • What is Self-Attention?
  • What is Positional Encoding?

Quick Navigation

  • Common Use Cases
  • Frequently Asked Questions
  • Related Terms
  • Back to top

Details

Updated
September 26, 2026
Read
2 min
  • Forum
  • Submit a tool
  • Submit Guest Post
  • List Your Startup
  • Privacy Policy
  • Editorial Policy
  • Account
  • Contact
  • AI Productivity
  • AI Video
  • AI Coding
  • AI Chatbots
  • Sales
  • AI Business
  • View All Tools

Subscribe our Newsletter

Get weekly exclusive content - No spam.

Copyright © 2026 -  Query Feedz

Manage Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
  • Manage options
  • Manage services
  • Manage {vendor_count} vendors
  • Read more about these purposes
View preferences
  • {title}
  • {title}
  • {title}