liveBook · Manning

Top-p filtering

As explained in Data Analysis with LLMs

A top_p parameter is a model-generation setting that limits eligible output tokens to a cumulative probability mass.

Top-p filtering controls model randomness by limiting eligible output tokens to a cumulative probability mass. Tokens are considered from highest to lowest probability until that mass exceeds top_p; the next token is selected from the eligible set. section 3.5.3

Use top_p with these practical guidelines:

  • Choose a value between 0 and 1; higher values admit lower-probability tokens and produce more randomization. section 3.5.3
  • Treat top_p as an alternative to temperature rather than changing both parameters in one model invocation. section 3.5.3
  • Generate multiple completions when randomness makes several answers useful, then select the preferred result through postprocessing. section 3.5.3

Comparing generated SQL queries

For one input prompt, generate multiple SQL queries with randomized settings and choose the preferred query during postprocessing. section 3.5.3

How Data Analysis with LLMs covers it

How deep it goes
Explains probability-mass selection, value range, and randomization effects without detailing token-scoring internals.
Examples
Uses multiple generated SQL queries for one prompt as a postprocessing choice.
What you can do after
Operate/configure OpenAI model generation by setting top_p between 0 and 1 as an alternative to temperature.
How it connects
Connects temperature, token selection, probability scores, and multiple completions.

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 Data Analysis with LLMs. The section links point to the parts of the book it draws on.