How networks learn: gradient descent and backpropagation
A network starts with random weights and produces nonsense. Training adjusts millions or billions of weights so its outputs become useful. Two ideas make this possible.
Gradient descent: walking downhill in fog
Imagine standing on a hillside in thick fog, trying to reach the valley floor. You can't see the valley, but you can feel the slope under your feet. So you take a step in the steepest downhill direction, feel again, and repeat.
- The landscape is the loss: how wrong the network is for every possible setting of its weights.
- The slope is the gradient: for each weight, how much the loss would change if that weight changed a little.
- Each step nudges every weight a small amount against its gradient.
- The learning rate is the step size. Too large and you overshoot the valley; too small and training takes forever.
In practice we use stochastic gradient descent (SGD): compute the gradient on a small random batch of examples rather than the whole dataset, which is much faster and adds helpful noise. Popular refinements such as Adam adapt the step size for each weight automatically.
Backpropagation: assigning blame
To take a step we need the gradient for every weight, even those deep inside the network. Backpropagation computes them efficiently:
- Forward pass: run inputs through the network to get a prediction and the loss.
- Backward pass: starting from the loss, work backward layer by layer using the chain rule from calculus, computing how much each weight contributed to the error.
- Update: adjust every weight a small step in the direction that reduces the loss.
One forward and backward pass over the whole training set is an epoch. Training runs for many epochs (or, for LLMs, a single pass over an enormous dataset).
Training settings and pitfalls
| Issue | What it means | Common fixes |
|---|---|---|
| Overfitting | Memorizing training data | More data, dropout (randomly switch off neurons during training), weight decay, early stopping, data augmentation |
| Vanishing gradients | Signals fade in very deep networks, so early layers stop learning | ReLU activations, normalization layers, residual (skip) connections |
| Unstable training | Loss jumps or explodes | Lower learning rate, learning-rate warm-up and decay, gradient clipping |
| Slow training | Too much compute | GPUs/TPUs, mixed precision, larger batches, distributing across many chips |
These details sound technical, but they explain a lot about the AI industry: training is a long, fragile, expensive optimization run, and much engineering effort goes into making it stable at huge scale.
Check your understanding
What does backpropagation compute?
Training loss jumps around wildly and never settles. The most likely first fix is: