14/25
Part 3 of 6 · The maskLearn

Masking after the softmax leaves rows that sum to less than 1

Here are the numbers for that shortcut, on the same scores.

# softmax first, then zero the future
late = softmax(scores) * allowed
print(late.round(2))
print(late.sum(axis=-1).round(2))
[[0.09 0.   0.  ]
 [0.09 0.24 0.  ]
 [0.09 0.24 0.67]]
[0.09 0.33 1.  ]

Each row is the softmax of all three scores, with the future cut off afterwards. The weight the future took is simply gone.

QueryKept weightsRow sumLost
q10.090.090.24 + 0.67
q20.09, 0.240.330.67
q30.09, 0.24, 0.671.00nothing