Juan Pablo García
All writing
Explainer5 steps · scroll to play

How neural networks learn

A neural network learns by guessing, measuring how wrong the guess was, and nudging its weights to be a little less wrong next time.

  1. 1

    Layers of neurons

    A network is layers of simple units. Every connection has a weight, a number the network learns.

  2. 2

    Forward pass

    Input values flow left to right. Each neuron adds up its weighted inputs plus a bias and applies a nonlinear activation such as ReLU.

  3. 3

    Measure the error

    The output is compared with the right answer. A loss function turns the gap into a single number.

  4. 4

    Backpropagation

    The error flows backward. Using the chain rule, backpropagation computes for every weight its gradient: how much the loss would change if that weight moved slightly.

  5. 5

    Gradient descent

    Each weight moves a small step against its gradient, usually computed on a mini-batch of examples. Optimizers like Adam adapt the step size for each weight.

Layers of neurons

A network is layers of simple units. Every connection has a weight, a number the network learns.

Forward pass

Input values flow left to right. Each neuron adds up its weighted inputs plus a bias and applies a nonlinear activation such as ReLU.

Measure the error

The output is compared with the right answer. A loss function turns the gap into a single number.

Backpropagation

The error flows backward. Using the chain rule, backpropagation computes for every weight its gradient: how much the loss would change if that weight moved slightly.

Gradient descent

Each weight moves a small step against its gradient, usually computed on a mini-batch of examples. Optimizers like Adam adapt the step size for each weight.

In short

  • Training is a loop: forward pass, loss, backpropagation and update, repeated over many batches of examples.
  • The learning rate sets the step size. Too large and training diverges, too small and it crawls.
  • The same idea scales from this toy network to language models with billions of weights.
  • Without the nonlinear activations, any stack of layers would collapse into a single linear function.

References

  1. Rumelhart, Hinton & Williams (1986). Learning representations by back-propagating errors. Nature 323.
  2. Goodfellow, Bengio & Courville (2016). Deep Learning. MIT Press.
  3. Kingma & Ba (2015). Adam: A Method for Stochastic Optimization. ICLR.

Share

Keep reading

All writing

Want to work together?