The Learning Problem
A network starts with random weights, so its predictions are bad. We need a method to improve the weights. That method is gradient descent, and the way to calculate the needed changes is backpropagation.
Gradient Descent: Walking Down a Hill
- The gradient tells us the slope: which direction increases the loss
- We move in the opposite direction to decrease the loss
- The learning rate is the size of each step
A Tiny Example in Python
Let us find the value of w that minimizes the loss (w - 3)^2. We know the answer is 3, so we can check the result.
The value of w goes 0.6, 1.08, 1.46 ... until it is very close to 3.0.
Learning Rate
| Learning rate | What happens |
|---|---|
| Too small | Learning is very slow |
| Just right | Smooth and fast learning |
| Too large | Steps overshoot, the loss jumps around or grows |
Backpropagation
In a real network there are thousands or millions of weights. Backpropagation uses the chain rule from calculus to find out how much each weight contributed to the final error. It works from the output layer backward to the input layer, and that is why it has this name.
- Forward pass: the data flows through the network and produces a prediction.
- Loss: compare the prediction with the true value.
- Backward pass: calculate the gradient for every weight.
- Update: change each weight a little using gradient descent.
TensorFlow Does the Math for You
tf.GradientTape records operations and computes gradients automatically. This is called automatic differentiation.
model.fit() in Keras, all of this happens automatically for every weight in the network. You do not have to write it yourself.
Batches and Epochs
| Term | Meaning |
|---|---|
| Batch size | How many samples are used for one weight update |
| Iteration (step) | One weight update |
| Epoch | One full pass through the entire training dataset |
If you have 1000 samples and a batch size of 100, one epoch has 10 steps.
Conclusion
Gradient descent walks downhill on the loss surface and backpropagation tells it which way is down for every weight. Keras and TensorFlow take care of the calculations.

