MM

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 −∞-\infty to a score before softmax removes that option. Since e−∞=0e^{-\infty} = 0, that position gets exactly zero weight, contributes nothing, and receives no gradient.

The causal mask sets Mij=−∞M_{ij} = -\infty whenever j>ij > i, so token ii cannot look at later tokens. In code, a large negative number such as −109-10^9 is used in place of −∞-\infty to avoid arithmetic with true infinities.

Example

M=[0−∞−∞00−∞000]M = \begin{bmatrix} 0 & -\infty & -\infty \\ 0 & 0 & -\infty \\ 0 & 0 & 0 \end{bmatrix}

Causal mask for 3 tokens: row i may see columns up to i and nothing after.

Where the course uses it

Related terms