Lensa ML
Lensa ML

How Backpropagation Works

Step 1 of 6

The Prediction Was Wrong

The network guessed Cat = 0.62 — but we wanted 1.0

Cat
Got
0.57
Want
1.0
Dog
Got
0.67
Want
0.0

The forward pass ran. The network says Cat = 0.57 but the answer should be 1.0. How does the network fix itself? That's backpropagation: sending the error backward through the network so every weight learns from the mistake.

① Measure error
② Blame each weight
③ Nudge weights

Step 1 of 6: The Prediction Was Wrong

The network guessed Cat = 0.62 — but we wanted 1.0

Cat
Got
0.57
Want
1.0
Dog
Got
0.67
Want
0.0

The forward pass ran. The network says Cat = 0.57 but the answer should be 1.0. How does the network fix itself? That's backpropagation: sending the error backward through the network so every weight learns from the mistake.

① Measure error
② Blame each weight
③ Nudge weights

Step 2 of 6: Measuring the Mistake

The loss function puts a number on how wrong we are

Catpred: 0.571goal: 1.0diff: -0.429Dogpred: 0.671goal: 0.0diff: +0.671

The loss function measures how wrong we are. Take each output's error, square it (so bigger mistakes get punished more), and add them up. This single number is what backprop tries to minimize.

L = (Cat - 1.0)² + (Dog - 0.0)² = 0.6348

Step 3 of 6: The Chain Rule

How a tiny weight change ripples through to the output

∂L∂outOutputoutput error×∂out∂h₂Hidden 2layer blame×∂h₂∂h₁Hidden 1passed back×∂h₁∂wInputweight update

The chain rule is the key insight. To find out how much one weight affected the final loss, multiply together the local derivatives at each step along the path. Each neuron only needs to know its local math, then pass the blame backward.

Step 4 of 6: Gradients Flow Backward

Watch error signals propagate from output back to input

Error signals flowing backward
0.85Pointy ears0.72Whiskers0.91Fur texture0.620.520.630.300.650.770.410.480.57δ=-0.105Cat0.67δ=0.148DogInputHidden 1Hidden 2Outputerror flows backward
Hidden 1
δ max: 0.006
Hidden 2
δ max: 0.025
Output
δ max: 0.148

Each neuron's delta (δ) represents its share of the blame. The bigger the delta, the more that neuron contributed to the error. Deltas start at the output and propagate backward.

Step 5 of 6: Nudging the Weights

Each weight gets a personalized correction

Learning rate:1.50
Loss Before
0.6348
Loss After
0.4957
FROM→TOOLD wGRADIENTSTEPNEW w
H2#1→1+0.600-0.0688+0.103+0.703
H2#1→2+0.070+0.0970-0.145-0.075
H2#2→1-0.460-0.0808+0.121-0.339
H2#2→2+0.640+0.1140-0.171+0.469
H2#3→1+0.040-0.0433+0.065+0.105
H2#3→2-0.260+0.0611-0.092-0.352
H2#4→1+0.480-0.0505+0.076+0.556
H2#4→2+0.590+0.0713-0.107+0.483

new weight = old weight - learning rate × gradient. A big gradient means that weight had a big effect on the error, so it gets a bigger correction.

Step 6 of 6: Repeat Until Learned

Many rounds of backprop — watch the network master the cat

Watch the network converge
0.85Pointy ears0.72Whiskers0.91Fur texture0.620.520.630.300.650.770.410.480.57Catgoal 1.0err 0.4290.67Doggoal 0.0err 0.671InputHidden 1Hidden 2Output
EPOCH
0
LOSS
0.6348
CAT
0.57