Study guide · How machines learn
How machines learn: examples, errors and layers
How do you teach a computer to recognize a handwritten seven? Nobody can write down every way people write a seven. This is exactly where machine learning comes in. On this page you follow this one question from the basic terms to the networks that read ZIP codes and bank cheques in the 1990s. Along the way you find out why deep networks were still seen as impractical until about 2010.
Learning from examples instead of rules
In classic programming a person writes every rule. With handwriting, that fails because of the sheer variety. In machine learning the computer gets many examples instead. It derives the rules from the data by itself. Data are therefore essential.
Three terms come up again and again:
- An example is a single record, such as the image of a digit.
- Features are the inputs the model reasons from. For an image of a digit, that is for example the brightness of each pixel.
- A label is the correct answer for an example, that is, the digit that was meant. You can picture it as a small card attached to each image.
The model is a calculation rule that turns the features into a prediction. Its behaviour depends on many adjustable numbers, the parameters. In neural networks they are called weights. Training means setting the parameters so that the model explains the examples well.
There are also settings that you choose yourself before training. They are called hyperparameters. They include the learning rate and the number of hidden layers in a network. The weights and thresholds of the neurons, by contrast, are real parameters, because training sets them from the data.
Three types of learning
Depending on what is known about the data, there are three types of learning.
In supervised learning every training example carries a label. The model learns to infer the label from the features. If it predicts a category, this is called classification. Examples are "spam or not spam" and "which digit". If it predicts a numerical value, this is called regression, for example a house price from size and location, learned from past sales. Both need labels. Networks and decision trees can solve both tasks.
In unsupervised learning there are no labels. The method looks for similarities by itself and forms groups, for example of customers with similar buying habits. A well-known method for this is k-means. James MacQueen coined the name in 1967; the basic idea is older.
In reinforcement learning a program acts, observes the result and receives a reward or a penalty. There is no correct answer per example. The program learns to choose actions that bring many points in the long run. Often the reward only comes much later, for example at the end of a game.
Measuring the error and going downhill
How does a model set its parameters? First it needs a measure of how wrong it is. That is the loss function. It measures how far the model's predictions are from the correct answers and sums this up in a single number. Training tries to make this number as small as possible.
Imagine the error as a landscape of hills and valleys. Each spot stands for one setting of the parameters, and the height stands for the error. Gradient descent works like a ball rolling downhill. The method checks in which direction the error falls most steeply and takes a small step that way. The bottom of the valley stands for the smallest error. A random search, by contrast, would try out new settings blindly.
The size of each step is set by the learning rate. It is a hyperparameter.
- If the learning rate is too small, training only crawls along.
- If it is too large, every step jumps across the valley onto the other slope. The error may even grow.
Gradient descent only sees the slope nearby. At the bottom of a small valley the slope is zero, and it stops, even if there is a deeper valley elsewhere. This is called a local minimum. Smaller steps do not help here; they stay in the valley all the more. Whether you end up in the deepest valley therefore also depends on the starting point.