The loss landscape

AI from scratch · 2 of a series

The loss landscape: lesson transcript

1. Every line has a score

Last time we scored a line by adding up its squared gaps. Notice what the score depends on: only the two dials, w and b. Feed in a pair of numbers, get back one number. That is a function, and we can draw it.

2. Turn one dial

Hold the height fixed and sweep the tilt from 0 to 5. On the right, plot the error for every tilt you pass. It draws a U: high on both sides, one lowest point in the middle. That lowest point is the best tilt for this height.

3. Turn both

Now let the height vary too. Every pair (w, b) is a point on a map, and every point is one possible line. Colour it by error: pale green where lines fit well, red where they fit badly. A green valley appears, and its floor is the best line.

4. It is a bowl

Lift the map so error becomes height. What you get is a bowl, stretched into a long curved valley: smooth sides, a single lowest point, and every direction uphill from there. Fitting a model is nothing more than finding the bottom.

5. Change how you score, change the bowl

Squaring the gaps was a choice. Slide δ down and big gaps are counted at face value instead of squared: the bowl turns into a sharp-bottomed trough. The scoring rule is called the *loss*, and its shape is the landscape the model has to search.

6. Walk the map

Move the dials. The line on the left and the ball on the right are the same object seen two ways: one line, one point on the map. Try to steer the ball to the floor of the valley by watching the gaps shrink.

7. Name it: the loss landscape

The error as a function of the dials is the *loss landscape*. Two dials gave a bowl you can look at; a real network has millions of dials and a landscape nobody can draw. Training means finding the bottom without ever seeing the whole map. That is next.

8. Did it land?

Look back at the flat map: the green valley runs diagonally, not straight up or across.

Check your understanding

Why does the valley on the map run diagonally?

Move the ball along the valley floor and the line on the left barely changes: a steeper tilt with a lower height crosses the data in almost the same place. Directions where the line does not change are directions where the error does not change either.