Learn/Generative AI, RAG & Agents/MODULE 1: FOUNDATIONS — UNDERSTANDING AI AND LARGE LANGUAGE MODELS
Lesson 7 of 37 · 3 min read

1.6 The Training Process: Pre-training, Fine-tuning, and RLHF

How does an LLM end up being good at this? Through training, which happens in distinct stages.

Stage 1: Pre-training

This is the bulk of the work, and the most expensive.

The model is shown enormous amounts of text — typically scraped from the internet, supplemented with books, scientific papers, code, and more — and asked, over and over, billions of times:

"Given this chunk of text, what is the next token?"

At first, the model's predictions are random.

But each time it gets the prediction wrong, the training algorithm slightly adjusts its parameters to make it more likely to get it right next time.

Repeat this trillions of times across vast amounts of text, and you end up with a model that is very good at predicting the next token in arbitrary text.

This is called pre-training.

After pre-training, the model has absorbed a tremendous amount of world knowledge as a side effect of learning text patterns.

It "knows" history, science, languages, programming, jokes, recipes, and so on — not because anyone explicitly taught it, but because all of that was in the text it was trained on.

But the result is just a text completer.

If you give it the prompt "The first president of the United States was," it'll complete it correctly.

But if you ask it "What's your favorite color?" it might continue with "What's your favorite food?

What's your favorite movie?" because that's the kind of text pattern it saw — it doesn't know yet that you want an answer, not a continuation.

Stage 2: Supervised Fine-Tuning (SFT)

To turn a text completer into a helpful assistant, you fine-tune it.

You provide examples of high-quality conversations:

User: What's the capital of France?
Assistant: The capital of France is Paris.

User: Write a haiku about coffee.
Assistant: Morning ritual / Steam rises from porcelain / Mind awakens slow.

The model is trained on thousands of these examples, learning the format of a helpful assistant response.

After fine-tuning, it knows that when someone asks a question, it should answer; when someone asks for a haiku, it should produce one.

Stage 3: Reinforcement Learning from Human Feedback (RLHF)

Even after fine-tuning, a model might produce technically correct but unhelpful, rude, or unsafe responses.

To improve this, modern LLMs go through a stage called RLHF.

In RLHF:

  1. The model produces multiple responses to a prompt.
  2. Human reviewers rank the responses from best to worst.
  3. A separate model is trained to predict human preferences — basically learning to score how good a response is.
  4. The main LLM is then further trained to produce responses that score highly.

After many rounds of this, the model becomes much better at being helpful, harmless, and honest — at least in the ways the reviewers cared about.

RLHF is a major part of why modern LLMs feel polished and pleasant to use, compared to earlier raw models.

What This Means for You

Knowing about training stages helps demystify some things:

  • Why LLMs sometimes feel "preachy" or "overly cautious": That came from RLHF, which trained them to avoid certain kinds of responses.
  • Why they have a "knowledge cutoff": Their pre-training data only goes up to a certain date. They don't automatically know about anything that happened after.
  • Why fine-tuned models can differ a lot: The same base pre-trained model, fine-tuned for different purposes (general chat, coding, medical advice), behaves very differently.

Keep going with a free account

A free account saves your progress across lessons and lets you pick up where you left off.