How a Language Model Is Trained, in Three Stages
A language model is trained in three stages: reading lots of text, learning from examples, and learning from people's ratings. See each one, with examples.
Rodrigo Faustino ·
- Shelf
- Inside AI
- Call number
- DEN-005
- Level
- Beginner
- Reading
- 9 min
- Published
- Lab
- Quiz
A language model is trained in three stages. First, it reads an enormous amount of text and learns to predict the next piece, which gives you a base model. Next, it studies examples of well-written responses, written by people, and learns to carry out requests. Finally, it learns from the ratings people give to different responses, and adjusts itself to write what they prefer. None of this is a library of ready-made answers: the end result is a set of tuned numbers.
One caveat before we start. The description in this book follows a published recipe, the one from InstructGPT, a 2022 study from OpenAI. Today’s models use variations on that recipe, and the details of commercial models aren’t always public. What we learn here is the skeleton, not the full blueprint of any product.
What Training Means
A language model is a program with many internal numbers, called parameters. GPT-3, from 2020, has about 175 billion of them. The largest model in Meta’s Llama 3 family has 405 billion. Training means adjusting those numbers, little by little, so the model makes fewer mistakes at a task.
Here’s an analogy, and it’s only an analogy: imagine a mixing board with billions of knobs. Nobody knows what each knob does. Training is an automatic process that turns the knobs, listens to the result, compares it with what was expected, and turns them again, millions of times.
Stage 1: Read Lots of Text and Predict the Next Piece
In pretraining, the model is given an enormous amount of text and does just one thing: estimate which piece comes next. Google’s course on language models sums up the idea this way: the model estimates the probability of each piece showing up in a sequence. Those pieces are tokens, which the book What Are Tokens, and Why AI Doesn’t Read Words explains.
Here’s a made-up example, just for the illustration. Given the sentence “The cat climbed onto the …”, the model assigns a probability to each possible continuation.
When it’s time to generate, the program can take the most probable continuation or draw according to the odds. Google’s course describes both approaches. The choice between them is the subject of the book Temperature: Why the Same Question Gets Different Answers.
Training works like this: the program hides the next piece of a text that already exists, asks the model for its guess, compares it with the true piece, and adjusts the numbers to miss less next time. The text itself contains the right answer, which is why so much material can be used without anyone having to correct every example by hand.
The result is the base model. It knows patterns of language and of various subjects, but it wasn’t taught to hold a conversation. A base model, for instance, may simply continue your text instead of fulfilling your request. The InstructGPT paper explains why: the goal of predicting the next piece of web pages is different from the goal of following the instructions of whoever is asking, helpfully and safely. The authors call this gap misalignment and list the consequences: making up facts, producing biased or toxic text, or not following what was asked.
One detail about size: the paper shows that a larger model isn’t, by itself, better at doing what the person wants. The proof comes in stage 3.
Stage 2: Learn from Examples of Well-Written Responses
To teach the base model to behave like an assistant, the second stage uses examples. In InstructGPT, hired contractors write responses that demonstrate the desired behavior for a range of requests, and the model is fine-tuned on those examples in a supervised way. In other words, the model sees the request and the ideal response and adjusts its numbers to get closer to it.
The volume is small compared with pretraining. The paper cites about 13,000 requests with examples written by people.
This stage is why the assistant answers “sure, here you go” instead of continuing your sentence. When you write a well-organized request, as in How to Structure a Text Prompt, you’re speaking in the format the model saw in this stage.
Stage 3: Learn from People’s Preferences
Writing ideal responses is expensive, and it doesn’t always capture what a person prefers. The third stage swaps “write the perfect response” for “tell me which response you prefer.” In InstructGPT, it has two steps.
In the first, hired contractors see several of the model’s responses to the same request and rank them from best to worst. Those rankings are used to train a second model, the reward model, which learns to predict which response people would prefer. In the second step, the reward model gives scores to the assistant’s responses, and a reinforcement learning method called PPO adjusts the assistant to earn higher scores. In this second step, people aren’t directly involved.
The method has a technical name: reinforcement learning from human feedback, or RLHF. About 33,000 requests were used for the reward model and about 31,000 in reinforcement learning.
The result that became famous: in people’s evaluations, responses from the 1.3-billion-parameter InstructGPT were preferred over those of the 175-billion-parameter GPT-3, a model more than a hundred times larger. And the 175-billion-parameter InstructGPT was preferred over the 175-billion-parameter GPT-3 in about 85% of comparisons. Tuning with people’s opinions paid off more than simply getting bigger.
There are variations on this stage. A 2023 paper by Rafailov and colleagues proposes direct preference optimization, which does away with the reinforcement learning phase and the separate reward model training. According to the authors, the method is simpler to train and matches or beats classic RLHF in the tests they ran. The same paper describes RLHF as complex and often unstable.
What Training Helps Explain in Your Daily Life
Knowing the three stages explains behaviors that seem mysterious.
Why AI sometimes makes things up. The goal of pretraining is to predict what comes next, not to check whether something is true. The InstructGPT paper lists made-up facts among the effects of that goal, and even after tuning the model still makes simple mistakes and invents facts, according to the authors themselves. See how to handle this in When AI Makes Things Up: How to Check an Answer.
Why the same question gets different answers. The model estimates probabilities and, in many tools, draws from among the likely continuations.
Why how you ask matters. The model learned to carry out requests from examples of requests. A clear request looks more like what it saw.
Why tuning doesn’t fix everything. The InstructGPT paper describes an “alignment tax”: tuning with human feedback made performance worse on some public language benchmarks, and mixing in pretraining updates reduced that loss without eliminating it. The authors also point out that the group of people who did the rating was small and mostly English-speaking. What the model considers “a good response” reflects those people.
Think Before You Read the Answer
For each behavior below, say which stage it most likely came from. Then check the answer.
- The model continues a text you started, without trying to fulfill a request.
- The model answers in a conversational format, fulfilling the request.
- The model picks, from among several possible responses, the one that tends to please the people who rated.
Answers: 1, stage 1 (pretraining). 2, stage 2 (examples), which teaches the format of fulfilling requests. 3, stage 3 (preferences). The boundary between stages isn’t always clear-cut in real models, but asking “where did this behavior come from?” helps organize your thinking.
Test What Stuck
You’ll answer six questions about the stages, what people do in each one, and the study’s results.
Do you understand how the model is trained?
Question 1 of 6
In the first stage, pretraining, what does the model learn to do?
- Predict the next piece of a text
- Obey the orders of whoever talks to it
- Look things up in an encyclopedia whenever it's asked
- Rank answers from best to worst
Show answer
Right answer: A. In pretraining, the model reads a lot of text and learns to estimate which piece comes next. Following orders and pleasing people come in the later stages.
In pretraining, the model reads a lot of text and learns to estimate which piece comes next. Following orders and pleasing people come in the later stages.
Question 2 of 6
What is the order of the three stages described in this book?
- Preferences, examples, pretraining
- Examples, pretraining, preferences
- Pretraining, examples, preferences
- Pretraining, preferences, examples
Show answer
Right answer: C. First pretraining, which creates the base model. Then tuning with examples written by people. Finally, tuning with people's preferences.
First pretraining, which creates the base model. Then tuning with examples written by people. Finally, tuning with people's preferences.
Question 3 of 6
What do the contracted people do in the examples stage, in the case of InstructGPT?
- Write answers that show the desired behavior
- Fix spelling mistakes on the internet
- Program grammar rules by hand
- Delete texts from pretraining
Show answer
Right answer: A. In the examples stage, people write demonstrations of the desired behavior, and the model is tuned with them.
In the examples stage, people write demonstrations of the desired behavior, and the model is tuned with them.
Question 4 of 6
What is a reward model?
- A prize paid to the people who rate
- A model that learns to predict which answer people prefer
- A type of tokenizer
- A filter that deletes forbidden words
Show answer
Right answer: B. It's trained on the answers people ranked and learns to give each answer a score. Then the assistant adjusts itself to earn higher scores.
It's trained on the answers people ranked and learns to give each answer a score. Then the assistant adjusts itself to earn higher scores.
Question 5 of 6
Why might a model that has only gone through pretraining ignore your request?
- Because it was trained to continue texts, not to follow instructions
- Because it doesn't understand Portuguese
- Because it needs to be connected to the internet
- Because the request was too short
Show answer
Right answer: A. The goal of pretraining is to predict the next piece of text. That's different from following instructions helpfully and safely, which is why the later stages exist.
The goal of pretraining is to predict the next piece of text. That's different from following instructions helpfully and safely, which is why the later stages exist.
Question 6 of 6
In the InstructGPT study, the people rating answers preferred the answers of which model?
- Always the largest model, with 175 billion parameters
- The tuned 1.3-billion-parameter model, over the 175-billion-parameter GPT-3
- Neither: there was no difference
- The longest answers
Show answer
Right answer: B. Tuning with people's opinions made a model about a hundred times smaller preferred over the original GPT-3. Size isn't everything.
Tuning with people's opinions made a model about a hundred times smaller preferred over the original GPT-3. Size isn't everything.
The lab could not load. The summary above still applies.
Open this lab on its own page →Common Mistakes and Cautions
Thinking the model stores ready-made answers. It doesn’t consult a database of responses: it generates each response from the numbers it learned.
Thinking bigger is always better. The InstructGPT study shows that a much smaller model, tuned with people’s feedback, was preferred over a model a hundred times larger that had only gone through pretraining. Size counts, but tuning does too.
Mixing up training and fine-tuning. Training from scratch takes far more resources than fine-tuning an existing model with your own examples. Google’s course treats fine-tuning as one way of improving an already-trained model.
Treating this description as complete. What you’ve read is a published recipe from 2022. Today there are variations, such as direct preference optimization, and companies don’t always disclose the process behind commercial models. When a maker describes the training of a new model, use the three stages as a map to understand what changed.
Confusing “few-shot” with training. Putting examples into the request itself, which is called few-shot, doesn’t train the model. In the GPT-3 paper, the model gets no tuning for the task: the examples go into the request as text and apply only to that one response.
Keep Reading
- What Are Tokens, and Why AI Doesn’t Read Words
- Temperature: Why the Same Question Gets Different Answers
- When AI Makes Things Up: How to Check an Answer
References
- Ouyang, Long et al.. Training language models to follow instructions with human feedback, Abstract, introduction, and description of the three-step method; results with InstructGPT; limitations (2022). Consultado em Nov 28, 2026.
- Google. Machine Learning Crash Course: Large Language Models, Section on how a language model predicts the next token. Consultado em Nov 28, 2026.
- Brown, Tom B. et al.. Language Models are Few-Shot Learners, Abstract: GPT-3 size, training objective, and the meaning of few-shot (2020). Consultado em Nov 28, 2026.
- Rafailov, Rafael et al.. Direct Preference Optimization: Your Language Model is Secretly a Reward Model, Abstract: the difference between RLHF and direct preference optimization (2023). Consultado em Nov 28, 2026.
- Llama Team, AI @ Meta. The Llama 3 Herd of Models, Abstract: size of the largest model and context window (2024). Consultado em Nov 28, 2026.