For a vanilla RNN with ht=tanh⁡(Wht−1+Uxt), show that ∥∂hT/∂h0∥≤(σmax⁡(W))T, where σmax⁡ is the largest singular value. What does this say for σmax⁡=0.9 and 1.1 over T=50 steps? How does gradient-norm clipping help, for example when the gradient norm is 25 and the threshold is 5?

Sequence models and transformers, Recurrent networks
Level L3 Intermediate. Length Medium. Nature Mat Mathematical.

What's being asked

Whether you can bound a product of Jacobians and tie it to vanishing and exploding gradients and to clipping.

Key idea

∂ht∂ht−1=diag(1−ht2) W, with norm at most σmax⁡(W) because 0<1−ht2≤1. A product of T such terms has norm at most σmax⁡T.

Steps

  1. By the chain rule, ∂hT∂h0=∏t=1T∂ht∂ht−1=∏t=1Tdiag(1−ht2) W.
  2. Each diagonal matrix has entries in (0,1], so its spectral norm is at most 1. Hence ∥diag(1−ht2)W∥≤σmax⁡(W).
  3. Submultiplicativity of the norm gives ∥∂hT/∂h0∥≤σmax⁡T.
  4. If σmax⁡=0.9: 0.950=0.0052, so the gradient vanishes. This bound is a guarantee.
  5. If σmax⁡=1.1: 1.150=117. This is only an upper bound, so the gradient can explode, but is not forced to. Explosion needs a large spectral radius and active tanh units.
  6. Clipping: if ∥g∥>τ, replace g by τ g/∥g∥. With ∥g∥=25 and τ=5 the gradient is multiplied by 0.2. The direction is kept and only the step size is limited, so one huge gradient cannot throw the weights far away.
  7. Clipping cures explosion but not vanishing, which needs gated cells such as an LSTM or GRU.

Common mistakes

How long your answer should be

Half a page; 5 minutes.

Last checked on 4 December 2026.

Read this

Previous in Sequence models and transformers: LoRA computes h=W0x+αrBAx, where B∈Rd×r is initialised to zero and A∈Rr×k is random. How do you show that at initialisation the model equals the pre-trained one, what are the gradients ∂L/∂A and ∂L/∂B at the start, and what is the α/r factor for?
Next in Sequence models and transformers: Let a=softmax(s) be attention weights over scores s. Derive the Jacobian ∂ai/∂sj and the backward rule ∂L/∂s=a⊙(g−(a⊤g)1) where g=∂L/∂a. For a=(0.7,0.2,0.1) and g=(1,0,−1), compute ∂L/∂s, and again for the peaky a=(0.98,0.01,0.01). What does this say about saturated attention?