Top-p, or nucleus sampling, controls the cumulative probability of the top tokens to consider: the model keeps the smallest set of most likely tokens whose probabilities add up to p, and picks from that set only. With top-p at 1.0 every token is considered; with top-p at 0.9 only the tokens covering 90 percent of the probability are considered. It narrows the choice without fixing a token count.
Prerequisites
- Access to the top_p parameter in your API or runtime.
- A question where the answer should stay on topic.
- A way to run the same question at two settings.
Steps
Step 1: Understand the pool
Think of top-p as a pool size that adapts: when the model is confident, the pool is small, because a few tokens cover 90 percent; when it is unsure, the pool is larger. That is the difference from top-k, which fixes the count.
Step 2: Set top-p to 0.9
Set top_p to 0.9 and leave temperature at its default. Do not change temperature as well; the guidance is to alter one or the other, not both, so you can tell what changed.
Step 3: Compare the answers
Run the question at top-p 1.0 and at 0.9 and compare. The 0.9 answers should stay closer to the topic, with fewer odd turns of phrase.
Worked example: Bluebell Bakery product description
The fictional Bluebell Bakery asks a model to describe a sourdough loaf. At top-p 1.0 the description wanders; at 0.9 it stays on the loaf.
| Setting | Tokens considered | Description stays on topic |
|---|---|---|
| top-p 1.0 | All tokens | Wanders to unrelated topics |
| top-p 0.9 | Tokens covering 90% of probability | Stays on the loaf |
At top-p 0.9 the description stays on the loaf, while at 1.0 it wanders, so the narrower pool keeps the answer on topic.
Expected result. The answer at top-p 0.9 stays on topic more reliably than at 1.0, with temperature unchanged. UNTESTED: this guide was not run against a live model or API. The worked example below is fictional practice material, and its result is the expected result, not a measured one.
Limits
- Top-p is a sampling control, not a truth control; a focused wrong answer is still wrong.
- Some providers have deprecated top_p; check your provider’s current reference.
- Very low top-p values can make the output repetitive.
