liveBook · Manning

Top-p filtering

As explained in Machine Learning Platform Engineering

Top-P sampling generates each token from the smallest set of candidates whose cumulative probability reaches a specified threshold.

Top-P filtering, also called nucleus sampling, generates each token from the smallest candidate set whose cumulative probability reaches a configured threshold. Unlike Top-K sampling, it adapts vocabulary size to model confidence: confident predictions consider fewer tokens, while uncertain predictions consider more. This controlled randomness supports varied responses without admitting the full tail of unlikely candidates. section 12.1.1

Use the sampling threshold according to the response goal:

  • Favor deterministic, consistent behavior for factual retrieval by using temperature 0; Top-P is part of the broader randomness configuration. section 12.1.1
  • Allow controlled variation for creative generation, brainstorming, research assistance, or conversational responses. section 12.1.1
Listing 12.1 Parameters that control output randomness
temperature=0.0  #1
temperature=0.7  #2
temperature=1.5  #3

top_k=1 #4
top_k=40  #5
top_k=100  #6

top_p=0.1  #7
top_p=0.9  #8
top_p=1.0 #9

Compare sample Top-P configurations of 0.1, 0.9, and 1.0 alongside temperature and Top-K settings. section 12.1.1

How Machine Learning Platform Engineering covers it

How deep it goes
Defines dynamic cumulative-probability selection and contrasts it with fixed-size Top-K sampling, without detailing implementation internals.
Examples
Uses Top-P settings of 0.1, 0.9, and 1.0 in a parameter listing.
What it assumes
Assumes familiarity with token probabilities while defining cumulative-probability candidate selection directly.
What you can do after
Apply it via sampling configuration to balance response variety and coherence for a chosen application.
How it connects
Connects Top-P sampling with temperature, Top-K sampling, nondeterminism, and creative generation.

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 Machine Learning Platform Engineering. The section links point to the parts of the book it draws on.