Computing outputs is only half the battle: to learn, a network must measure its mistakes and fix them. A loss function scores how wrong the predictions are, and backpropagation, using the chain rule, works out how to fix each weight. Picture a factory: when a machine comes out wrong, a supervisor traces the error backwards from the output, finds which workstations (the weights) caused the biggest errors, and tunes those tools the most. Training repeats four steps: the forward pass turns inputs into predictions, the loss measures the mistake (for example, mean squared error), the backward pass uses the chain rule to find each weight's gradient (the slope of the error), and the weight update nudges every weight a little in the direction that lowers the loss. One backward pass by hand (example values, not in the lesson's code): with input 0.5, target 0.5 and weight 0.5, the prediction is 0.25 and the squared-error loss is (0.25 - 0.5)² = 0.0625; the chain rule gives the gradient 2 × (prediction - target) × input = 2 × (-0.25) × 0.5 = -0.25. That's the gradient in the lesson's code, with the weight 0.50 and the learning rate 0.1. The update rule is W_new = W_old - learning rate × gradient, so 0.50 - 0.1 × (-0.25) = 0.525, which the code prints as Old weight: 0.50 and Weight updated: 0.53. The gradient was negative, so the weight moves up, toward a lower loss. Choose the learning rate with care: too small (0.01 in the example) and training takes forever, too large (4.5 in the example) and the updates bounce around wildly, overshoot and never converge, while 1.0 reaches the lowest loss of the example. One full pass over the training data is called an epoch, usually done in batches.
📱 Run this lesson's code yourself (free, offline) in the NeuraLearn AI app. It has a real Python playground, interactive lessons, quizzes and daily challenges:
👉 https://play.google.com/store/apps/details?id=com.pygrounds
⏱️ Chapters
0:00 Loss & backprop: the big idea
0:29 The training cycle in 4 steps
0:54 Backprop by hand: gradient = −0.25
1:14 The lesson's code: 0.50 → 0.53
1:41 Choosing the learning rate
1:53 Recap & next lesson
📚 Stage 5 · Deep Learning · Lesson 4 of 10 in the NeuraLearn AI roadmap.
⬅️ Previous: The Forward Pass (Deep Learning Ep 3)
➡️ Next: Train a Neural Network from Scratch (Deep Learning Ep 5)
#DeepLearning #Backpropagation #GradientDescent #NeuralNetworks #Python