Points That Read Digits
We know how the reader makes a decision. Each digit supplies a direction and an offset, the image supplies a point, and ten dot products decide which region contains it. But we have been given all the numbers that make this work. Where did they come from?
Suppose we erase them. There are ten lists to fill in, each containing a bias and 64 weights. We could try guessing. Write down 650 numbers, run some images through the resulting reader, and see how it does. If it does badly, change the numbers and try again.
This sounds hopelessly unstructured. But it also sounds like something we have seen before: choosing a point, evaluating a function, and looking for a better point. The first task is to work out what the point and the function should be.
30.1This time the reader is the point
In the first chapter an image became a point of
Now apply the same idea to the reader. Put its ten parameter lists end to end:
Another point in a high-dimensional space! This time it is a point of
There are now two spaces to keep track of. When we use a reader, we fix
Of course, watching probabilities change does not tell us whether they have improved. We need some answers to compare them with.
30.2What counts as a better reader?
The data include images whose written digits are already known. We call these digits the labels. Our training set consists of 3,823 pairs
where each
There is a wonderfully direct way to compare readers: count their mistakes. Feed every training image to the reader and count how often the largest score belongs to the wrong digit. This gives a function on
But imagine a reader that assigns a known three probability
We can make this problem particularly visible with the reader we already have. Call its parameter list
Every score is multiplied by
More generally, a small change of parameters usually leaves all the winning digits alone. Away from ties, the mistake count is locally constant. Its partial derivatives are zero there, even when the reader has much to learn. At a change of winner it can jump. Neither behavior gives us the smooth function we would like to study with calculus.
30.3Ask for probability on the known answer
For a labeled image
A good reader should put a large probability on
small. We call this quantity the loss for the image. Here and throughout the laboratory,
Why this particular function? First, it has the right direction:
There is also a useful way to understand adding these losses. If we multiply the probabilities assigned to all the known answers, then
Thus minimizing the sum of losses is equivalent to maximizing that product. We are asking the reader to account for the whole collection of known answers. One probability close to zero matters, even if many others are good. This identity is algebraic: it does not require us to regard the images as independent random events.
We can express the loss directly in terms of the scores. Recall that
Taking the negative logarithm gives
This is a smooth function of ten scores, and each score is a linear function of the stored parameters. We have turned the reader's answer into a function we can differentiate.
30.4Keeping the numbers in check
There is one more choice to make. Good predictions do not, by themselves, single out sensible parameter sizes.
For example, add the same vector
Also, increasing all scores by a common positive scale makes a winning answer more confident. That helps on images the reader gets right and hurts on images it gets wrong. We should not confuse increasing confidence with improving the decisions. Our existing reader makes 75 training mistakes, so this example does not say that scaling it forever improves its loss.
We will add a cost for large parameters:
This is the familiar squared distance from the origin in parameter space. It penalizes all 650 entries, including the biases. The positive constant
Our complete objective is therefore
It is a long expression, but it asks for two understandable things: put probability on the known digits, and pay for large stored numbers. We use a sum, rather than an average, of image losses. Changing to an average while leaving
The lowest point on this particular line is near
30.5What we will teach, and what we will test
The training images define
This distinction is easy to lose when we have a drawing pad that responds immediately. A reader can improve on the examples used to choose its numbers without improving by the same amount on new handwriting. Training performance tells us how well we solved the fitting problem. Test performance asks a different question about the resulting reader.
We have now supplied a precise meaning for “find a good reader”: find a point where
30.6Things to try
Compute the loss when the reader assigns the known digit probabilities
,0 . 9 , and0 . 5 . Which change in probability produces the larger change in loss?0 . 0 1 Show directly that adding the same constant to all ten scores leaves each softmax probability unchanged. Explain why this differs from multiplying all scores by a positive constant.
Suppose we replace the sum of losses by their average. What coefficient on
gives an objective with exactly the same minimizer as the one above?‖ Θ ‖ 2 / 2