In-context learning
Show that adding a few input→output examples to the prompt changes behavior with no weight updates. Explain why this follows from next-token prediction on documents that contain repeated patterns.
Builds on: Base models continue documents, Behavior is learned, not programmed
What the animation says
Learning with nothing changed?
You type a prompt: hot goes to cold. Big goes to small. Then fast goes to, and you stop. The model answers: slow. Nobody stated the task. It picked up 'opposites' from two examples. Yet the model's weights, the numbers training set, are exactly the same before and after. So where did this learning happen?
The learning lives in the prefix
It's the prompt. The model computes the chance of the next token, given everything before it: the whole prefix. That's a fixed function. With the same weights, a different prefix gives a different output. Examples are just more prefix. So this is conditioning, not training. It lasts only while the examples sit in the context window. A new call without them starts from scratch. Now swap the examples: hot goes to caliente, big goes to grande. What comes after fast?
Same model, three prompts
Rápido, at about eighty percent. Slow drops to roughly one in a hundred. Now strip the examples and leave fast, arrow, alone. Slow gets only ten percent, competing with car, food, and lane. That's a surprisal of two point three nats. Add the opposite examples back, and slow jumps to eighty-five percent. Surprisal falls to point one six. The weights and the last line are the same every time. Only the examples differ.
Why next-token training builds this
But why can a model trained only to predict the next token do this at all? Look at what it trained on. Glossaries, tables, Q and A sheets, translation lists, test files, code. Text full of repeated structure. In these documents, line seven follows the same rule as lines one to six. A model that infers the rule from the earlier lines predicts line seven far better. So training rewards exactly that skill: read the pattern, then continue it.
The objective pays for using examples
Take one document: rows that all follow one hidden rule. Call it f. Each row's loss is the surprisal of its answer, given all the rows above it. Over countless documents with different rules, lowering that loss pushes the model toward one general skill: infer the rule from the rows in front of it. Here are five rows from one document. Tap the row whose answer should cost the most, on average.
Remember
So: in-context learning is the model conditioning on the examples in its prefix. No weights change. When the examples leave the prompt, their effect leaves with them. It exists because predicting the next token, on text full of repeated patterns, rewards inferring the rule and continuing it.
The learning lives in the prefix
Why next-token training builds this
The objective pays for using examples
Same model, three prompts
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