Causal attention
Inspect query-key scores, masking and normalized attention weights.
Causal attention
Inspect query-key scores, masking and normalized attention weights.
Rows: queries · columns: keys
Synthetic unscaled scores are [1, 2, 4, 0] × √dₖ. The mask is applied before normalization.
Change the experiment
scores = Q @ K.T / sqrt(d_k)
scores[future_positions] = -inf
weights = softmax(scores)
output = weights @ VTry it yourself
Select the last query, increase the key dimension and disable scaling. Watch the distribution sharpen.
Query 1 attends to 1 allowed positions. Future weights are zero.
Apply the causal mask before softmax. Scaling controls score magnitude; masked positions retain exactly zero weight.
Playback pauses in hidden tabs and offscreen. With reduced motion enabled, use the timeline or Next step.Turn the idea into an implementation
Select the last query, increase the key dimension and disable scaling. Watch the distribution sharpen.
Predict a result, change one input, then explain what happened. Use the timeline to revisit a state and compare it with the algorithm sketch.
Explain it in an interview
Apply the causal mask before softmax. Scaling controls score magnitude; masked positions retain exactly zero weight.
Describe the inputs, the state that changes, the computational cost and a limitation of the model before discussing a production implementation.