14/29
Part 4 of 6 · Top-pLearn and do

Top-p keeps the fewest tokens that reach p

A real vocabulary isn't sorted by score. Now give the six candidates ids in alphabetical order, the way a tokenizer might: bed 0, floor 1, mat 2, moon 3, roof 4 and sofa 5. by_id holds the same six scores in that order.

vocab = ["bed", "floor", "mat", "moon", "roof", "sofa"]
by_id = torch.tensor([[0.5, 2.0, 3.0, -1.0, 0.0, 1.0]])
sorted_logits, order = torch.sort(by_id, descending=True, dim=-1)
sorted_p = sorted_logits.softmax(dim=-1)
print(order)
print(sorted_p.round(decimals=3))
print(sorted_p.cumsum(dim=-1).round(decimals=3))
Predict

The same six scores, in alphabetical id order: bed 0, floor 1, mat 2, moon 3, roof 4, sofa 5. What does order, the sort's second output, print?

Pick one to see what it prints.
Pick an answer above to see the rest
Predict

At p = 0.9, how many tokens does the nucleus hold on Two plus two is, The cat sat on the and My favorite color is?

Pick an answer above to see the rest