Every chapter in this course has changed a model's behavior by changing its weights — gradient descent, fine-tuning, LoRA (short for Low-Rank Adaptation), all of it. What if you could change what a model does without touching a single weight, just by changing what you show it first?
A handful of demonstrated (input, output) pairs, and a new query. The query attends to the demonstrations by how close their inputs are to its own — exactly Part IV's attention mechanism — and blends their outputs accordingly. Swap the demonstrations, and the same frozen mechanism gives a different answer.
In-context learning treats the demonstrations in a prompt as an implicit, tiny training set, processed entirely within a single forward pass — no gradient step, no weight update:
- — the query input: the thing actually being asked about.
- — the input of the -th demonstration example shown in the prompt.
- — the output demonstrated alongside .
- — the model's predicted output for the query, blended from the demonstrations.
- — a similarity kernel: how close the query is to a given demonstration's input.
- — the kernel's bandwidth, controlling how fast similarity falls off with distance.
- — indices ranging over the demonstration examples in the prompt.
- Attention as kernel regression
This is a kernel-regression view of what attention over demonstrations computes: weight each example by similarity to the query, then blend their answers.
- Weights depend only on inputs, never on outputs
The weights depend only on the inputs — completely independent of what pattern the outputs happen to encode.
Both prompts share identical demonstration inputs (), so both produce the exact same attention weights for the same query. The only thing that differs is which outputs were demonstrated — and that alone flips the sign of the final answer.
Query , two different sets of demonstrations at the same three input values:
- The weights come from the inputs alone
Both prompts use against query , with bandwidth :
- Sum
- Normalized weights:
Both prompts produce weights — identical, because the kernel only ever looks at how far is from each .
- 'Double' demonstrations blend toward roughly double
With demonstrated, the weighted blend is — close to the true doubled value of , though not exact, since a weighted average can only interpolate, not perfectly extrapolate a slope.
- 'Negate' demonstrations, same weights, opposite answer
With demonstrated instead, the identical weights blend to — close to the true negated value of , and of the opposite sign entirely from the "double" case.
Find the prompt, between the two candidates, that steers the query toward a negative answer.
Nothing about the model changed between the two prompts — same weights, same attention mechanism, same query. The entire behavior change came from what was placed in the context window. That's the practical power of prompting: a frozen, already-trained model can be steered toward wildly different behaviors purely through what it's shown, which is why so much of modern LLM engineering happens at the prompt level rather than through retraining. The next chapter turns to what happens after a prompt is chosen: making that frozen model actually fast enough to serve.