Top-p (nucleus) sampling

Inference · Formula · Appears in 3 lessons

Vp=min⁡{V′⊆V:∑x∈V′p(x)≥p}\mathcal{V}_p = \min \left\{ \mathcal{V}' \subseteq \mathcal{V} : \sum_{x \in \mathcal{V}'} p(x) \geq p \right\}

Keeps the smallest set of tokens whose probabilities already add up to p, then samples within it. The cutoff moves with the model's confidence, which is what makes it behave better than a fixed top-k.

Symbols

V\mathcal{V}
The full vocabulary.
Vp\mathcal{V}_p
The nucleus — the kept set.
pp
The cumulative probability mass to retain, often 0.9.
Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark