19/29
Part 5 of 6 · The whole samplerLearn and do

After top-k, p is a share of what top-k kept

When top-k runs first, top-p sees fewer tokens, and that changes what p means. Top-k 3 keeps mat, floor and sofa, and the softmax spreads all the weight over those three. Top-p then reads that renormalized row, not the full distribution.

Flip top-k 3 first off and on, and watch sofa come and go.

Top-p after top-kInteractive
probbeforetotal
mat0.6650.0000.665.
floor0.2450.6650.910crosses p
sofa0.0900.9101.000.
After top-k 3, the shares are renormalized over the 3 kept. Mat makes 0.665, short of p = 0.90. Adding floor makes 0.910, which reaches it, so floor stays. The nucleus is mat and floor.

So after top-k, p is a share of what top-k kept, not of the whole vocabulary.

In the editor are keep_top_k and keep_top_p again. Set full_share: the probability that mat and floor hold in the full softmax. Set kept_share: the share they hold after top-k 3. Set both: the words that survive top-k 3 and then top-p 0.9, as a list.