AI Hints
Home›Fine-Tuning LLMs Tutorial›What Fine-Tuning Is
Fine-Tuning LLMs · Lesson 2 of 120

How LLMs Work

Predicting the next token.

⏱ 2 min read▶ Video at 1:48🎓 Free
Watch this lesson in the Fine-Tuning LLMs courseWatch on YouTube ↗Full Fine-Tuning LLMs course

Before we can fine-tune a model, we need to know what it actually does. The answer is surprisingly simple. It predicts what text comes next. That's all.

  • What does an LLM do?
  • A surprisingly simple answer
  • It predicts what comes next

Tokens

Models don't read letters, or whole words. They read tokens. A token is a small piece of text. Often a whole word, sometimes part of a word. For example, the word unhappiness might become two tokens, un, and happiness. A typical model knows about fifty thousand different tokens.

keyvalue
Tokena small piece of text
Oftena whole word
Sometimespart of a word: un + happiness
Vocabulary~50,000 tokens

Next token prediction

Here's what a model does. We give it some text. The cat sat on the. It looks at every token, and works out a probability for each possible next token. Mat is the most likely. Floor and sofa are less likely. Then it picks one. Mat. And it does it again, for the next token.

From tokens to answers

So how does a model write a whole answer? One token at a time. It predicts a token, adds it to the text, then predicts the next one. It keeps going until it predicts a special token that means stop. This is called generation. Every chat answer you've ever seen was made this way.

keyvalue
Predictone token
Addit to the text
Repeatuntil a stop token
Calledgeneration

Quick check

Let's check. What does a language model predict, at each step? Pause, and think about it. The answer is B, the next token.

Quick check
At each step, a language model predicts...

Summary

Let's recap. Models read text as tokens. At every step, they predict the probability of each possible next token. And they write answers one token at a time. Next, how a model learns all this, with pretraining, and then fine-tuning.

Key takeaways
  • Text → tokens
  • Predict the next token
  • One token at a time
Next up: Pretraining vs Fine-Tuning — two stages of training