From base model to assistant
A base model only continues documents in the style of its training text. Post-training turns it into an assistant in three ways. Fine-tuning on example conversations teaches the format. Optimizing toward responses that people prefer, scored by a reward, is reinforcement learning from human feedback (RLHF). Reinforcement learning (RL) on problems with checkable answers produces 'reasoning' models. In RL the model is treated as a policy that chooses tokens and is rewarded for good outcomes. A chat is stored as a single token sequence with markers for system, user and assistant turns.
What the animation says
A base model continues documents
A model pretrained on internet text learns one skill: continue a document. Ask it how to reverse a list in Python. It may carry on like a forum thread: I tried reverse, but it gave me nothing back. Or it just adds more questions, like a quiz page. Same network, wrong job. So what turns it into an assistant that answers, follows instructions, and stops when it's done?
The chat is one token sequence
Post-training starts with fine-tuning on example chats, using the same next-token training as pretraining. First, a chat is rendered as one token sequence. Each turn gets a role header, its text, and an end marker. This loop builds the sequence and, alongside it, a mask saying which tokens are learned. The system and user turns are only context. Headers are given, not learned. Tap the two tokens the loss is computed on.
The model as a policy
When the model is used, it writes until it emits the end marker, then the serving code stops. Each token gets a probability, given everything before it. Multiply them to get the whole response's probability. That makes the model a policy: each token is an action. Fine-tuning raises the probability of a demonstration answer someone wrote. Reinforcement learning instead raises the average reward of answers the model samples itself. The reward comes from a model of human preferences, or from a checker. What does a math checker look at?
One RL step: 17 × 3
Only the final answer. Here's one step on: what is seventeen times three? The model samples four responses. They end in fifty-one, forty-one, fifty-one, and fifty-four. The checker gives one, zero, one, zero. The average is one half. The update compares each response with that average. Above it, its tokens become more likely. Below it, less likely. Tap the responses whose tokens become more likely.
Habits, and the three stages
Now repeat that over thousands of problems. Whatever habits lead to correct answers become more likely, like writing out steps or re-checking. That's how reasoning models arise. So, three stages. Fine-tuning learns from example chats someone wrote. RLHF learns from people picking the better of two answers. RL on checkable problems needs a checker for the final answer. And underneath it all, the chat is one token sequence with role markers.
Three stages of post-training
Chat as a sequence, model as a policy
One RL step on a checkable problem
Rendering a chat into one sequence
chat = [("system", "Be brief."), ("user", "2+3?"), ("assistant", "5")]
seq, train = [], []
for role, text in chat:
toks = [f"<|{role}|>"] + text.split() + ["<|end|>"]
seq += toks
# header is given; only the assistant's own tokens are learned
train += [False] + [role == "assistant"] * (len(toks) - 1)
print(" ".join(seq))
print([t for t, m in zip(seq, train) if m]) # ['5', '<|end|>']
Remember
On Bytewise this lesson comes in small steps with a check at the end, and the app brings it back right before you would forget it.
Bytewise
All courses