liveBook · Manning

Top-p filtering

As explained in Building Reliable AI Systems

Top-p sampling is a language-model generation setting that samples from the smallest set of tokens whose cumulative probability reaches a specified threshold.

Top-p filtering, also called nucleus sampling, limits which tokens an LLM considers at each generation step. It keeps the smallest set of the most probable tokens whose cumulative probability reaches the chosen threshold, then samples from that set. At top-p 0.9, lower-probability tokens outside the 90% pool are excluded. section 2.2.2

Tune top-p when a response needs a different balance of variety and focus. A higher value admits more candidate tokens; a lower value narrows the pool. This can improve coherence and reduce the risk of irrelevant or inconsistent choices, but a narrower pool does not itself establish that a response is accurate. section 2.2.2 section 2.2

Product recommendation

For a request about wireless headphones for a daily commute, top-p 0.95 may allow a detailed recommendation covering comfort, battery life, and noise cancellation. At 0.5, the response may be more focused but less comprehensive. The setting changes which wording is available to sample; it does not verify the product claims. section 2.2.2

Treat top-p as one generation control alongside temperature, maximum output length, stop sequences, and penalty strengths. Adjust it for the task’s desired response style rather than treating any single value as a guarantee against hallucinations. section 2.2 section 2.2.2

How Building Reliable AI Systems covers it

How deep it goes
Defines the cumulative-probability threshold and compares two settings in a chatbot scenario, without providing API code or a tuning procedure.
Examples
Contrasts wireless-headphone recommendations at top-p 0.95 and 0.5 to show the difference between detail and focus.
What it assumes
Assumes familiarity with LLM prompting and temperature while defining top-p’s cumulative-probability threshold.
What you can do after
Operate/configure it by adjusting top-p to narrow or broaden candidate tokens for a desired response style.
How it connects
Relates top-p to temperature, maximum output length, stop sequences, penalty strengths, and hallucinations.

Also explained in

Compare how 12 books explain top-p filtering →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Reliable AI Systems. The section links point to the parts of the book it draws on.