Backpropagation & empirical risk
This lecture trains a small network by hand with backpropagation, from feedforward sums to gradient updates. It defines the MSE loss and empirical risk as the average loss over training samples. After this page you can do one full backpropagation update with learning rate 0.1 by hand.
Training with backpropagationSearch on YouTube
Training finds the best learnable parameters of a network. It repeats three steps: feedforward, loss calculation, and backpropagation. Each cycle nudges every weight and bias. Many cycles drive the loss down.
Feedforward alone only predicts. The loss scores the prediction against the label. Backpropagation assigns credit to each weight for that score. Without this loop the network cannot learn.
Feed, Loss, Push: F-L-P
Feedforward sends inputs forward · Loss scores the prediction · Push gradients back and update each weight.
Feedforward passSearch on YouTube
Feedforward sends the input vector through the network layer by layer. Each neuron forms a weighted sum of its inputs plus a bias. Then it applies its activation function. The slides write the hidden output as and pass it on as . They write the final output as .
= weighted sum plus bias at one neuron. = weight on input . = bias of the neuron. and = activation functions. = network output.
Hidden-layer sumsSearch on YouTube
The hidden layer converts raw inputs into learned features. Each hidden neuron has its own weights and bias. Its output becomes an input of the next layer.
Output-layer sumSearch on YouTube
The output layer combines the hidden outputs into one sum. It adds its own bias and applies its own activation function. That result is the prediction .
Worked example. Inputs and . Hidden neuron 1 uses weights and with bias . Hidden neuron 2 uses weights and with bias . The output neuron uses weights and with bias . Every activation is the sigmoid . The label is .
Step 1. Hidden weighted sums.
Step 2. Hidden activations. Apply .
Step 3. Output sum and prediction.
Loss calculationSearch on YouTube
Loss measures the gap between the prediction and the label for one sample. The slides use the mean squared error (MSE). With one sample () the mean is the single squared gap.
= label of sample . = network prediction for sample . = number of samples. Square the gap so positive and negative gaps both add cost.
Worked example. The network above predicts for label ().
Worked example. Two samples. Labels and . Predictions and .
Backpropagation at the output layerSearch on YouTube
Backpropagation sends the loss signal backward through the network. The chain rule splits each gradient into a product of local partials. The output layer comes first because it sits next to the loss.
The slides call this Equation (1). It gives the slope of the sigmoid at any sum . Every sigmoid partial below uses it.
= loss signal at the output sum. = learning rate (here ). Each weight moves against its gradient. The bias updates the same way.
Worked example. Loss , , , .
Step 1. Output loss signal.
Step 2. Output-layer gradients. Each gradient is the signal times its input.
Step 3. Update with . Subtract the learning rate times each gradient.
Keep the sign. A negative gradient raises the weight because minus times minus is plus. Check the sign of before every update.
Backpropagation at the hidden layerSearch on YouTube
The hidden layer needs the signal that passes through the output weights. Each hidden neuron gets only its share of . Then the sigmoid slope at its own sum shapes that share.
= loss signal at a hidden sum. = output-layer weight on that hidden output. = sigmoid slope from Equation (1). Hidden weights update with .
Worked example. Signal flows back through and .
Step 1. Hidden loss signals.
Step 2. Hidden gradients. Multiply each signal by its input (, ).
Step 3. Update with .
Update the biases too. Students often update the weights and leave the biases fixed. The bias gradient equals the neuron signal, so its step is .
Second feedforward passSearch on YouTube
One update ends one training round. A fresh feedforward pass with the new weights tests the round. The loss should fall.
Worked example. Use all six updated weights and both updated biases.
Step 1. New hidden outputs.
Step 2. New prediction and loss.
Step 3. Compare. Loss falls from to . The update helps. Many more rounds follow.
The lab below replays the worked example on this page. It moves the loss signal back and updates each weight once.
The 2-2-1 network learns one sample with label 1. Circles hold activations and arrows hold weights.
Feedforward gives O = 0.6623 and loss L = 0.1141. Select a circle or an arrow. Run plays one update with learning rate 0.1.
Batch, SGD, and minibatchSearch on YouTube
The update rule needs gradients, but the data size sets how often updates happen. Three schemes split the same epoch in different ways. One epoch means one full pass over the training set.
| Method | Samples per update | Updates per epoch | Character |
|---|---|---|---|
| Batch GD | all | stable gradient, slow per step | |
| SGD | noisy steps, fast and frequent | ||
| Minibatch | () | middle ground, used in practice |
Batch GD sums the gradient over every sample before one step. SGD updates after each single sample. Minibatch updates after each small group of samples. Minibatch keeps some noise but stays efficient on modern hardware. The slides name all three as ways to minimize empirical risk.
Chain-rule equationsSearch on YouTube
The chain rule links the loss to any weight through the sums between them. Each factor is a local slope. Their product is the full gradient.
= loss slope at the prediction. = activation slope (use Equation (1) for sigmoid). = the input that the weight scales. Deeper weights chain more factors.
Empirical risk minimizationSearch on YouTube
Training minimizes the average loss on the training set. This average has a name: empirical risk. The theory behind it starts with the data distribution.
Joint data distributionSearch on YouTube
Supervised data holds pairs . Here is an input feature vector and is its label. A joint probability distribution governs how these pairs arise. It states the chance of each input and label happening together. It acts like the real-world rule that produces labels for inputs.
The true distribution stays unknown. The training set is only a finite sample drawn from it. The goal is a function that mimics the true map from to . Here is the parameter vector holding all weights and biases. A good works on new samples, not only on training samples.
Empirical riskSearch on YouTube
= empirical risk for parameters . = per-sample loss. = prediction, which depends on both the input vector and the parameters. Empirical risk is the average loss over all training samples. Training minimizes it with gradient descent, SGD, or momentum methods.
Worked example. Four samples give losses , , , and .
The single number scores the whole training set. The optimizer drives it down step by step.
Do not trust a low training loss alone. A model can memorize training samples yet fail on new data. Low empirical risk must still generalize to the true distribution.
Quick self-testSearch on YouTube
1. Name the three training steps in order.
Feedforward, loss calculation, backpropagation. Repeat the three to lower the loss.
2. Inputs are 0.5 and 0.3. A neuron has weights 0.4 and 0.2 with bias 0.1. Find z and h with a sigmoid.
. .
3. Label is 1 and prediction is 0.6623. Find the MSE loss for n = 1.
. One sample means the mean equals the single squared gap.
4. Given output signal -0.1511 and hidden output 0.5890, find the gradient for their connecting weight.
Multiply signal by input: . With the weight rises by .
5. Why does the hidden signal multiply by h(1 - h)?
is the sigmoid slope from Equation (1). It converts the signal at the hidden output into a signal at the hidden sum.
6. Differentiate batch GD, SGD, and minibatch by updates per epoch.
Batch GD makes update per epoch. SGD makes updates. Minibatch makes updates. Minibatch is the practical middle ground.
7. A weight is 0.4 and its gradient is -0.0110. Update it with learning rate 0.1.
. The negative gradient raises the weight.
8. Four losses are 0.04, 0.09, 0.16, 0.25. Find the empirical risk.
. Empirical risk is the average loss over training samples.
9. After one update the loss falls from 0.1141 to 0.1103. Does training stop now?
No. One step only starts the process. Training repeats feedforward, loss, and backpropagation until the loss settles.
10. Training loss is near zero but new data scores poorly. What went wrong?
The model fits training samples without matching the true distribution. Low empirical risk alone does not guarantee new-data results.
- Training repeats three steps: feedforward, loss calculation, backpropagation.
- Feedforward builds , then with , and .
- MSE loss is ; the example gives .
- Sigmoid slope (Equation 1) is .
- Output signal is ; weights move by with .
- Hidden signals are ; biases update too.
- The second feedforward pass cuts the loss from to .
- Batch GD uses all samples per update, SGD uses , minibatch uses .
- Empirical risk is ; the example gives .
- Low training loss alone does not guarantee good results on new data.
Backprop intuitively
Backprop calculus
Backprop Main Ideas
Backprop Chain Rule