∂hT∂ht\frac{\partial \mathbf{h}_T}{\partial \mathbf{h}_t}

Gradient through many steps

How much the state at the last step T depends on the state at an earlier step t. The chain rule makes it a product of one factor per step, which is why RNN gradients vanish or explode.

The chain rule says the derivative through a sequence of functions is the product of each function's derivative. Across T−tT - t recurrent steps, that is T−tT - t matrices multiplied together.

If each factor shrinks things (roughly, a size λ<1\lambda < 1), the product shrinks like λT−t\lambda^{T-t}. The gradient reaching step tt is then effectively zero, and the model cannot learn that step tt affected step TT. If each factor is above 1, the product grows without limit instead. Keeping every factor near exactly 1 over long sequences is very hard. This is a main reason attention replaced recurrence: attention connects any two positions in a single step.

Example

0.950≈0.005,1.150≈1170.9^{50} \approx 0.005, \qquad 1.1^{50} \approx 117

Fifty steps with a factor slightly below or above 1.

Where the course uses it

Related terms