How a neural network learns
How a neuralnetwork learns
A neural network is a function with thousands or billions of adjustable numbers. Learning means nudging those numbers until the function gets things right.
Slide 1 of 15: How a neural network learns.
How a neuralnetwork learns
A neural network is a function with thousands or billions of adjustable numbers. Learning means nudging those numbers until the function gets things right.
A neural network is a function. Numbers go in, numbers come out.
Everything else in this deck is about how the network finds the right function.
What goes in, what comes out
- Input
- 784 numbers
- Output
- 10 numbers
- Answer
- The largest output
Take a photo of a handwritten digit, 28 by 28 pixels. That is 784 numbers, one per pixel, from 0 for black to 1 for white.
The network turns those 784 numbers into 10 numbers: one for each digit from 0 to 9. The largest one is its answer.
This is the classic MNIST example used in 3Blue1Brown’s series, and it is how we will think about every network here.
One neuron
- 1Three inputs arrive. Each one is just a number.
- 2Each input is multiplied by its own weight. A negative weight pushes against.
- 3The neuron adds the products and a bias: z = 0.45 − 0.32 + 0.12 + 0.1 = 0.35.
- 4An activation function sets the output. ReLU keeps positive values and turns negative ones into 0.
The weights are the knowledge
- Weights
- 784×16 + 16×16 + 16×10 = 12,960
- Biases
- 16 + 16 + 10 = 42
- Total
- 13,002
A network is layers of these neurons. Every neuron in one layer feeds every neuron in the next, and every connection has its own weight.
The small digit network in 3Blue1Brown’s video (784, 16, 16 and 10 neurons) has 13,002 weights and biases. Large language models have billions.
Nothing else is stored. Whatever a trained network knows lives in those numbers.
A forward pass
- 1The input layer holds the data.
- 2Each hidden neuron takes a weighted sum of every input, then applies its activation.
- 3The output layer does the same with the hidden values.
- 4The largest output is the network’s answer. Values here are illustrative.
Before training, every weight is random. So every answer is a guess.
Measuring wrong: the loss
To improve, the network needs one number that says how wrong it is. That number is the loss.
A simple choice is squared error. If the right output is 1 and the network says 0.2, the error is (1 − 0.2)² = 0.64. A perfect answer scores 0.
Average the loss over many examples and you have a single score for the whole network. Training means making it small.
Gradient descent
- 1Start anywhere. Here the weight w = 0.5 and the loss is 7.25.
- 2Measure the slope, −5, and step the other way: w = 0.5 − 0.3 × (−5) = 2.0.
- 3The slope is gentler now, so the step is smaller: w = 2.6.
- 4Smaller again: w = 2.84. Steps shrink as the ground flattens.
- 5The lowest loss is at w = 3. Training never jumps there. It walks.
Loss L(w) = (w − 3)² + 1. Learning rate 0.3.
Millions of slopes at once
A real network has a slope for every weight. Together they form the gradient: the direction in which the loss rises fastest.
Gradient descent steps the opposite way, a little at a time. The step size is the learning rate.
Too large and the network overshoots the valley. Too small and training crawls.
Backpropagation
- 1The network guessed dog. The right answer was cat.
- 2The loss measures the miss. Its gradient tells each weight into the output layer which way to move.
- 3The chain rule from calculus passes that blame back, layer by layer.
- 4Every weight takes a small step downhill. Next time, cat scores a little higher.
The training loop
- 1ForwardRun a batch of examples through the network.
- 2LossMeasure how wrong the outputs are.
- 3BackwardUse backpropagation to find the gradient for every weight.
- 4UpdateNudge every weight a little downhill. Then repeat, thousands of times.
“Instead of trying to produce a programme to simulate the adult mind, why not rather try to produce one which simulates the child’s?”
Video · 3Blue1Brown
Watch it drawn
Grant Sanderson builds the digit network from scratch and shows what each layer might be looking for.

Go further
In rough order. The first two need no calculus.
- Gradient descent, how neural networks learnVideo · 3Blue1Brown (opens in a new tab)
- The Essential Main Ideas of Neural NetworksVideo · StatQuest (opens in a new tab)
- Backpropagation, intuitivelyVideo · 3Blue1Brown (opens in a new tab)
- TensorFlow PlaygroundSite · Google (opens in a new tab)
- Building microgradVideo · Andrej Karpathy (opens in a new tab)
End of the deckNext deck: Generative AI, from noise to image