A worked example: six tokens, every setting
Here are all the settings at once, on the six-word row.
| Token | Logit | |||
|---|---|---|---|---|
| mat | 3.0 | 0.860 | 0.605 | 0.382 |
| floor | 2.0 | 0.116 | 0.222 | 0.232 |
| sofa | 1.0 | 0.016 | 0.082 | 0.140 |
| bed | 0.5 | 0.006 | 0.050 | 0.109 |
| roof | 0.0 | 0.002 | 0.030 | 0.085 |
| moon | -1.0 | 0.0003 | 0.011 | 0.052 |
| Entropy | 0.71 bits | 1.66 bits | 2.29 bits |
Uniform over six tokens would be 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.
- Tokens kept
- 6 of 6
- Top token
- 0.60
- Entropy
- 1.66 bits
Now the filters, each renormalized over what survives:
| Setting | Kept | Probabilities |
|---|---|---|
| , top-k 3 | mat, floor, sofa | 0.665, 0.245, 0.090 |
| , top-p 0.9 | mat, floor | 0.881, 0.119 |
| , top-p 0.9 | mat, floor, sofa | 0.665, 0.245, 0.090 |
| , top-p 0.9 | mat, floor, sofa, bed, roof | 0.403, 0.244, 0.148, 0.115, 0.090 |
| , top-k 3, then top-p 0.9 | mat, floor | 0.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.
| Mistake | What you get |
|---|---|
logits * T at | the column, 0.71 bits instead of 2.29 |
cumsum >= p at , | mat and floor only, 0.827 of the mass |
| with | bed survives too |
| no scatter back at , | bed, id 0, gets mat's 0.665, and sofa can never be drawn |
| sampling unfiltered at , top-k 3 | 9.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.