Skip to content
ML to LLMs
Labs / Neural Network Lab

Backpropagation, step by step

A one-neuron classifier: edit the inputs and weights and recompute all nine steps.

Theory and worked examples: Backpropagation

Backpropagation lab

One neuron, sigmoid output, binary cross-entropy. Defaults are the course example.

  1. 1. Weighted sumz=w1x1+w2x2+b=0.5000⋅2.0000+(−1.0000)⋅1.0000+0.0000z = w_1x_1 + w_2x_2 + b = 0.5000\cdot2.0000 + (-1.0000)\cdot1.0000 + 0.0000z=0.0000z = 0.0000
  2. 2. Sigmoid outputy^=σ(z)=11+e−0.0000\hat{y} = \sigma(z) = \frac{1}{1 + e^{-0.0000}}y^=0.5000\hat{y} = 0.5000
  3. 3. Binary cross-entropyL=−[ylog⁡y^+(1−y)log⁡(1−y^)]L = -[y\log\hat{y} + (1-y)\log(1-\hat{y})]L=0.6931L = 0.6931
  4. 4. Error signal∂L∂z=y^−y=0.5000−1\frac{\partial L}{\partial z} = \hat{y} - y = 0.5000 - 1−0.5000-0.5000
  5. 5. Gradient for w₁∂L∂w1=∂L∂z x1=(−0.5000)⋅2.0000\frac{\partial L}{\partial w_1} = \frac{\partial L}{\partial z}\,x_1 = (-0.5000) \cdot 2.0000−1.0000-1.0000
  6. 6. Gradient for w₂∂L∂w2=∂L∂z x2=(−0.5000)⋅1.0000\frac{\partial L}{\partial w_2} = \frac{\partial L}{\partial z}\,x_2 = (-0.5000) \cdot 1.0000−0.5000-0.5000
  7. 7. Gradient for b∂L∂b=∂L∂z⋅1\frac{\partial L}{\partial b} = \frac{\partial L}{\partial z} \cdot 1−0.5000-0.5000
  8. 8. Update (η = 0.1)w1=0.5000−0.1⋅(−1.0000),  w2=(−1.0000)−0.1⋅(−0.5000),  b=0.0000−0.1⋅(−0.5000)w_1 = 0.5000 - 0.1\cdot(-1.0000),\; w_2 = (-1.0000) - 0.1\cdot(-0.5000),\; b = 0.0000 - 0.1\cdot(-0.5000)0.6000,  −0.9500,  0.05000.6000,\; -0.9500,\; 0.0500
  9. 9. New predictionz′=0.6000⋅2.0000+(−0.9500)⋅1.0000+0.0500=0.3000z' = 0.6000\cdot2.0000 + (-0.9500)\cdot1.0000 + 0.0500 = 0.3000y^′=0.5744\hat{y}' = 0.5744

Why is step 4 so simple? ∂L∂y^=y^−yy^(1−y^)\frac{\partial L}{\partial \hat{y}} = \frac{\hat{y}-y}{\hat{y}(1-\hat{y})} and ∂y^∂z=y^(1−y^)\frac{\partial \hat{y}}{\partial z} = \hat{y}(1-\hat{y}). Multiplying them (the chain rule), the y^(1−y^)\hat{y}(1-\hat{y}) terms cancel.

The update moved the prediction from 0.5000 to 0.5744, toward the label 1, and the loss fell from 0.6931 to 0.5544. Each weight moved in proportion to its input: x₁ = 2 is larger than x₂ = 1, so w₁ changed more.