Skip to content
ML Academy

Introduced on day 39

Causal mask

A mask that sets the attention scores for future positions to minus infinity before the softmax, so each position reads only earlier ones.

In detail

Required in decoders trained on next-token prediction; without it the model reads the token it must predict and reports a near-zero loss while failing at generation. Padding masks are applied the same way to remove padded keys. A unit test is that changing a later token leaves earlier outputs unchanged.