Skip to main content

Review — Causal masking

Back to the lesson · Learning path plan

What to remember

  • For a query at position i, keys at positions j ≤ i are accessible. The diagonal allows access to the current position.
  • The mask blocks future-position scores before softmax, typically by setting them to negative infinity. Their weights are then zero.
  • During parallel training, position i can see token i while predicting token i + 1, which its attention cannot access.
  • This restriction makes it possible to compute the terms of the autoregressive factorization in parallel. Each term predicts the next token using only the available prefix.

Recall from memory

A training sequence contains A, B, C and D. The query at position C gives four equal scores before masking. Which token is its target? What weights does causal masking give? What weights would result from zeroing only D’s weight after softmax?

Show the answer

The target is D. The causal mask allows A, B and C, each of which gets weight \(\frac{1}{3}\), and blocks D, which gets \(0\). Applying softmax to all four equal scores and then zeroing only D’s weight leaves three weights of \(\frac{1}{4}\) that sum to \(\frac{3}{4}\).

Language · Français · English