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:
Row 1 may see keys 0 and 1, with scores 1 and 3, so key 1 gets about 0.88 and key 2 gets exactly 0.
Step through the same scores, one piece at a time:
Hide the future, one step at a timeInteractive
rows: the query, columns: the key it looks at
thecatsatthecatsat
.softmax(dim=-1) turns each row into weights that add up to 1. exp(-inf) is 0, so every later key gets exactly 0.cat (query 1) looking at sat (key 2): a later word, so it must be hidden.
In the editor, att holds new scores for the cat sat, and V holds one value per token, two numbers each. Set allowed, then wei, the masked softmax, then out = wei @ V.
Pick an answer above to see the rest
Instructions
1
Set allowed: a 3 by 3 lower triangle of True.
2
Set wei: write minus infinity where a token may not look, then take the softmax over each row.
3
Set out to wei @ V: each token's weighted average of the values.