Privacy note: We capture your IP address to provide customised and focused services. See our Privacy Policy.

Generative AI & Large Language Models — Alpha School

Lesson 5: Training: Pretraining, Fine-tuning and Alignment

A language model is not built in one step. It is built in three, and each step has a different purpose. First comes pretraining, where the model learns the patterns of language itself. Then fine-tuning, where it is taught to do particular jobs well. Then alignment, where it is steered towards being helpful, honest and safe to use. Understanding the three steps explains both what these models can do and why they behave the way they do when you talk to them.

Pretraining is the long, expensive part. The model is shown an enormous collection of text — books, articles, websites, code — and trained on a single task: predict the next token. It does this billions of times, adjusting its weights a little each time, until it can predict text well. At the end of pretraining, the model is very good at continuing text, but it is not a helpful assistant: ask it a question and it may answer with another question, or continue your question as if it were writing a quiz. It has learned language, not how to be useful.

From text predictor to assistant

Fine-tuning is where the model learns to be useful. It is trained further on examples of the behaviour wanted: pairs of instructions and good responses, written or checked by people. Thousands or millions of such pairs teach it the shape of helpful answers — to answer questions directly, to follow instructions, to say when it does not know. Fine-tuning uses far less data than pretraining, but the data is far more carefully chosen, because it is teaching the model how to behave, not just how language works.

Alignment goes further. The builders want the model to refuse harmful requests, to avoid making things up when it can, and to behave in line with human values. One widely used method is reinforcement learning from human feedback, or RLHF: people rank several of the model's answers, a reward model learns what people prefer, and the language model is then trained to earn higher rewards. The result is a model that is polite, cautious and helpful — and also one whose behaviour reflects the judgements of the people who ranked its answers, for better and worse. You will study RLHF in detail in Lesson 7.

Why so few organisations train large models

Pretraining a large language model is one of the most expensive things in computing. It needs thousands of specialised processors running for weeks or months, enormous amounts of electricity, and teams of engineers to keep the training stable — a single crash can waste days of work. The cost is why only a small number of organisations build the largest models from scratch, while schools, small companies and individual developers use those models through an API, or adapt smaller openly available ones by fine-tuning them for a particular job. That division of labour shapes the whole field: a few builders, and very many adapters and users. For a student, the practical consequence is encouraging: you do not need to train a model to do useful work with one. Fine-tuning a small model, or simply prompting and retrieving well, is within reach of anyone — and it is where most of the real applications are built.

Two things are worth remembering about training. First, it is enormously expensive in computing power, which is why only a small number of organisations build the largest models, while everyone else uses or adapts them. Second, the model cannot learn what is not in its data: it reflects the text it was trained on, including its biases, its errors and its gaps. A model trained mostly on text from one part of the world will know that part best. Training explains both the power and the limits of everything that follows in this course.

Key Terms

Pretraining
The first, longest stage of training, where a model learns the patterns of language by predicting the next token across enormous amounts of text.
Fine-tuning
Further training on carefully chosen examples of wanted behaviour, such as instruction-and-answer pairs, to teach a model to be useful.
Alignment
Steering a trained model towards being helpful, honest and safe, in line with human values.
Reinforcement learning from human feedback (RLHF)
A method where people rank a model's answers, a reward model learns those preferences, and the model is trained to earn higher rewards.
Reward model
A model trained to predict how much people will like an answer, used to guide RLHF training.
Instruction
A prompt that tells the model what to do, such as 'summarise this article in three points'.

Discussion Questions

  1. After pretraining only, a model asked a question might reply with another question. Why would it do that, and what is missing?
  2. Fine-tuning data is small but carefully chosen, while pretraining data is huge but unfiltered. Why does that difference make sense?
  3. RLHF teaches a model what people prefer. Whose preferences count, and what could go wrong if the ranking is done badly?

Practice Questions

  1. What are the three stages of building a language model?
  2. What is the model trained to do during pretraining?
  3. Why is a pretrained-only model not a good assistant?
  4. What does fine-tuning add that pretraining does not?
  5. What is RLHF, in one sentence?
Show answers
  1. Pretraining, fine-tuning and alignment. Pretraining teaches language, fine-tuning teaches usefulness, alignment steers behaviour towards helpfulness and safety.
  2. Predict the next token, billions of times, across enormous amounts of text. That single task teaches it the patterns of language itself.
  3. It has learned to continue text, not to answer questions helpfully. Asked a question, it might continue with another question as if writing a quiz.
  4. Examples of wanted behaviour, such as instruction-and-answer pairs. It teaches the model the shape of helpful answers: direct, following instructions, admitting when it does not know.
  5. People rank the model's answers, a reward model learns those preferences, and the model is trained to earn higher rewards. It is one of the main ways models are aligned to be helpful, honest and safe.
Keep reading to complete this lesson