Access AI Education
← Primer

Learning

The problem

When a brand new AI model is created, it knows absolutely nothing. Zero. It's like a baby, except worse, because a baby at least has instincts.

The model is just a big pile of numbers (called weights), and at the start, those numbers are completely random. Ask it to predict the next word in "The sky is ____" and it might say "banana" or "the" or "#@$!", it has no idea.

So how does it go from knowing nothing to writing essays, answering questions, and generating code?

It learns from its mistakes. Over and over and over again. Billions of times. That's the entire secret.

During training, the model reads through a massive dataset, billions of sentences from books, Wikipedia, websites, forums, and code repositories. It sees each sentence, tries to predict the next word, and adjusts when it's wrong. That's how it goes from clueless to capable.

Loss

When you're learning to throw darts, you need to see how far you are from the bullseye. If you can't see the target, you can't improve.

AI works the same way. After the model makes a guess, we need to measure how wrong it was. This measurement is called the loss.

  • Model predicts "banana" when the answer was "blue"? That's a high loss (very wrong).
  • Model predicts "blue" when the answer was "blue"? That's a low loss (nailed it).

The goal of training is simple: make the loss go down. Lower loss = better predictions. That's it. The entire training process is just the model trying to shrink its loss, one step at a time.

Watch the error meter on the right, it shows how wrong the model is.

Try it yourself

Let's try something. Imagine you're standing on a hilly landscape in thick fog. You can't see more than a few feet. Your goal: find the lowest valley.

What would you do? You'd feel the ground around you and take a step downhill. Then feel the ground again. Step downhill again. Eventually, you'd reach a low point.

That's exactly how the model learns! It can't see the whole landscape, it just checks which direction "downhill" is (which way reduces the loss) and takes a small step that way.

This process is called gradient descent. "Gradient" = which direction is downhill. "Descent" = walking that way.

Try it yourself in the demo on the right. Drag the ball downhill and watch the loss decrease.

Loading activity…

What the computer does

You just did gradient descent by hand, feeling which way is downhill and stepping that way.

The computer does the exact same thing, but automatically and incredibly fast. It:

1. Shows the model some text (like "The cat sat on the")
2. The model guesses the next word

3. Checks the answer and measures the loss

4. Figures out which direction to nudge each weight to make the loss smaller

5. Nudges all the weights a tiny bit

6. Goes back to step 1 with new text

It does this cycle thousands of times per second, with billions of weights being nudged simultaneously. After seeing enough examples, the weights settle into values that make good predictions.

Learning rate

Remember the downhill walk? There's one important detail: how big are your steps?

If you take tiny baby steps, you'll eventually reach the bottom, but it'll take forever. If you take huge leaping steps, you might jump right over the valley and end up on the other side, even higher up.

The step size is called the learning rate, and getting it right is crucial:

  • Too small: The model learns painfully slowly. It might take weeks instead of days.
  • Too big: The model overshoots, bouncing wildly. The loss goes up instead of down. It never settles.
  • Just right: The model steadily improves, getting a little better with each step.

Finding the right learning rate is one of the trickiest parts of training AI models.

Putting it together

Let's zoom out and see the full picture of how a model learns.

1. Start with random weights, the model knows nothing
2. Show it some text, like a sentence from a book or website

3. It guesses the next word, badly, at first

4. Measure the loss, how wrong was it?

5. Figure out which way to adjust, gradient descent tells us the direction

6. Nudge the weights, make them a tiny bit better

7. Repeat, millions and millions of times

Each time through this loop, the model gets slightly better at predicting words. After seeing billions of sentences, those random weights have been shaped into something that can write poetry, answer questions, and explain quantum physics.

An important thing to understand: the "training data" isn't a database the model searches through later. The model reads through it during training and compresses the patterns into its weights. After training, it doesn't look anything up, it generates from what it learned, kind of like how you don't re-read a textbook during an exam.

The model never "understands" anything the way you do. But its predictions get so good that it's hard to tell the difference.

What happens if the learning rate is too high during training?

What's next

You now know how a model starts from nothing and learns to predict words. It makes guesses, measures how wrong it was, figures out which direction to nudge its weights, and repeats this billions of times.

But there's a mystery we skipped over. The model turns every token into a list of numbers, an embedding. At first, these numbers are random. But during training, something magical happens: words with similar meanings end up with similar numbers.

"King" and "queen" become close together. "Dog" and "puppy" become neighbors. The model discovers meaning just by trying to predict the next word.

Next lesson: Embeddings, how numbers capture meaning.

Ready for the next lesson?

Answer 1 remaining question above to finish this lesson.