The loss as a landscape
Fix the data and the loss becomes a surface over the parameters. Every point on it is a whole model; training walks downhill across it.
1. The idea
Fix the data, and the loss becomes a function of the parameters alone. With two parameters, the w and b of a line, you can draw it: every point (w, b) is a whole candidate line, and the height there is how badly that line fits. Training is a walk across this landscape looking for low ground.
For a linear model with squared error the landscape is a bowl: one lowest point, no traps, with elliptical contour lines. The ellipses are stretched when the parameters affect the loss very differently, which turns the bowl into a long, narrow valley, the shape that makes plain gradient descent zig-zag.
Real networks have millions of parameters, so nobody sees their landscape. The two-parameter picture still gives the right instincts: the gradient points across the contours, the learning rate decides how far each step jumps, and the shape of the valley decides how hard the walk is.
2. Try it: a model is a point
Drag the point on the right (or click anywhere there) and watch its line on the left. Find the green lowest point, and notice which direction the bowl is narrow in.
3. The math
4. The code (python)
import numpy as np
x = np.array([0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0])
y = np.array([1.9, 2.3, 3.4, 3.6, 4.4, 5.1, 5.3, 6.2, 6.8, 7.1])
W, B = np.meshgrid(np.linspace(-0.5, 2.5, 301), np.linspace(-2, 6, 401))
L = np.mean((y - (W[..., None] * x + B[..., None])) ** 2, axis=-1) # the whole landscape at once
i, j = np.unravel_index(L.argmin(), L.shape)
print(L.shape) # (401, 301)
print(round(W[i, j], 2), round(B[i, j], 2), round(L[i, j], 4)) # 1.19 1.34 0.02875. You’ll see this in
- Core Course chapter 1: what a model is a grid search over this same kind of landscape
- Mean squared error, read with the seven questions
- Module 4: partial derivatives and the gradient
6. Check yourself
Finished this chapter?
What changed in ML architectures this week
New models worth knowing, benchmark moves, and one architecture explained in plain words. Free, once a week, unsubscribe anytime.