Open Agent School · Public worked example

Top-p sampling: meaning and example

Welcome! Take one idea with you today.

A generation method that samples from the smallest leading set of candidate tokens whose combined probability reaches a chosen threshold p.

Picture it: The candidate set is small when one token dominates and larger when probability is spread out.

What is easy to mix up?

Unlike top-k, the number of candidates can change at each step. Neither setting guarantees correct answers.

Teaching example by Open Agent School. Source: Google - Machine Learning Glossary.