M — the attention mask
A matrix of 0s and −∞ (minus infinity) added to the attention scores before softmax. A 0 leaves a position allowed; −∞ blocks it.
Adding to a score before softmax removes that option. Since , that position gets exactly zero weight, contributes nothing, and receives no gradient.
The causal mask sets whenever , so token cannot look at later tokens. In code, a large negative number such as is used in place of to avoid arithmetic with true infinities.
Example
Causal mask for 3 tokens: row i may see columns up to i and nothing after.
Where the course uses it
Related terms
- The exponential functionRead "e to the z" (also written exp(z)). It raises e ≈ 2.718 to the power z. The result is always positive: e⁰ = 1, and it shrinks toward 0 as z becomes very negative.
- Cases — an if/elseA large left brace with several lines is an if/else written vertically. Read each line as "this value, if this condition holds" and use the line whose condition is true.
- Scaled dot-product attentionEach token scores every other token, turns the scores into weights that add up to 1, and takes the weighted average of their value vectors.