15/29
Part 4 of 6 · Top-pLearn and do
Drop a token only when the tokens before it already reach p
Top-p needs a careful rule for the token that crosses p.
The rule that works: drop a token only when the mass before it already reaches p. Mat has 0 before it, floor 0.605, sofa 0.827 and bed 0.909. At p = 0.9, sofa stays and bed goes.
The top token always has exactly 0 before it. So it stays for any p above 0, and keeping at least one token comes for free.
In the editor, sorted_p holds the six probabilities, largest first. Write drop_mask(sorted_p, p): True where a token goes, because the tokens before it already reach p.