Deep Learning · TEE · section

Model answer: backpropagation through time

Recurrent neural networks

Question

Question. Explain backpropagation through time and the vanishing/exploding gradient problems in a recurrent neural network.

Answer — step by step

Backpropagation through time, or BPTT, applies backpropagation to an RNN unrolled across a sequence. The forward pass computes the state and any output at each time step. The backward pass follows how later losses depend on earlier states and shared parameters.

The drawn copies reuse one parameter set. Their backward contributions add into one gradient for each shared parameter. Tap the diagram to enlarge.

Working procedure

1. Start from the supplied initial state and compute h₁, h₂ and all subsequent states in order.

2. Calculate the loss at the output positions specified by the task.

3. Propagate loss derivatives backward through the output computations and recurrent state transitions.

4. Add contributions from all time steps that use the same parameter.

5. Apply the optimizer update to the shared parameter after its gradient contributions have been accumulated.

Why gradients can vanish or explode

The chain rule repeatedly multiplies derivatives through time. A simple illustration is multiplying by 0.5 ten times, giving about 0.000977, versus multiplying by 2 ten times, giving 1,024. Real RNNs involve matrices and activation derivatives, so these scalars illustrate the mechanism rather than define a universal threshold.

Vanishing gradients make distant earlier inputs receive very weak learning signals. Exploding gradients can produce extremely large updates and unstable training. Gradient clipping limits gradient magnitude before an optimizer update and is useful for exploding gradients. It does not by itself restore already vanished information.

LSTM/GRU gating, suitable initialization and architecture choices can improve long-range learning. Truncated BPTT limits how far the backward computation runs for computational reasons; it does not mean that each unrolled box has independent parameters.