← CS Lab AI & Machine Learning / Backpropagation Open standalone ↗

Backpropagation is how a network finds the gradient of its loss with respect to every weight — in one backward sweep. The tool shows the idea on a single weight; real nets just run the same chain rule across millions of them at once.

Where you meet it

What it does

It answers one question for every parameter: if I nudge this weight a hair, how much does the loss change? That number is the partial derivative ∂L/∂w. Collect them for all weights and you have the gradient — the direction the optimizer needs to step downhill.

Backprop gets every gradient for the price of one backward sweep — by reusing what the forward pass already computed.

How it works

First a forward pass runs input → layers → prediction → loss, saving each layer's output along the way. Then the backward pass walks the same graph in reverse, applying the chain rule: the error at the output is propagated back layer by layer, and at each step the incoming gradient is multiplied by that step's local derivative.

# forward
z = w*x + b
a = sigmoid(z)
L = 0.5*(a - y)**2

# backward — chain the local derivatives right to left
dL_da = a - y          # local: ∂L/∂a
da_dz = a*(1 - a)      # local: ∂a/∂z
dz_dw = x              # local: ∂z/∂w
dL_dw = dL_da * da_dz * dz_dw   # ∂L/∂w

Each node needs only its local derivative and the gradient handed to it from the right: multiply, pass it left. The reason this beats the naive approach is reuse — numerical differentiation would re-run the whole forward pass once per weight (millions of passes); backprop computes all gradients from a single forward + backward pass by sharing intermediate results.

Watch out

  • Vanishing & exploding gradients — multiplying many small local derivatives shrinks the signal toward zero (deep layers stop learning); many large ones blow it up. ReLU, residual connections and normalization exist largely to fight this.
  • Every operation in the path must be differentiable (or have a defined sub-gradient). A hard if or argmax stops the gradient cold.
  • The forward activations must be stored for the backward pass to use — that is the memory cost of training, and why batch size hits your VRAM.
  • Backprop only computes the gradient. It is not the learning step — the optimizer (SGD, Adam, …) is what actually updates the weights with w ← w − η·∂L/∂w.

Go deeper

Backpropagation berechnet den Gradienten des Loss bezüglich jedes Gewichts — in einem einzigen Rückwärtslauf. Das Tool zeigt die Idee an einem Gewicht; echte Netze ziehen dieselbe Kettenregel über Millionen Gewichte auf einmal.

Wo es vorkommt

Was es tut

Es beantwortet für jeden Parameter eine Frage: wenn ich dieses Gewicht ein winziges Stück verschiebe, wie stark ändert sich der Loss? Diese Zahl ist die partielle Ableitung ∂L/∂w. Sammelt man sie für alle Gewichte, hat man den Gradienten — die Richtung, in die der Optimizer bergab schreiten muss.

Backprop liefert jeden Gradienten zum Preis eines Rückwärtslaufs — indem es wiederverwendet, was der Forward Pass schon berechnet hat.

Wie es funktioniert

Zuerst läuft ein Forward Pass: Eingabe → Schichten → Vorhersage → Loss, und jede Schicht-Ausgabe wird unterwegs gespeichert. Dann läuft der Backward Pass denselben Graphen rückwärts mit der Kettenregel: Der Fehler am Ausgang wird Schicht für Schicht zurückpropagiert, und bei jedem Schritt wird der eingehende Gradient mit der lokalen Ableitung dieses Schritts multipliziert.

# forward
z = w*x + b
a = sigmoid(z)
L = 0.5*(a - y)**2

# backward — lokale Ableitungen von rechts nach links verketten
dL_da = a - y          # lokal: ∂L/∂a
da_dz = a*(1 - a)      # lokal: ∂a/∂z
dz_dw = x              # lokal: ∂z/∂w
dL_dw = dL_da * da_dz * dz_dw   # ∂L/∂w

Jeder Knoten braucht nur seine lokale Ableitung und den Gradienten von rechts: multiplizieren, nach links reichen. Warum das den naiven Weg schlägt, ist Wiederverwendung — numerische Differentiation müsste den ganzen Forward Pass einmal pro Gewicht neu rechnen (Millionen Durchläufe); Backprop liefert alle Gradienten aus einem einzigen Forward- + Backward-Pass, indem es Zwischenergebnisse teilt.

Worauf achten

  • Vanishing & Exploding Gradients — das Multiplizieren vieler kleiner lokaler Ableitungen drückt das Signal gegen null (tiefe Schichten lernen nicht mehr), viele große sprengen es. ReLU, Residual Connections und Normalisierung gibt es größtenteils dagegen.
  • Jede Operation im Pfad muss differenzierbar sein (oder einen definierten Sub-Gradienten haben). Ein hartes if oder argmax bricht den Gradienten ab.
  • Die Forward-Aktivierungen müssen gespeichert sein, damit der Backward Pass sie nutzen kann — das ist der Speicherpreis des Trainings und der Grund, warum die Batch-Größe dein VRAM frisst.
  • Backprop berechnet nur den Gradienten. Es ist nicht der Lernschritt — der Optimizer (SGD, Adam, …) aktualisiert die Gewichte mit w ← w − η·∂L/∂w.

Mehr dazu

Next up
AI & Machine LearningLoss Functions AI & Machine LearningSoftmax All concepts →