LearnQuestion bank

Why do deep or recurrent nets suffer vanishing or exploding gradients, and which architectural and training choices mitigate it?

ML engineeringTechnicalMedium

Answer it yourself first, out loud or on paper, then compare.

Answer

Model answer, written in a candidate's voice

In short

  • Backprop multiplies Jacobians across depth/time; products shrink or blow up.
  • Saturating activations and poor scaling make derivatives tiny or huge.
  • Mitigate with non-saturating activations, variance-preserving init, residuals, normalisation, clipping, and gated recurrence.
  • Diagnose with per-layer gradient norms, NaNs, and loss spikes rather than only final loss.

In full

The core issue is that gradients are products of many Jacobians: through depth in a feedforward net, and through time in an unrolled recurrent net. If the typical factor is below 1, the signal decays toward zero; if it is above 1, it grows exponentially, and saturating sigmoid/tanh-like activations make the derivatives even smaller. The practical fixes are to keep forward and backward signal scales stable: ReLU/GELU-style activations, Xavier/Glorot-style init for saturating units and He-style init for ReLU-like units, residual/skip connections, batch/layer normalisation, gradient clipping, and LSTM/GRU gates that learn to preserve or reset information over time. Normalisation and residuals help a lot but do not replace sensible initialisation and clipping. I would diagnose by logging per-layer gradient norms, watching for NaNs and loss spikes, and checking whether gradients collapse in early layers or explode in recurrent time steps, then adjust init, architecture, clipping, or learning rate accordingly.

Corrected by an independent AI reviewer.

What a strong answer covers

  • Repeated Jacobian products; saturating activations.
  • Fixes: ReLU/GELU, careful initialisation (He/Xavier), residual connections, normalisation layers, gradient clipping, LSTM/GRU gates.
  • Diagnosis: per-layer gradient norms, NaNs, loss spikes.

Common mistakes

  • using clipping as a substitute for fixing initialisation
  • confusing vanishing gradients with a low learning rate.