New Tool Radar

AI Concepts

How to Set Top-P Nucleus Sampling to Focus Token Choices

Set top-p to 0.9 so the model samples only from the smallest token set that reaches 90 percent probability.

Schematic with three steps: Set top-p and leave temperature alone; Generate and check the focus; Record the setting that works.

Top-p, or nucleus sampling, chooses the smallest set of tokens whose probabilities add up to p, then samples from that set. It adapts to the distribution, so it is generally preferred to top-k: when the model is confident, the set is small, and when it is unsure, the set grows. A value of 0.95 is the common default, and 0.8 to 0.9 is more focused and better for instruction following.

What you need

  • A generation task where the output should stay on track
  • Access to the top_p setting
  • A temperature setting you will leave alone while testing top-p

Step 1: Set top-p and leave temperature alone

Set top_p to 0.9 and keep temperature at its default. Change temperature or top-p, not both at once, or you will not know which change did what.

Step 2: Generate and check the focus

Generate a reply and check it stays on the task. If the output wanders, lower top-p toward 0.8; if it is too narrow, raise it toward 1.0, which applies no filtering.

Step 3: Record the setting that works

Record the top-p value that worked for this task. A value of 0.9 to 1.0 is the typical range; 0.95 is the default most APIs ship with.

Worked example: synthetic top-p test

The table below is a synthetic example. It shows the expected result of a top-p test; no model was run.

Top-p Token pool Output
1.0 All tokens Wanders off-topic
0.95 Smallest set reaching 95 percent On-topic
0.9 Smaller set Focused, on-topic
0.8 Very small set Focused but repetitive

Expected result (UNTESTED). top-p 1.0 wanders, 0.95 and 0.9 stay on-topic, and 0.8 is focused but repetitive, so 0.9 is picked. This check was not run live; the table shows the expected result for the synthetic example.

Limits

  • Change temperature or top-p, not both; changing both at once hides which one helped.
  • Top-p adapts to the distribution, so it is generally preferred to top-k.
  • Top-p 1.0 means no filtering at all; the whole vocabulary stays in play.
  • A low top-p can make the output repetitive; if it does, raise it rather than raising the temperature.

Sources

See all