InferenceAI

Enter at least two characters to search.

Start free
INTERACTIVE LESSON LIBRARY

Causal attention

Inspect query-key scores, masking and normalized attention weights.

INTERACTIVE ENGINEERING · TEACHING MODEL

Causal attention

Inspect query-key scores, masking and normalized attention weights.

Rows: queries · columns: keys

Key 1
100.0%
Key 2
0.0%
Key 3
0.0%
Key 4
0.0%

Synthetic unscaled scores are [1, 2, 4, 0] × √dₖ. The mask is applied before normalization.

Change the experiment

Core calculation
scores = Q @ K.T / sqrt(d_k)
scores[future_positions] = -inf
weights = softmax(scores)
output = weights @ V
Try 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.