§ Gradients · Interactive Graduate Primer
Tensor by Tensor · expanded

Gradient problems

Learn how changing several inputs changes one output. Begin with partial derivatives, then explore gradient descent, backpropagation, and optimizers. The later sections include proofs and deeper mathematical detail.
A first reading path

Start with sections 2–4, then section 7. Return to the directional-derivative proof after you understand a gradient-descent update. An optimizer is a rule for updating the model’s adjustable numbers.

For L(a, b) = a² + 2b², the gradient at (1, 2) is [2, 8]. The first entry measures change along a while b stays fixed. The second measures change along b while a stays fixed. With step size 0.1, subtract [0.2, 0.8] to reach (0.8, 1.2). The loss falls from 9 to 3.52.

Check: why subtract the gradient?

The gradient points toward the steepest local increase under the usual Euclidean length measure. Subtracting it moves toward a local decrease when the step is small enough. A large step can still overshoot and increase the loss.

11. Pathologies in Deep Learning

Introduction

Multiplying many local derivatives can erase or amplify a learning signal. With sigmoid derivatives bounded by one quarter, an eight-layer network chain can shrink a unit gradient below two hundred-thousandths.

Learning goal

Recognize vanishing gradients, exploding gradients, saddle points, and sharp-minimum behavior and connect each to practical remedies.

Before you start

Backpropagation through layers, repeated multiplication, activation functions, gradient vectors, and the idea of curvature.

Lesson plan

  1. Calculate gradient decay through depth and inspect it with the interactive control.
  2. Contrast vanishing and exploding gradient signals and review practical stabilization methods.
  3. Distinguish saddle points from flat and sharp minima using local geometry.

Predict the symptom before choosing a remedy. Vanishing gradients produce tiny early-layer updates. Exploding gradients produce very large values or nan. Noisy gradients vary across batches. These failures can look similar if you inspect only the final loss.

11.1 Vanishing gradients

When each Jacobian $J_\ell$ has spectral radius $\rho(J_\ell)<1$, the chain-rule product $J_K^\top\cdots J_1^\top$ decays exponentially with depth. Early layers receive near-zero gradients. Fixes: ReLU activations, residual connections, careful initialisation (He, Xavier).

11.1.1 Interactive · gradient decay with depth

A deep chain of sigmoid units $a_{\ell+1}=\sigma(w\,a_\ell)$, with $L=a_N$. Drag the depth $N$ and weight $w$ to watch $|\partial L/\partial a_0|$ collapse. For $\sigma'(z)=\sigma(z)(1-\sigma(z))\le 1/4$, the gradient magnitude is bounded by $(|w|/4)^N$.

Interactive · $a_{\ell+1}=\sigma(w\,a_\ell)$, $L=a_N$

11.2 Exploding gradients

The dual problem ($\rho(J_\ell)>1$). Common in RNNs. Fix: gradient clipping $g \leftarrow g\cdot\min(1,\, c/\|g\|)$, typically $c=1$.

11.3 Saddle points

In high dimensions, most critical points are saddles, not minima. The loss is flat, gradients are tiny, SGD crawls. Momentum and stochasticity help escape.

11.4 Flat vs. sharp minima

Flat minima generalise better (Hochreiter & Schmidhuber, 1997). SGD's implicit bias toward them is one of the deep-learning regularisation effects.