How networks learn: gradient descent and backpropagation

13 min read

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:

  1. Forward pass: run inputs through the network to get a prediction and the loss.
  2. 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.
  3. 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

IssueWhat it meansCommon fixes
OverfittingMemorizing training dataMore data, dropout (randomly switch off neurons during training), weight decay, early stopping, data augmentation
Vanishing gradientsSignals fade in very deep networks, so early layers stop learningReLU activations, normalization layers, residual (skip) connections
Unstable trainingLoss jumps or explodesLower learning rate, learning-rate warm-up and decay, gradient clipping
Slow trainingToo much computeGPUs/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

Check 1 of 2Module 4 · Neural networks and deep learning

What does backpropagation compute?

Check 2 of 2Module 4 · Neural networks and deep learning

Training loss jumps around wildly and never settles. The most likely first fix is:

Answer the checks, then mark this lesson complete
Completion and scores are saved in this browser.