Let be attention weights over scores . Derive the Jacobian and the backward rule where . For and , compute , and again for the peaky . What does this say about saturated attention?
Sequence models and transformers, Attention
Level L3 Intermediate. Length Long. Nature Mat Mathematical.
What's being asked
Whether you can derive the softmax Jacobian and apply it to see that peaky attention gives small gradients to the scores.
Key idea
, so and .
Steps
- Write with .
- For : . For : .
- In matrix form . It is symmetric, so the backward pass is .
- Case 1: . So . The entries sum to because softmax ignores a constant shift of .
- Case 2: . So .
- The gradient magnitudes drop by about a factor of . When is nearly one-hot, every entry is small, so scores (and hence ) receive almost no gradient. This is why large score magnitudes (no scaling) slow learning.
Common mistakes
- Forgetting the off-diagonal terms and using only .
- Not noticing that the rows of sum to zero.
- Using in place of times a vector of ones when subtracting.
How long your answer should be
Half a page; 5–6 minutes.
Last checked on 4 December 2026.
Read this
Previous in Sequence models and transformers: For a vanilla RNN with , show that , where is the largest singular value. What does this say for and over steps? How does gradient-norm clipping help, for example when the gradient norm is and the threshold is ?
Next in Sequence models and transformers: A decoder has layers, query heads of dimension () and stores keys and values in 16-bit floats ( bytes). How large is the KV cache for one sequence of tokens with multi-head attention (MHA), grouped-query attention with KV heads (GQA), and multi-query attention (MQA, one KV head)? How many parameters does GQA save in the and projections?