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.
After “I’d like a cup of”, the model gives five next words a chance and draws one. Even a junk word gets its turn now and then. Which words should it keep before drawing, so they cover 80% of the chance?
keep(chances, share)| chances | one per word, adding up to 1 | e.g. [0.97, 0.01, 0.01, 0.01] |
| share | how much of the chance the kept words should cover | e.g. 0.9 |
| returns | the indexes of the words to keep | |