techtree / Attention / ← prev 21 of 26 next →

Causal masking

Tokens may only look backward, never at the future.

46 seconds

Transcript

A model that writes text writes one token at a time. While it works on a token, the tokens after it do not exist yet.

So each token may look at itself and the tokens before it. Never ahead.

Here are the scores, one row for each token. Every score that looks ahead is replaced with minus infinity.

Then softmax. e to the minus infinity is zero, so those weights vanish. The others still add up to one.

The first token can only look at itself. The last can look at everything.

The weights form a triangle. This is called a causal mask. Each token sees the past, and only the past.