16/23
Part 5 of 6 · Hide the futureLearn and do

Hide the future with minus infinity

The triangle is attention with equal weights. Real attention gets its weights from a softmax over scores. The scores between tokens are called att here, so the name scores keeps meaning the students' test scores. The mask goes on att, before the softmax:

allowed = torch.tril(torch.ones(3, 3, dtype=torch.bool))
att = torch.zeros(3, 3)
masked = att.masked_fill(~allowed, float("-inf"))
print(masked)
print(masked.softmax(dim=-1))
Predict

Scores of all zeros, with every later key set to minus infinity. What does each row become after the softmax?

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