ViewWiki

The world, a little closer

Neural networks.

Nobody writes the rules a neural network follows. It starts with random guesses and learns from examples. How does guessing turn into knowing?

Explore the scene Interactive article

01 / The experiment

Random guesses. Learned answers.

Train the network step by step, then look at the boundary it draws between the two colours.

Still of the Neural networks 3D scene, which explores: How does a neural network learn a rule nobody gave it?
Interactive scene

Loading the interactive version…

The explanation below is available while the scene loads.

A real network, trained on these 80 points by gradient descent; every step is computed, and the same step always gives the same weights.This network has 13 units and 51 adjustable numbers. Networks that recognise speech or write text have billions, train on vastly more data, and take weeks on specialised chips.

02 / Three problems

Harder data, bendier boundary.

Each square shows a trained network's answer at every position, with the points it learned from.

A straight cut

Two clusters

Blue and orange sit in two separate groups. A single straight line divides them.

Boundary
A straight line
Steps to 97% right
About 15
Hidden layers needed
None needed
Right after 400 steps
100%
Opposite corners

Corners (XOR)

Blue in two opposite corners, orange in the others. No straight line can do it; the network folds a band.

Boundary
A diagonal band
Steps to 97% right
About 175
Hidden layers needed
At least one
Right after 400 steps
100%
Inside and out

Ring

An orange core inside a blue ring. The network has to bend its boundary all the way round.

Boundary
A closed loop
Steps to 97% right
About 300
Hidden layers needed
At least one
Right after 400 steps
100%
The big idea

A neural network is a big adjustable sum. Training nudges every weight downhill on the error, and hidden layers let the network bend its boundary to fit whatever shape the data has.

w ← w − η·∂L/∂w

A web of tiny sums

A neural network is built from simple units, loosely modelled on nerve cells, arranged in layers. Each unit does very little: it takes the numbers coming in from the layer before, multiplies each by a weight, adds them up with a constant of its own (the bias), and squashes the total into a fixed range. Its result, the unit’s activation, is passed on to the next layer.

The network in the experiment has two inputs, the x and y position of a point, two hidden layers of five units, and one output: its answer to whether the point is blue or orange. Each link’s thickness shows the size of its weight. Blue links add to the next unit’s total, orange ones subtract.

Learning is adjusting weights

At the start the weights are random, so the answers are guesses. Training shows the network the 80 example points with their true colours and measures how wrong it is, a number called the loss. Then it works out, for every single weight, whether a slight increase would make the loss bigger or smaller, and nudges every weight a little in the direction that helps. That is gradient descent: like walking downhill in fog by feeling which way the ground slopes.

Working out all those slopes at once is done by backpropagation: the error at the output is passed backwards through the layers, so each link learns its share of the blame.

Try it: start with Training steps at 0 and drag it slowly to the right. Watch links thicken and change colour, and the score climb towards 100%.

Back to the experiment

The boundary it learns

Choose On under Show the decision boundary. The board shows the network’s answer at every position: the surface rises and turns blue where it says blue, sinks and turns orange where it says orange. The white line is the decision boundary, where the network is exactly undecided.

Choose Two clusters and a straight boundary is enough, so the network learns it in under twenty steps. Corners (XOR) puts blue in two opposite corners and orange in the other two; no single straight line can split them, the problem that famously stumped the earliest one-layer networks in the 1960s. With hidden layers, the network bends its boundary into a band. For Ring it learns to draw a closed loop.

The hidden units are why: each one draws its own straight cut through the plane, and the next layer combines those cuts into curves.

What this model leaves out

This network is tiny, so you can see every weight. Image and language models have billions of weights, are trained on millions of examples in small random batches rather than all at once, and use extra techniques to keep learning stable. Doing well on the training points is not the same as doing well on new ones: a network can memorise its examples, called overfitting, so real training checks it on data it has never seen. Units in a neural network are a loose analogy for neurons; brains do not learn by backpropagation in this form. The link colours, glowing units and travelling beads show the numbers in the network; nothing in a computer actually lights up.

Reuse with credit to ViewWiki and a link to this page.

04 / Learn this in a course

Practise it, step by step.

These 2 lessons teach the topic with checked questions, in course order.

  1. Neurons and weights Computer science · Machine learning
  2. Training a network Computer science · Machine learning