A language model gives every possible next word a chance, and then picks one at random (“Roll a loaded die”). Most words get a tiny chance, and together that long tail of junk still gets picked now and then. Write keep(chances, share): the indexes of the words to keep before picking. No junk, but enough variety: keep the most likely words until they cover share of the chance.
| water | coffee | soup | tea | milk |
|---|---|---|---|---|
| 0.1 | 0.4 | 0.05 | 0.3 | 0.15 |