TensorTau PathToAGI Neural Networks from First Principles Level 06

Level 06 · Neural Networks from First Principles · Chapter 083

Backpropagation: Sending the Error Backward

We know how one parameter changes the loss. How can we send that information backward through several computations without guessing?

Where We Are

We just learned Backpropagation: Sending the Error Backward.

But using it creates a new question.

What problem does this idea still leave us unable to solve?

That question leads naturally to Matrix Backpropagation: dW, db, dX by Hand.

Next → Matrix Backpropagation: dW, db, dX by Hand.

1. The Problem: The First Layer Cannot See the Final Error

Consider the smallest useful two-stage network:

x→z→y^x\rightarrow z\rightarrow \hat y

with

z=wx,y^=vz.z=wx, \qquad \hat y=vz.

Suppose the target is yy and the loss is

L=(y^−y)2.L=(\hat y-y)^2.

The second weight vv touches the prediction directly. The first weight ww does not.

So here is the training problem:

How can ww know whether increasing it would make the final loss better or worse?

The answer cannot simply be “look at the loss.” The loss is several operations away.


2. What Would a Solution Need?

We need a method that:

  1. starts at the final loss;
  2. moves backward one operation at a time;
  3. measures the local effect of each operation;
  4. combines those local effects into the total effect on the loss;
  5. works for deeper networks without inventing a new rule for every architecture.

Notice the shape of the answer already: local pieces + a rule for connecting them.


3. First Attempt: Differentiate the Whole Expression at Once

Substitute everything into the loss:

L=(vwx−y)2.L=(vwx-y)^2.

Then expand it mentally and differentiate directly with respect to ww.

For this tiny example, you can do it:

dLdw=2(vwx−y)vx.\frac{dL}{dw}=2(vwx-y)vx.

But this approach becomes ugly when the network contains many layers and nonlinear functions.

Worse, the long expression hides the structure we actually need: every operation only has to answer a tiny local question.

A Tempting Wrong Idea

“Just expand the whole neural network into one giant formula and differentiate that.”

You can sometimes do this on paper. But the expression grows with the network, repeated computation becomes wasteful, and it becomes difficult to see which local operation caused which part of the gradient.

We need to preserve the computation as a sequence of small operations.


4. The Discovery: Follow One Tiny Effect Backward

Start at the loss.

To understand how ww affects LL, ask three smaller questions:

  1. How does LL change when y^\hat y changes?
  2. How does y^\hat y change when zz changes?
  3. How does zz change when ww changes?

The chain rule says we can multiply those local answers:

dLdw=dLdy^dy^dzdzdw\boxed{ \frac{dL}{dw} = \frac{dL}{d\hat y} \frac{d\hat y}{dz} \frac{dz}{dw}}

This is the central discovery of the chapter.

Backpropagation is not a new kind of derivative. It is the systematic organization of the chain rule over a computation graph.


5. Three Levels of the Same Idea

LevelThe same idea
💡 IntuitionThree connected machines. Ask each machine, “If your output changed a little, how much would that affect the final error?” Multiply the answers as you walk backward.
✏️ Tiny numbersIf one stage has local effect 22, the next −3-3, and the previous 44, the total effect is 2(−3)(4)=−242(-3)(4)=-24.
🎓 AbstractionAlong a path, total sensitivity is the product of local derivatives.

The chain rule turns many small sensitivities into one global sensitivity.


6. Calculate Every Local Derivative

Our computation is

w→z→y^→L.w\rightarrow z\rightarrow\hat y\rightarrow L.

First:

L=(y^−y)2L=(\hat y-y)^2

so

dLdy^=2(y^−y).\frac{dL}{d\hat y}=2(\hat y-y).

Second:

y^=vz\hat y=vz

so

dy^dz=v.\frac{d\hat y}{dz}=v.

Third:

z=wxz=wx

so

dzdw=x.\frac{dz}{dw}=x.

Now multiply them:

dLdw=2(y^−y)vx\boxed{ \frac{dL}{dw} = 2(\hat y-y)vx }

The long derivative came from three tiny derivatives.


7. ✏️ Hand Calculation: The Error Travels Back

Choose

x=2,w=3,v=4,y=30.x=2,\qquad w=3,\qquad v=4,\qquad y=30.

Forward pass

First operation:

z=wx=3(2)=6.z=wx=3(2)=6.

Second operation:

y^=vz=4(6)=24.\hat y=vz=4(6)=24.

Loss:

L=(24−30)2=36.L=(24-30)^2=36.

Backward pass

Start from the loss:

dLdy^=2(24−30)=−12.\frac{dL}{d\hat y}=2(24-30)=-12.

Move one step backward:

dy^dz=4.\frac{d\hat y}{dz}=4.

So

dLdz=(−12)(4)=−48.\frac{dL}{dz}=(-12)(4)=-48.

One more step:

dzdw=2.\frac{dz}{dw}=2.

Therefore

dLdw=(−48)(2)=−96.\frac{dL}{dw}=(-48)(2)=-96.

The negative sign is information: locally, increasing ww would decrease the loss.


8. Why “Backward”?

The forward computation is

input → layer 1 → layer 2 → prediction → loss

The derivative computation reverses direction:

loss → prediction → layer 2 → layer 1 → parameter
flowchart LR
    X[Input x] --> Z[ z = w x ]
    Z --> Y[ y-hat = v z ]
    Y --> L[ Loss L ]
    L -. dL/dy-hat .-> Y
    Y -. dL/dz .-> Z
    Z -. dL/dw .-> X

The backward arrows are gradient information, not data travelling backward through the network.


9. Computational Graphs: The Network as Small Operations

Write the same computation as a graph:

x→wx→v(wx)→(y^−y)2.x \rightarrow wx \rightarrow v(wx) \rightarrow (\hat y-y)^2.

Every node performs a local operation. Every operation has a local derivative.

Backpropagation stores the intermediate values from the forward pass and then reuses them while moving backward.

That last part matters. A good algorithm should not repeatedly rebuild the same forward calculations just to differentiate them.


10. Local Derivatives Become a Reusable Vocabulary

Here are three tiny rules:

OperationLocal derivative
z=wxz=wx wrt wwxx
z=wxz=wx wrt xxww
z=u2z=u^2 wrt uu2u2u

A complex network is then assembled from simple operations whose local derivatives can be chained together.

This is why the method scales conceptually even when the network becomes much larger.


11. The Subtle Part: A Variable Can Have Multiple Paths

So far ww had only one route to the loss.

Real computation graphs can branch.

Suppose

z=xwz=xw

and then

a=z+1,b=2z.a=z+1, \qquad b=2z.

The final quantity is

L=a+b.L=a+b.

The variable zz influences LL through two paths.

The total derivative must add the contributions from both paths:

dLdz=dLdadadz+dLdbdbdz.\frac{dL}{dz} = \frac{dL}{da}\frac{da}{dz} + \frac{dL}{db}\frac{db}{dz}.

That gives us an important rule:

Along one path, multiply local derivatives. When several paths meet, add their contributions.

This is one reason computational graphs are a better mental model than one enormous formula.


12. Backpropagation Is Not the Optimizer

There are four separate jobs:

Forward pass       → calculate predictions
Loss               → measure wrongness
Backpropagation    → calculate gradients
Optimizer          → change parameters

The optimizer uses a gradient such as dL/dwdL/dw:

w←w−ηdLdw.w\leftarrow w-\eta\frac{dL}{dw}.

Here η\eta is the learning rate.

With our gradient −96-96, a positive learning rate would increase ww because subtracting a negative number moves it upward.

Backpropagation does not choose the learning rate or perform the update. It supplies the direction and sensitivity information.


13. 🔬 The Experiment: Change One Variable

Keep

x=2,v=4,y=30x=2,\qquad v=4,\qquad y=30

fixed. Change only ww.

From

dLdw=2(vwx−y)vx,\frac{dL}{dw}=2(vwx-y)vx,

we can predict the gradient for several values of ww.

At w=3w=3, it is −96-96.

If ww increases toward the value that makes vwx=30vwx=30, the error should shrink and the gradient should move toward zero.

The gradient is therefore not “the error.” It is a local sensitivity of the loss to the parameter.


14. Why This Idea Scales

Imagine a network with thousands of operations.

We do not want thousands of giant symbolic formulas.

Instead:

  1. run the network forward once;
  2. store the intermediate results we need;
  3. start with the loss gradient;
  4. move backward, applying local derivative rules;
  5. reuse the same intermediate calculations where paths overlap.

The computation becomes systematic.

This is the conceptual foundation of automatic differentiation systems used by frameworks such as PyTorch.


15. 📜 History Lens — Backpropagation in the 1980s

Imagine working on multilayer networks when the major difficulty is not writing a neuron, but finding a practical way to train all the hidden weights.

David Rumelhart, Geoffrey Hinton and Ronald Williams published the influential 1986 paper Learning representations by back-propagating errors. Their work helped establish the practical use of backpropagation for multilayer neural networks.

The chain rule itself was much older. The contribution was showing how to organise repeated chain-rule calculations into a usable learning procedure for layered models.

That distinction matters: backpropagation is an algorithmic way of applying old calculus to a new computational structure.


🎯 Machine Learning Connection

At training time, a neural network repeatedly executes

forward→loss→backward→update.\text{forward} \rightarrow \text{loss} \rightarrow \text{backward} \rightarrow \text{update}.

The backward stage computes quantities such as

∂L∂w, ∂L∂v.\frac{\partial L}{\partial w},\nobreakspace \frac{\partial L}{\partial v}.

The optimizer then uses them to move parameters.

Once we have many weights and many examples, these scalar derivatives naturally become arrays of derivatives. That is the exact problem waiting in Chapter 085.


Distinctions That Matter

Do not confuseWith
derivativevalue of the variable itself
gradientloss
backpropagationgradient descent
local derivativetotal derivative through the graph
gradient directionupdate size
backward passdata flowing backward

What We Discovered

  1. A parameter can affect the loss through a chain of intermediate computations.
  2. The chain rule turns local sensitivities into a total derivative.
  3. Backpropagation is the systematic application of that rule backward through a computational graph.
  4. Along a single path, derivatives multiply.
  5. When paths merge, their gradient contributions add.
  6. Backpropagation computes gradients; an optimizer uses them to change parameters.
  7. The same idea can be packed into matrix operations when many values are involved.

Mathematics We Built

Network:

z=wx,y^=vz,L=(y^−y)2.z=wx, \qquad \hat y=vz, \qquad L=(\hat y-y)^2.

Chain rule:

dLdw=dLdy^dy^dzdzdw.\frac{dL}{dw} = \frac{dL}{d\hat y} \frac{d\hat y}{dz} \frac{dz}{dw}.

Local derivatives:

dLdy^=2(y^−y),dy^dz=v,dzdw=x.\frac{dL}{d\hat y}=2(\hat y-y), \qquad \frac{d\hat y}{dz}=v, \qquad \frac{dz}{dw}=x.

Therefore:

dLdw=2(y^−y)vx.\boxed{\frac{dL}{dw}=2(\hat y-y)vx}.

Parameter update:

w←w−ηdLdw.\boxed{w\leftarrow w-\eta\frac{dL}{dw}}.

What Each Symbol Means

SymbolRead it asMeaningIn code
xxinputvalue entering the networkx
wwweightlearned parameter in the first stepw
zzintermediateoutput of the first operationz
vvweightlearned parameter in the second stepv
y^\hat yy-hatpredictiony_hat
yytargetcorrect answery
LLlossnumerical measure of wrongnessloss
dL/dwdL/dwderivative of loss wrt weightsensitivity of loss to www.grad
η\etalearning rateupdate step sizelearning_rate

One-Minute Explanation

Imagine a chain of machines. The first machine uses a weight to turn an input into an intermediate value. The next machine turns that into a prediction. The loss tells us how wrong the final prediction is.

Backpropagation starts at the loss and walks backward. At each machine it asks: “If my input changed a little, how much would my output change?” It multiplies that local answer by the amount of error arriving from downstream.

If there are several paths, their contributions are added.

So backpropagation is simply the chain rule organised as an algorithm for a computation graph.


Exercises

Level 1 — Observe

Look at the graph w→z→y^→Lw\rightarrow z\rightarrow\hat y\rightarrow L. Which quantity is furthest upstream from the loss?

Level 2 — Calculate

For x=3x=3, v=2v=2, y^−y=−4\hat y-y=-4, compute dL/dw=2(y^−y)vxdL/dw=2(\hat y-y)vx.

Level 3 — Derive

Starting from L=(vwx−y)2L=(vwx-y)^2, derive dL/dwdL/dw using the chain rule without expanding the square first.

Level 4 — Investigate

In the notebook, change only ww and plot the loss and gradient. Predict where the gradient becomes zero before running the code.

Level 5 — Design

Build a three-stage scalar computation with at least one branching path. Derive the gradient to the first parameter by multiplying along paths and adding where paths merge.


Common Mistakes

MistakeWhy it is wrong
Calling the gradient the errorthe gradient measures sensitivity of the loss to a parameter
Multiplying gradients across two separate branchesseparate paths contribute by addition
Updating parameters inside backpropagationgradient calculation and optimization are separate steps
Forgetting intermediate valueslocal derivatives often depend on values produced by the forward pass
Thinking backward propagation sends data backwardit sends derivative information backward

Socratic Questions

Why does a weight far from the output still receive a useful learning signal?

Why do local derivatives multiply along one path?

Why must gradients from two branches be added?

Why would differentiating one giant expanded expression become difficult to maintain?

What changes when one scalar parameter becomes an entire weight matrix?


🔭 Bridge to Chapter 085

Our scalar example is complete. But real layers do not have one input, one output and two weights.

A dense layer may have thousands of weights. Every training example contributes to those weights. Writing one scalar derivative after another would hide the repeated structure we just discovered.

Next question: Can we take the same chain-rule reasoning and pack all those repeated scalar derivatives into three matrix formulas — one for the weights, one for the bias, and one for the input?

Yes. The next chapter derives

dW=XTdZ,db=∑dZ,dX=dZWT.\boxed{dW=X^TdZ,\qquad db=\sum dZ,\qquad dX=dZW^T}.

Six ways to work the chapter, climbing from explaining it in your own words to investigating it like a researcher. Reading is not enough — this is where the chapter lands.

Exercises should progress from understanding to research behaviour.

Level 1 — Explain it

Explain the idea in plain language without equations.

Level 2 — Calculate it

Solve a tiny numerical example by hand.

Level 3 — Predict it

Predict code output, model behaviour, tensor shapes, or graph movement before running anything.

Level 4 — Break it

Deliberately change an assumption or parameter and explain what fails.

Level 5 — Build it

Implement the core mechanism from scratch before using a high-level library.

Level 6 — Investigate it

Form a hypothesis, design an experiment, compare alternatives, and explain the evidence.