Zero Labs
Industry News / AI

How Do Neural Networks Actually Learn

Source · Towards AI By Sanika Tare

From the publisher’s feed, collected in the ZeroLabs newsroom.

From making a prediction to figuring out exactly which weights caused the mistake.Your network just made a prediction. It said 0.6, and the right answer was 1. Now what?Knowing you’re wrong isn’t enough. A network can have thousands or millions of weights, and somebody has to work out which ones are to blame and by how much. In the last article we saw the pipeline: prediction → loss → weight update. Today we open up the missing middle step.The network made a mistake. How does it figure out which weights caused it?The answer is backpropagation.Quick recapA neuron multiplies each input by a weight, adds them up with a bias, and passes the result through an activation function. Layers of these neurons form a network, and sending data through them is the forward pass. At the end, a loss function compares the prediction with the true target and gives a single score for how wrong we were. High loss means very wrong. Low loss means close.The goal of training is simple to say: make that score smaller.Why not just change weights at random?You could nudge a weight up, check the loss, nudge another down, check again. With 3 weights, fine. With a million, you’d be there until the heat death of the universe. We need a method that tells every weight, in one sweep, which way to move.So what is backpropagation?Think of shooting a basketball and missing. You don’t just say “I missed.” You ask: was the angle off, or the force, or the release? You trace the miss back to its causes.Backpropagation does this for a network. It starts from the loss and travels backward through the layers, working out how much each weight contributed to the error. That’s the whole reason for the name: the error information is propagated back.Forward pass vs backward passWhat is a gradient?Before any math: a gradient is a hint. For every weight, it answers two questions.• Which direction? If increasing the weight raises the loss, the weight should go down. If increasing it lowers the loss, it should go up.• How strongly? A big gradient means the loss is very sensitive to that weight. A tiny one means it barely matters.In symbols, ∂L/∂w reads “how much the loss changes when w changes a little.”The chain rule: the engine under the hoodHere’s the catch. A weight doesn’t touch the loss directly. It affects a neuron’s output, which affects the next layer, which affects the prediction, which finally affects the loss. It’s a chain of cause and effect.The chain rule says: to find the total effect, multiply the effect of each link.dLoss/dw = (dLoss/dŷ) × (dŷ/dz) × (dz/dw)That’s also why we go backward. The loss is closest to the output, so we compute that piece first, then reuse it as we move toward the input. Nothing gets computed twice, which is what makes it efficient enough for huge networks.A tiny example you can check by handOne input, one neuron, no activation, no bias. Numbers: x = 2, target y = 1, weight w = 0.3, learning rate η = 0.1.1. Forward: ŷ = w·x = 0.3 × 2 = 0.62. Loss: L = ½(ŷ − y)² = ½(0.6 − 1)² = 0.083. Gradient via the chain rule:dL/dŷ = ŷ − y = −0.4dŷ/dw = x = 2dL/dw = (−0.4)(2) = −0.84. Update: w_new = 0.3 − 0.1 × (−0.8) = 0.38The gradient is negative, meaning “raising w lowers the loss.” So the weight goes up, the prediction goes from 0.6 to 0.76, and we’re closer to the target.Why do we subtract the gradient?w_new = w_old − η × ∂L/∂wHere w is the weight, L the loss, ∂L/∂w the gradient, and η the learning rate (the step size). The gradient points toward higher loss, the uphill direction. We want to go down, so we move the opposite way. That minus sign is the whole trick. In our example the gradient was −0.8, so subtracting it increased the weight.Backpropagation vs gradient descentBackprop is the measuring. Gradient descent is the moving.One complete training cycleThe same thing in plain NumPyNo frameworks yet. This way you can see exactly what backprop is doing.import numpy as npx, y = 2.0, 1.0w, lr = 0.3, 0.1for i in range(11):y_hat = w * x # forward passloss = 0.5 * (y_hat — y) ** 2 # lossdL_dyhat = y_hat — y # backward passdyhat_dw = xgrad = dL_dyhat * dyhat_dw # chain ruleif i in (0, 1, 2, 5, 10):print(f”iter {i:2d} w={w:.4f} loss={loss:.6f}”)w = w — lr * grad # gradient descent updateRunning it prints:iter 0 w=0.3000 loss=0.080000iter 1 w=0.3800 loss=0.028800iter 2 w=0.4280 loss=0.010368iter 5 w=0.4844 loss=0.000484iter 10 w=0.4988 loss=0.000003What happens over many iterations?Look at that output. The weight creeps toward 0.5, which is exactly the value that makes 0.5 × 2 = 1. The loss shrinks fast at first, then more slowly as the slope flattens. In a real network with millions of weights, the same story plays out, just noisier.Common beginner confusionsIs backpropagation the same as gradient descent? No. Backprop computes gradients. Gradient descent uses them.Does backpropagation change the weights? Not by itself. It only calculates. The update step does the changing.What exactly is a gradient? A number per weight telling you the direction and sensitivity of the loss to that weight.Why do we need derivatives? Because a derivative is precisely “how much does the output change if I nudge this input.” That’s what a gradient is.Why repeat the process so many times? Each step is small and based on a local slope. One step only gets you a little closer, as our example showed. Many steps get you there.ConclusionBackpropagation tells a neural network what went wrong and how each weight contributed to the error. It does that efficiently by applying the chain rule from the output back to the input.But that’s only half of learning. We now know the direction for every weight. We haven’t yet decided how big each step should be, or how much data to look at before taking it.Backprop tells the network what went wrong. How does it decide how big each update should be?ConclusionBackpropagation tells a neural network what went wrong and how each weight contributed to the error. It does that efficiently by applying the chain rule from the output back to the input.But that’s only half of learning. We now know the direction for every weight. We haven’t yet decided how big each step should be, or how much data to look at before taking it.Backprop tells the network what went wrong. How does it decide how big each update should be?That’s the next article: Gradient Descent Explained: How Neural Networks Find Better Weights.How Do Neural Networks Actually Learn was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.