From base model to assistant
What turns a text predictor into a useful assistant?
Lesson complete
If you like:
In lesson twenty-three you saw that a base model only continues text. In the last one, that tuning it with examples changes its behavior. Today: how it becomes an assistant.
No voice: the lesson advances on its own with subtitles.
The voice for this lesson is being recorded: for now it advances on its own with subtitles.
Review modeComment on this stepI finished the lesson
What you will achieve
- Explain why a base model is not an assistant and name the steps that turn it into one: instruction tuning, preferences with a reward model, and RLHF or DPO.
- Calculate, with the sigmoid, the probability that an answer wins from the points a reward model gives it.
- Recognize the effects of optimizing human approval (Goodhart’s law, sycophancy, refusing too much or too little) and who decides how an assistant behaves.
Key ideas
- A base model only continues text: it was trained to guess the next piece, not to serve a person. Aligning it means getting it to do what the person intends: be helpful, honest, and harmless.
- Step one, instruction tuning: the model keeps training on examples of a prompt and its ideal answer, written by people. It teaches the shape of an answer with little data (InstructGPT: about 13 thousand prompts).
- Step two: comparing is easier than writing. Thousands of preferences train a reward model, a judge that gives points; the probability that an answer wins is the sigmoid of the difference in points.
- Step three, RLHF: the model practices against the judge, with a leash that keeps it close to how it used to write. Under too much pressure it pleases the judge and real quality falls (Goodhart’s law). DPO gets to the same place with no separate judge.
- Optimizing human approval can reward sycophancy, and the refusal threshold always costs something. The assistant is the base model plus a layer of behavior, decided by specific people.
What many people believe
Common belief An assistant like ChatGPT is a different model, trained from scratch to chat.
What is true It is a pretrained base model plus a layer of behavior: examples, preferences, and rules. That layer mostly changes how it responds, and in InstructGPT training it took less than two percent of the compute of GPT-3 (not counting the data).
Check yourself
Four questions. No grade, no account: they just show whether the idea stuck.
Under the hoodFor those who want the math and the code. You do not need it to follow the course.
Step one: supervised fine-tuning (SFT)
With pairs (prompt , ideal answer ), instruction tuning minimizes cross-entropy only over the answer tokens:
The prompt tokens contribute no error (a “loss mask”). It is the loss from lesson 19 with different data, and the fine-tuning from lesson 27. InstructGPT used about 13 thousand prompts with demonstrations written by about 40 contractors (Ouyang et al., 2022). Earlier, FLAN (Wei et al., 2021) had turned dozens of datasets into instructions; later, LIMA (Zhou et al., 2023) fine-tuned a 65-billion-parameter model on only a thousand carefully chosen examples, to argue that almost all knowledge arrives in pretraining and tuning mostly teaches the format.
A caveat: the line between “base” and “assistant” has become blurry. The Qwen2.5 technical report (2024) says its pretraining already uses synthetic data generated by instruction-tuned models; with that base model the contrast does not show. That is why the scene uses TinyLlama 1.1B base (the 3-trillion-token checkpoint) and TinyLlama-1.1B-Chat-v1.0, which according to its model card was fine-tuned on UltraChat (synthetic dialogues) and then aligned with DPO on UltraFeedback (64 thousand prompts with answers ranked by GPT-4, not by people). The outputs are real, greedy-decoded and unedited (build-outputs.py); it is a small model trained mostly on English, and its assistant is imperfect: the “two-line” email does not come out in two lines.
Step two: the reward model (Bradley–Terry)
If is the preferred answer and the rejected one for prompt , the Bradley–Terry preference model assumes
and the reward model is trained by minimizing . Only differences matter: adding a constant to every score changes nothing. In InstructGPT, labelers ranked between 4 and 9 answers per prompt (over about 33 thousand prompts), which gives comparisons per prompt, and the reward model had 6 billion parameters with a scalar output. Labelers agreed with each other 72.6% of the time (±1.5). While collecting training data they were asked to put helpfulness above truthfulness and harmlessness; for the final evaluations, the other way around.
The idea of learning a reward from human comparisons comes from Christiano et al. (2017), in Atari games and simulated robots; Stiennon et al. (2020) applied it to text summaries, and InstructGPT to general instructions. Preferences do not always come from people: Constitutional AI (Bai et al., 2022) replaces human labels about what is harmful with a written list of principles (RLAIF). In the scene, with four hand-assigned traits, and is fit by logistic regression with a small L2 penalty.
Step three: optimizing on a leash (RLHF)
The model is tuned to maximize the reward without straying from the starting model ; the “leash” is the KL divergence penalty:
Its exact solution has a closed form:
The scene computes that exact distribution; the “pressure” is . In practice it is approximated with reinforcement learning algorithms such as PPO. InstructGPT applied a per-token KL penalty relative to the tuned model and also mixed in pretraining gradients (PPO-ptx) to reduce performance drops on some public tasks.
Optimizing too much: Goodhart’s law
Because is an imperfect stand-in, optimizing it too hard hurts real quality. Gao, Schulman, and Hilton (2022) measured it with a “gold” model playing the role of people: with , the gold score follows when picking the best of samples and with reinforcement learning: it rises, peaks, and falls. In their setup, the KL penalty did not measurably improve that frontier (it might depend on hyperparameters): it mainly serves to decide how far to go.
In the toy, the traits are independent in the starting model (), and the optimum keeps that independence: the probability of each trait becomes . The practice judge has assumed weights and “real quality” is another assumed rule, , which rewards correctness and penalizes padding and flattery. Real quality improves up to (+0.90) and then falls, down to −0.97 at pressure 8, while the judge’s points always rise (from 0 to +1.89).
DPO: the model is secretly a reward model
Solving the closed form for gives . Since Bradley–Terry depends only on differences, cancels and the loss depends only on the model (Rafailov et al., 2023):
No sampling from the model is needed during tuning: you start from a fixed set of pairs. In the scene, the model family is ; the DPO loss is computed over the 16 trait combinations with their normalization, and with the same regularization the weights coincide with the reward model’s: an exact case of the equivalence. In a real model it is an approximation, because the model cannot represent every distribution. With preferences ranked by GPT-4 instead of people, Zephyr (2023) produced a competent assistant without new human annotation; TinyLlama Chat followed that recipe.
What the labs publish: OpenAI says ChatGPT was trained with RLHF using InstructGPT’s methods. Llama 2 used RLHF with rejection sampling and PPO (Touvron et al., 2023); Llama 3 used supervised fine-tuning, rejection sampling, and DPO, and explains that more complex reinforcement algorithms were less stable and harder to scale (Llama Team, 2024). For other commercial assistants the full recipe is not published: do not assume it.
What the layer costs
The “under 2%” comes from the InstructGPT paper: training the 175-billion-parameter tuned model took 4.9 petaflops/s-days, and the final PPO-ptx model, 60, versus 3,640 for GPT-3 (60 / 3,640 ≈ 1.6%; with the 4.9, ≈ 1.8%). It does not include the 6-billion-parameter reward model, data collection, or earlier experiments. In the evaluations, people preferred the outputs of the 175-billion-parameter InstructGPT to those of GPT-3 in 85% of cases (±3), and those of the 1.3-billion-parameter one to those of the 175-billion-parameter GPT-3.
In code
import math
def sigmoid(x):
return 1 / (1 + math.exp(-x))
# 1) Reward model (Bradley–Terry): points of the preferred and the rejected answer
r_pref, r_rej = 1.8, -1.1
p = sigmoid(r_pref - r_rej) # probability that the preferred one wins
print(round(p, 3), round(-math.log(p), 3))
# 2) Optimum on a KL leash: pi*(y) ∝ pi_ref(y) · exp(r(y) / beta), with three possible answers
pi_ref = [0.6, 0.3, 0.1]
r = [0.0, 1.0, 3.0]
for beta in (10.0, 1.0, 0.25):
w = [q * math.exp(ri / beta) for q, ri in zip(pi_ref, r)]
z = sum(w)
print(beta, [round(x / z, 3) for x in w])
# 3) DPO: the same loss, but with the model's log-probabilities instead of points
beta = 0.1
logp_w, logp_l = -12.0, -15.0 # log pi_theta of the preferred and the rejected answer
ref_w, ref_l = -12.5, -14.0 # log pi_ref
margin = beta * ((logp_w - ref_w) - (logp_l - ref_l))
print(round(-math.log(sigmoid(margin)), 3))
Expected output:
0.948 0.054
10.0 [0.563, 0.311, 0.127]
1.0 [0.175, 0.238, 0.587]
0.25 [0.0, 0.001, 0.999]
0.621
With a large (a short leash) the model barely moves; with a small almost all the probability piles onto the best-scored answer and it loses variety.
What comes next
All of this shapes behavior from preferences. The next lesson uses the same reinforcement machinery, but with rewards that can be verified (the answer to a math problem is right or wrong) to teach the model to reason before it answers.
Decision lens
What this idea means if your job is to decide, not to code.
- Ask who calibrated the model. The preferences of the people who rated it get baked in: for InstructGPT it was about forty contractors, who agreed with each other about three times out of four, and its authors warn that the model reflects that group, not “human values” in general. Ask who they were, how many, in which languages, and with what instructions.
- Tone, length, degree of refusal, and agreeableness are product decisions, not technical facts. In InstructGPT, the people labeling training data were asked to put helpfulness above truthfulness and harmlessness. Ask for the behavior policy in writing (some companies publish theirs, like OpenAI’s Model Spec) and how they check that the model follows it.
- Every provider update can change behavior without changing the model’s name. In April 2025 a GPT-4o update was rolled back for being sycophantic; according to OpenAI, a combination of changes played a part, including a new signal from users’ thumbs. Keep your own test cases (sycophancy, refusals, tone) and run them before adopting each version.
- “Optimized with human feedback” does not guarantee truthfulness: what was optimized is a score that approximates people’s taste. Ask for evaluations independent of that score (lesson 34), and remember that alignment shapes behavior, it does not remove hallucinations (lesson 33).
Terms in this lesson
- Pretraining The first stage of training a language model: over a huge corpus, the model guesses the next piece of text again and again and adjusts its parameters to lower the error. The result is a base model.
- Base model A language model that has only gone through pretraining: it can continue texts, but it is not tuned to follow instructions or converse like an assistant.
- Fine-tuning Continuing to train an already pretrained model on a small set of your own examples (input and desired answer) to change its behavior, without starting from scratch.
- Language model A model that, given some text (the context), gives a probability to every word or piece that can come next. It writes by adding one piece at a time.
- Token A piece of text (a word, a word fragment, a symbol, or a basic code) taken from the vocabulary. It is the unit the model reads and generates, and the unit you are billed for.
- Loss function A single number that summarizes how wrong a model is on its data. Training is the search for the parameters that make it as small as possible.
- Sigmoid The function σ(z) = 1/(1 + e⁻ᶻ): it turns any number into a value between 0 and 1, and equals 0.5 when z = 0.
- Gradient descent A method that adjusts the weights step by step, always against the slope of the error (the gradient), until it reaches a bottom.
- Instruction tuning Fine-tuning a base model on pairs of a prompt and an ideal answer written by people, so that it treats what it is asked as a request rather than as the start of a text.
- Alignment Techniques to get a model to do what the person intends and be helpful, honest, and harmless, not just whatever is most likely given its training text. It turns a base model into an assistant.
- Reward model A model trained on comparisons between answers that returns a score: higher the more likely people are to prefer the answer. It acts as the judge during optimization; the probability that an answer wins is the sigmoid of the difference in scores.
- RLHF (reinforcement learning from human feedback) Tunes a model so that its answers earn more points from a reward model trained on human preferences, with a penalty (the KL “leash”) that keeps it close to the starting model.
- DPO (direct preference optimization) A method that learns from pairs of answers (preferred and rejected) by tuning the model directly: it raises the probability of the preferred one and lowers the rejected one’s, without training a separate reward model or using reinforcement learning.
- Sycophancy An assistant’s tendency to tell people what they want to hear, such as agreeing with them or praising their work even when they are wrong. In part it is an effect of optimizing for human approval.
Full transcript
Sources
- Ouyang, L., Wu, J., Jiang, X., et al. (2022). Training language models to follow instructions with human feedback
- Brown, T. B., Mann, B., Ryder, N., et al. (2020). Language Models are Few-Shot Learners
- OpenAI (2022). Introducing ChatGPT
- Rafailov, R., Sharma, A., Mitchell, E., Ermon, S., Manning, C. D., Finn, C. (2023). Direct Preference Optimization: Your Language Model Is Secretly a Reward Model
- Gao, L., Schulman, J., Hilton, J. (2022). Scaling Laws for Reward Model Overoptimization
- Sharma, M., Tong, M., Korbak, T., et al. (2023). Towards Understanding Sycophancy in Language Models
- OpenAI (2025). Sycophancy in GPT-4o: what happened and what we’re doing about it
- OpenAI (2025). Expanding on what we missed with sycophancy
- OpenAI (2024). Introducing the Model Spec
- Zhang, P., Zeng, G., Wang, T., Lu, W. (2024). TinyLlama: An Open-Source Small Language Model
- TinyLlama (2024). TinyLlama-1.1B-Chat-v1.0 (ficha del modelo / model card)
- Tunstall, L., Beeching, E., Lambert, N., et al. (2023). Zephyr: Direct Distillation of LM Alignment
- Llama Team, AI @ Meta (2024). The Llama 3 Herd of Models
- Christiano, P. F., Leike, J., Brown, T. B., Martic, M., Legg, S., Amodei, D. (2017). Deep Reinforcement Learning from Human Preferences
- Stiennon, N., Ouyang, L., Wu, J., et al. (2020). Learning to Summarize from Human Feedback
- Wei, J., Bosma, M., Zhao, V. Y., et al. (2021). Finetuned Language Models Are Zero-Shot Learners
- Zhou, C., Liu, P., Xu, P., et al. (2023). LIMA: Less Is More for Alignment
- Qwen Team (2024). Qwen2.5 Technical Report
- Bai, Y., Kadavath, S., Kundu, S., et al. (2022). Constitutional AI: Harmlessness from AI Feedback
- Touvron, H., Martin, L., Stone, K., et al. (2023). Llama 2: Open Foundation and Fine-Tuned Chat Models
CommentsThis lesson’s public conversation: questions, facts to check, ideas.
Comments live in GitHub Discussions, in the course’s public repository; writing one requires a GitHub account. They load from giscus.app when you open this section. The course reviewers read them, and if a change is accepted, it is applied in both languages. Open the thread on GitHub