ML MATH & LINEAR ALGEBRA Β· INTERVIEW QUESTION
What is the vanishing/exploding gradient problem? How do modern architectures solve it?
π‘ intermediate Β· Calculus & Optimization
Hint: Think about what happens when you multiply many small or large numbers together.
Answer
During backpropagation, gradients are multiplied through layers:
For scalar states, repeated derivative magnitudes below one can make gradients vanish, while magnitudes above one can make them explode. For vector states, the backward-ordered Jacobian product, its singular values, and gradient alignment govern amplification or contraction.
Solutions for Vanishing Gradients
- ReLU activation: β gradient = 1 for positive values
- Residual connections: provides gradient highway
- LSTM gates: additive memory paths can help, although gates still multiply the recurrent gradient
- LayerNorm/BatchNorm: keeps activations in good range
- He/Xavier initialization: proper variance scaling
Solutions for Exploding Gradients
- Gradient clipping:
torch.nn.utils.clip_grad_norm_(model.parameters(), max_norm=1.0) - Weight regularization
- Careful learning rate selection
Transformers use residual connections and LayerNorm to mitigate gradient instability; initialization, architecture and optimizer settings still matter.
Related questions
- Derive the gradient of the cross-entropy loss for softmax output.
- What is the difference between convex and non-convex optimization? Why does it matter in deep learning?
- What are gradients, Jacobians, and Hessians? When do you use each in ML?
- What is gradient descent? Explain the intuition behind it.
- Explain learning rate scheduling strategies. Which are most effective?