Availit World How AI really works, in your language

Lesson 9 of 4615 minFacts checked October 20, 2026

Machine learning: letting data choose the numbers

Under every AI system is one simple recipe: pick a function with some adjustable numbers, measure how wrong it is on examples, and let gradient descent fix the numbers. Here you will run that recipe on a model with two numbers. DeepSeek runs it on a trillion.

In this lesson you will

  • Name the four ingredients of every machine-learning system: data, model, loss and optimizer
  • Fit a straight line to data with gradient descent, and use it to predict
  • Tell apart supervised, self-supervised and reinforcement learning, and see where each appears in a language model
  • Spot overfitting, and say why a model must be tested on examples it has never seen
On this page
  1. The recipe
  2. Your first model: a straight line
  3. Too simple, too clever, just right
  4. Three ways to learn
  5. Numbers or categories
  6. Remember
  7. Check yourself

The recipe

Every machine-learning system, from a spam filter to a chatbot, is made of the same four ingredients. Papers describe them in the same order, so learning to spot them is the first step to reading papers.

  1. Data: examples to learn from, such as emails marked spam or not, or trillions of tokens of text.
  2. Model: a function with adjustable numbers (the parameters) that turns an input into an output. Papers call its design the architecture.
  3. Loss: one number that says how wrong the model’s outputs are on the data. Papers call it the objective.
  4. Optimizer: the method that adjusts the parameters to lower the loss, usually a form of gradient descent.

Training is running the optimizer over the data until the loss stops improving. Then comes the real test: does the model work on examples it has never seen? That ability is called generalisation, and it is the whole point. A model that only works on its training examples is useless.

Your first model: a straight line

Here is a small, real-looking dataset: eight students, how many hours each studied, and their test score. The simplest model you could try is a straight line.

score = w × hours + b

Two parameters. w (the weight) is how many points each hour of study adds. b (the bias) is the score with no study at all.

loss = average of (prediction − real score)²

The mean squared error from the last lesson.

Try itFit the line

The dots are the students; the thin lines show each prediction’s error. Try to fit the line yourself with the two sliders and watch the error number. Then press the button and let gradient descent do it.

This interactive part needs JavaScript.

Gradient descent finds the best line in a few steps: w ≈ 4.5 and b ≈ 47, with the average squared error falling from 155 to under 1. Now the model can predict: a student who studies 10 hours should score about 4.5 × 10 + 47 ≈ 92, even though no one in the data studied that long.

Quick check

In the line model, what does b stand for?

Show the answer

Answer: The predicted score with zero hours of study When hours = 0, score = w × 0 + b = b. The slope w is the points per hour.

Too simple, too clever, just right

A model can fail to generalise in two opposite ways.

Underfitting

  • The model is too simple for the pattern, like a straight line through data that curves.
  • It is wrong on the training data and on new data.
  • Fix: a more flexible model, or better inputs.

Overfitting

  • The model is so flexible that it memorises the training examples, noise and all.
  • Almost perfect on training data, poor on new data.
  • Fix: more data, a simpler model, or stop training earlier.

To catch overfitting, data is split in two (often three) before training starts. The training set is what the model learns from. The test set is locked away and used only at the end, to measure how well the model works on things it has never seen. A third validation set is used along the way to choose settings, so the test set stays untouched.

Three ways to learn

Machine learning comes in three main flavours, depending on where the “right answers” come from. A modern language model uses all three, one after another.

Where the answers come from
The model learns fromExampleIn a language model
Supervised learningExamples labelled by people with the right answerEmails marked spam or not spamFine-tuning on written examples of good assistant replies
Self-supervised learningData that contains its own answers: hide part of it and predict itPredict the next word of a sentencePretraining: predict every next token of trillions of tokens of text
Reinforcement learningTrying things and getting a reward or a penaltyA program that learns Go by playing millions of gamesRewarding correct maths answers or passing code tests (how DeepSeek-R1 learned to reason)

The middle row is the breakthrough behind large language models. Labelling data by hand is slow and expensive, but text labels itself: every sentence on the internet is an example of which word comes next. That is why models can learn from trillions of tokens without anyone marking a single answer.

Which kind of learning is each one?

0 of 6 sorted
  • Learning to recognise cats from 10,000 photos each tagged “cat” or “not cat”

    Answer: Supervised

  • Predicting the next token of web pages

    Answer: Self-supervised

  • A robot that gets a point each time it picks up a cup without dropping it

    Answer: Reinforcement

  • Hiding random words in sentences and guessing them

    Answer: Self-supervised

  • Rewarding a model when its code passes the tests

    Answer: Reinforcement

  • Training on question-and-answer pairs written by experts

    Answer: Supervised

Numbers or categories

Models also differ in what they output. Regression predicts a number, like a test score or tomorrow’s temperature. Classification picks a category, like spam or not spam, or which of 1,000 kinds of object is in a photo. A classifier usually outputs a probability for every category through a softmax, exactly as you saw in the probability lesson.

Seen this way, a language model is a classifier. The categories are the tokens of its vocabulary, 128,256 of them for Llama 3.1 8B, and each step picks one. It just runs again and again, feeding each choice back in, to write a whole reply.

Remember

  • Every ML system has four ingredients: data, a model (architecture), a loss (objective) and an optimizer.
  • Fitting a line (score = w × hours + b) by gradient descent is the whole recipe in miniature; language models run it with billions of parameters.
  • The goal is generalisation. Underfitting is too simple; overfitting is memorising. A locked test set tells them apart.
  • Supervised (labelled answers), self-supervised (data predicts itself) and reinforcement learning (rewards). Pretraining is self-supervised.
  • A language model is a classifier over its vocabulary, run once per token.

Words to know

Parameter
An adjustable number in a model. Weights and biases are parameters.
Architecture
The design of a model: what kind of function it is, before its numbers are learned.
Generalisation
Working well on new examples, not just the ones learned from.
Overfitting
Memorising the training examples instead of learning the pattern.
Training, validation and test sets
Data to learn from, data to choose settings with, and locked data to measure the final result.
Contamination
Test questions leaking into training data, which makes scores look better than the model is.
Supervised learning
Learning from examples labelled with the right answer.
Self-supervised learning
Learning from data that supplies its own answers, like predicting the next token.
Reinforcement learning
Learning by trying actions and receiving rewards or penalties.
Regression and classification
Predicting a number, or picking a category.

Go to the source

This lesson is built on these papers and documents. Paper links open arxiv.org, a separate site.

Check yourself

5 questions. Tap the answer you think is right.

0 of 5 answered

Which of these is NOT one of the four ingredients of a machine-learning system?

Show the answer

Answer: A list of hand-written rules The four are data, a model, a loss and an optimizer. Hand-written rules are the old way that machine learning replaces.

A model scores 99 % on its training data and 60 % on new data. What is happening?

Show the answer

Answer: Overfitting Doing far better on the examples it learned from than on new ones means it memorised instead of learning the pattern.

Why is pretraining a language model called self-supervised?

Show the answer

Answer: The text supplies its own answers: each next token Every piece of text already contains the right answer for each position, the token that follows, so nobody needs to label it.

DeepSeek-R1 was rewarded when its maths answers were correct. What kind of learning is that?

Show the answer

Answer: Reinforcement Learning from rewards for good outcomes, rather than from labelled examples, is reinforcement learning.

The line model is score = 4.5 × hours + 47. What does it predict for 6 hours?

Show the answer

Answer: 74 4.5 × 6 + 47 = 27 + 47 = 74.

Lesson complete

Answer every question above to complete this lesson.

Your progress is saved on this device only.

Next lessonNeural networks: small functions, stacked deep
Previous lesson All lessons

Choose your language