A scalar RNN has with , and . For inputs and , what are , and the gradient ?
Sequence models and transformers, Recurrent networks
Level L2 Elementary. Length Medium. Nature Mat Mathematical.
What's being asked
Whether you can unroll a recurrence by hand and apply the chain rule through one time step.
Key idea
, because .
Steps
- Step 1: .
- Step 2: pre-activation , so .
- Local derivative: .
- Chain rule: .
- This factor is less than because both and . Over many steps such factors multiply, which is the origin of the vanishing gradient.
Common mistakes
- Using or ; the correct form is .
- Evaluating the derivative at the pre-activation instead of at .
- Forgetting the factor from the inner derivative.
How long your answer should be
Half a page of arithmetic.
Last checked on 4 December 2026.
Read this
Previous in Sequence models and transformers: A weight matrix is adapted with LoRA of rank . How many trainable parameters does LoRA add for this matrix, and what fraction of the full matrix is that? If LoRA is applied to the query and value matrices of all layers, how many trainable parameters is that in total?
Next in Sequence models and transformers: Take the sinusoidal positional encoding with , ordered as pairs, and . What is the vector for position ?