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

A worked example: six tokens, every setting

Here are all the settings at once, on the six-word row.

TokenLogitT=0.5T = 0.5T=1T = 1T=2T = 2
mat3.00.8600.6050.382
floor2.00.1160.2220.232
sofa1.00.0160.0820.140
bed0.50.0060.0500.109
roof0.00.0020.0300.085
moon-1.00.00030.0110.052
Entropy0.71 bits1.66 bits2.29 bits

Uniform over six tokens would be log⁡26=2.58\log_2 6 = 2.58 bits. Greedy says mat at every temperature. Square the T = 1 column and renormalize, and you get the T = 0.5 column, because dividing the logits by 0.5 squares the probabilities.

The same six tokens, live. Set the sliders to any row of the two tables here, and the bars match it.

Temperature, top-k and top-pInteractive
Next token after “The cat sat on the ___”
Hover a bar
KeptFiltered out
Tokens kept
6 of 6
Top token
0.60
Entropy
1.66 bits

Now the filters, each renormalized over what survives:

SettingKeptProbabilities
T=1T = 1, top-k 3mat, floor, sofa0.665, 0.245, 0.090
T=0.5T = 0.5, top-p 0.9mat, floor0.881, 0.119
T=1T = 1, top-p 0.9mat, floor, sofa0.665, 0.245, 0.090
T=2T = 2, top-p 0.9mat, floor, sofa, bed, roof0.403, 0.244, 0.148, 0.115, 0.090
T=1T = 1, top-k 3, then top-p 0.9mat, floor0.731, 0.269

Walk the T = 1, top-p 0.9 row. The running totals are 0.605, 0.827, 0.909. Sofa takes the total past 0.9, so it stays. The mass before bed is already 0.909, so bed goes.

Here's what each mistake does to this example. For the scatter row, the ids are alphabetical, bed 0 to sofa 5. With mat as id 0, the row is already sorted, and that hides the bug.

MistakeWhat you get
logits * T at T=2T = 2the T=0.5T = 0.5 column, 0.71 bits instead of 2.29
cumsum >= p at T=1T = 1, p=0.9p = 0.9mat and floor only, 0.827 of the mass
k+1k + 1 with k=3k = 3bed survives too
no scatter back at T=1T = 1, p=0.9p = 0.9bed, id 0, gets mat's 0.665, and sofa can never be drawn
sampling unfiltered at T=1T = 1, top-k 39.1% of draws are bed, roof or moon

In the editor, keep_top_k and keep_top_p are done. Finish filter_logits(logits, temperature=1.0, top_k=None, top_p=None): divide by the temperature, then top-k, then top-p, and skip a filter that is None.