Go to Map Courses Lab Glossary How it works Troubleshooting Start →
ITEN
← Course 01 · The Basics (Lesson 01.03 · 18 minutes · No sensor · For everyone)

How a model learns.

Inside a model there are no rules written by hand. There are millions of numbers that start out random, and training adjusts them a little at a time. Here you'll follow a photo into the network and watch the numbers learn.

What you learn
  1. How a photo becomes a table of numbers
  2. What a neuron, a layer and the weights do
  3. Why learning means bringing a loss down
  4. Why training costs a lot and using the model costs little
You need to know

If you don't remember one of these, the link takes you to the chapter that explains it.

How do you want to follow it
Preparing the scene…
  1. 01 The numbers

    To a model, a photo is a table of numbers.

    The model doesn't see colors, it reads numbers. A photo of 224 by 224 pixels becomes a table with 224 rows and 224 columns. Each cell holds three numbers from 0 to 255, one for red, one for green and one for blue. A table like this is called a tensor.

    In practice. Sound and motion become tables of numbers too. That's why the same models work with such different sensors.

01 / 07
(Go deeper)

A few more numbers.


(01)

How many calculations a network does

ResNet-50, a famous network from 2015, has about 25 million parameters, and for each photo it does about 4 billion multiplications, each followed by an addition. MobileNet v2, built for phones, has 3.5 million parameters and does about 300 million. That's more than ten times fewer, with only slightly lower accuracy.

With the weights stored as 32-bit numbers with a decimal point, 4 bytes each, MobileNet v2 takes up about 14 MB. With 8-bit quantization it drops below 4 MB.

  • 3.5 Mparameters in MobileNet v2
  • 300 Mmultiplications for each photo
  • 14 MBits weights at 32 bits
(02)

How long is a step

The length of the step in the descent is called the learning rate. If it's too long, the model jumps from one side of the valley to the other and never settles at the bottom. If it's too short, it goes down so slowly that it never gets there. A common starting value is 0.001.

Each step moves every weight with the same rule. The new weight is the old weight minus the learning rate times the slope of the loss for that weight.

weight = weight - learning_rate * slope
(03)

Where the slope comes from

To know how to move millions of weights, the model computes the loss at the end and then carries it back layer by layer, all the way to the start. Each layer gets its share of the blame and splits it among its weights. This backward pass is called backpropagation.

Nobody writes it by hand. Libraries like PyTorch and TensorFlow work out all the slopes on their own. In the browser the job is done by TensorFlow.js, the library the lab uses.

(Try it on your phone)

Teach a small network


Tap the sheet to place yellow dots and black dots, then press Train. Tap a dot you already placed to remove it. A tiny network tries to separate them, and the background color shows what it has learned. Below, you see the loss going down.

The tool needs JavaScript turned on.

Try removing the hidden neurons. Without a hidden layer the network can only draw a straight line, and it can't separate dots in a circle. Then put 8 neurons back and try a step that's too long. Watch the loss jump.

(Quiz)

4 questions to close the lesson.

When you have answered them all, the lesson counts as done and its stone on the map turns yellow. Answering is what counts, not the score.


  1. (01)

    What are the weights of a neural network?

  2. (02)

    The model says 97 percent sick. What can you conclude?

  3. (03)

    What does the phone do when it recognizes a photo with a model that's already trained?

  4. (04)

    During training the loss jumps up and down instead of going down. What do you try first?

To close the lesson, answer the quiz

← What's inside your phone Back to the map
(Next lesson · 01.04) The map of models