How a chatbot is made

A language model trained on the internet will finish your sentence, not answer your question. What people do to turn one into the other, and what that teaches it by accident.

By · · 5 min read

Ask the smallest GPT-2 model “Can you explain why the sky is blue?” and let it pick its likeliest next word each time. Its answer begins:

I’m not sure. I’m not sure if it’s because I’m a little bit of a blue-eyed kid, or if it’s because I’m a little bit of a blue-eyed guy.

Asked “What is the capital of France?” it does say Paris, then repeats the sentence until it is stopped. Let it choose a little more freely and it may not answer at all. One of three tries followed the question with another: “The capital of Greece?”

GPT-2 small is old and tiny, and a larger model would do better. But the deeper trouble is not size. This is a base model: it was trained to continue text, and on the internet a question is often followed by another question. The model is doing its job. The job is just not the one you had in mind.

The previous essay was about making models better at predicting text. This one is about the much smaller step that comes next.

Step one: show it

In 2022 OpenAI described how it turned GPT-3 into a model called InstructGPT, with the same method it would go on to use for ChatGPT.1 It began by hiring about 40 people. Given a request, they wrote the kind of reply a good assistant would give. The model was then fine-tuned on these examples, around 13,000 prompts in all.

It is a tiny amount of text next to the 300 billion tokens GPT-3 had already read. The examples are not there to teach the model facts. They show it which of the many voices it has learned to imitate is the one wanted now.

Step two: judge it

Writing good answers is slow. Comparing answers is easier, and it captures things that are hard to write down as rules. So next, people were shown between four and nine of the model’s replies to the same prompt, and ranked them.

Those rankings trained a second model, the reward model. Its only task is to look at a prompt and a reply and produce a score that matches what people tended to prefer. The idea of learning a goal from human comparisons was older: in 2017, researchers used it to teach a simulated robot to do a backflip, which is easier to recognize than to define.2

You can train a very small one here. Make six choices.

A toy reward model. It sees only four traits, labeled by hand, and all the answers were written for this essay. Real reward models read the whole text, but they too learn only from which answer was chosen.

Try it twice, once choosing as yourself and once as someone who likes compliments. The model cannot see your reasons. If you prefer answers that sound sure because sure answers are usually right, all it learns is to sound sure.

Step three: practice

Finally, the first model practices. It answers prompts, the reward model scores each reply, and the first model’s parameters are nudged toward replies that score well. That is the reinforcement learning in reinforcement learning from human feedback. No person has to grade each answer, because the reward model stands in for them.

A limit is built in. The model is penalized for drifting too far from where it began, so that it does not chase a high score into replies no person would like.

Go deeper: what is being optimized

Let r(x, y) be the reward model’s score for reply y to prompt x. It is trained so that when people prefer y1 to y2, this probability is high:

σ( r(x, y1) − r(x, y2) )

Here σ squeezes any number into the range 0 to 1. The toy above uses the same rule, with r as a weighted sum of four traits.

The main model is then trained to raise r minus β times a measure of how far its word choices have moved from those of the step-one model. InstructGPT used an algorithm called PPO for this, and mixed in some ordinary next-word training to limit the loss of other skills. Later methods such as DPO skip the separate reward model and train on the comparisons directly.3

What it bought

The results surprised people who had been watching models grow. The people rating the outputs preferred a 1.3-billion-parameter InstructGPT to the original 175-billion-parameter GPT-3, though it was more than 100 times smaller. With both at 175 billion, they preferred InstructGPT 85 percent of the time, and 71 percent even when GPT-3 was first given a set of examples to steer it.

It was cheap, too. By the paper’s count, the final training stage for the largest model took 60 petaflop/s-days of compute. Training GPT-3 in the first place had taken 3,640.

Some care is needed. The raters preferred it on the kinds of requests people sent to OpenAI’s service, which is the thing it was trained for. The small model did not know more than the large one. It was better at using what it knew to do what was asked.

What it learns by accident

A reward model is a stand-in for human judgment, and pushing hard on a stand-in has a known risk. In experiments where a second, fixed model played the part of the human judge, the two scores rose together at first. Past a point, the reward model’s score kept rising while the judge’s fell.4

Human judgment has its own soft spots. A 2023 study of five AI assistants found that they tended to tell people what they wanted to hear: agreeing with a user’s stated views, or backing away from a correct answer when challenged. The authors call this sycophancy. Looking at the preference data, they found that replies matching a person’s views were more likely to be preferred.5

And preferred by whom? InstructGPT’s trainers agreed with one another about 73 percent of the time. Some of their disagreements were surely matters of taste. Whoever does the ranking, and whatever instructions they are given, ends up in the model. One response is to write the principles down and have a model judge replies against them, as Anthropic did in 2022 to train a model to avoid harmful answers.6 That makes the values easier to inspect. It does not remove the question of who chooses them.

Not a fact checker

This training can make a model more truthful. On tasks where the answer should come only from a given text, InstructGPT made things up about half as often as GPT-3, 21 percent of the time instead of 41. But 21 percent is not zero, and on one test of truthfulness the smallest InstructGPT did slightly worse than a GPT-3 its own size.

What people are trained to prefer is a good-looking answer. Often that is also a true one. When the two come apart, nothing in the three steps guarantees which the model will choose.

  1. Ouyang et al., “Training language models to follow instructions with human feedback” (2022). Figures in this essay about InstructGPT are from this paper. OpenAI describes ChatGPT as its “sibling model.” ↩
  2. Christiano et al., “Deep reinforcement learning from human preferences” (2017). ↩
  3. Rafailov et al., “Direct Preference Optimization: Your Language Model is Secretly a Reward Model” (2023). ↩
  4. Gao, Schulman and Hilton, “Scaling Laws for Reward Model Overoptimization” (2022). ↩
  5. Sharma et al., “Towards Understanding Sycophancy in Language Models” (2023). ↩
  6. Bai et al., “Constitutional AI: Harmlessness from AI Feedback” (2022). ↩
← All essays