From GPT to Production
Prompting and in-context learning
Steering a frozen model with examples
The weights are frozen - yet the model "learns" your task from a handful of examples you drop into the prompt, and reasons better when you tell it to think out loud.
After pre-training and alignment, a large language model's weights are fixed. You cannot retrain it every time you have a new task - but you don't have to. By writing a good prompt, you steer the frozen model at inference time. Show it two or three worked examples and it picks up the pattern on the spot; that is in-context learning. Ask it to "think step by step" and a problem it was botching suddenly comes out right. No gradient descent, no fine-tuning - just the right text in the context window, consumed by a single forward pass.
The one-line idea
A prompt is not a command you type at the model - it is the left half of a document the model completes. Put examples of the task in that left half and the model, trying to continue coherently, imitates the pattern. The weights never move; you changed what it is reading, not what it knows.
The prompting ladder: zero, one, few
Everything hangs on how many worked examples (called shots) you place before your real question.
- Zero-shot - just the instruction and the question. "Classify the sentiment: 'the film dragged.'" The model relies entirely on what pre-training baked in.
- One-shot - a single worked example first, so the model sees the exact input to output format you expect.
- Few-shot - several examples. Now the model has enough to infer the whole pattern, and accuracy usually climbs sharply over one-shot.
A system prompt sits above all of this - a persistent instruction ("You are a terse SQL expert; answer in one query") prepended to every turn, setting role and rules before the conversation even starts.
In-context learning: the weights never move
Call the frozen parameters . Given demonstration pairs and a new input , the model just computes a conditional probability over the next tokens and picks the most likely completion:
Why this is not training
Training changes weights: . In-context learning does none of that - . The examples enter through the input, and attention lets the tokens of your new question attend back to the demonstration tokens, copying and blending their pattern into its own representation. It all happens inside one forward pass. The "learning" is really conditioning: the same fixed function, handed a richer context, outputs a better answer.
Feel it: the prompt-builder sandbox
The task is grade-school math. Drag example cards from the bank into the context to add shots, and watch held-out accuracy climb (few-shot > one-shot > zero-shot). Then flip chain-of-thought on: the same frozen model, now shown its reasoning, jumps from mostly-wrong to mostly-right - while the token counter climbs, because every example and every reasoning step spends context-window budget.
17% on held-out - chain-of-thought OFF - prompt costs 46 tokens. Answer-only prompting learns the format but stalls on multi-step problems.
The aha: two different knobs
Examples (the drag) raise accuracy by showing the model the task and format - more shots, higher the bar, with diminishing returns. Chain-of-thought (the toggle) is a different lever: it doesn't teach the task, it gives the model room to compute. By emitting intermediate steps before the final number, a multi-step problem is broken into single steps the model can each get right. The frozen weights did both - you only changed the text they read.
Chain-of-thought: make it show its work
Ask a model "Roger has 5 balls, buys 2 cans of 3 - how many now?" and a terse model blurts a wrong number. Prepend "Let's think step by step" (or show exemplars that reason), and it writes "5 + 2×3 = 5 + 6 = 11" and lands on 11. The extra tokens are not decoration: each intermediate result is written into the context, so the next step can attend to it instead of solving everything in one leap. The cost is real - a longer prompt and a longer answer eat more of the context window - but on multi-step reasoning the accuracy gain is large, which is exactly what the chain-of-thought paper measured.
Prompts are brittle
In-context learning is sensitive to format. The order of your examples, whether labels read Positive vs positive, an extra newline, or a stray "Answer:" can swing accuracy by tens of points - because you are nudging a probability distribution, not setting a variable. Treat prompts as something to test and measure, not a spec the model is guaranteed to obey.
# The weights (theta) are frozen - this all happens at inference.
examples = [
("4 cars, each with 4 wheels. How many wheels?", "16"),
("20 apples, ate 8, bought 12. How many now?", "24"),
]
def build_prompt(query, cot=False):
shots = ""
for q, a in examples: # each pair is one "shot"
if cot:
shots += f"Q: {q}\nA: Let's think step by step. ... The answer is {a}.\n\n"
else:
shots += f"Q: {q}\nA: {a}\n\n"
tail = "A: Let's think step by step." if cot else "A:"
return f"{shots}Q: {query}\n{tail}"
answer = model.generate(build_prompt(query, cot=True)) # theta unchangedCheck yourself
During in-context learning, what actually changes in the model?
Why does 'let's think step by step' raise accuracy on hard math?
Recall: what is the difference between zero-, one-, and few-shot prompting, and what does chain-of-thought add on top - all with frozen weights?
This is the central mechanism of the lesson. Try to state it, then check.
Lock it in
- Zero-shot uses only the instruction; one-shot adds one worked example for format; few-shot adds several and accuracy climbs sharply.
- In-context learning never changes the weights - examples enter through the input and attention blends the pattern in one forward pass.
- Chain-of-thought asks the model to emit intermediate steps, trading tokens for correct multi-step reasoning.
- Prompts are brittle - order, capitalization, and newlines swing accuracy because you are nudging a distribution, not setting a variable.
Primary source
For the full menu of prompting techniques - few-shot, instruction, chain-of-thought, and their failure modes - read Lilian Weng's survey "Prompt Engineering". For the result behind the toggle in the demo - that emitting a reasoning chain sharply boosts large-model performance on arithmetic and commonsense tasks - read Wei et al., "Chain-of-Thought Prompting Elicits Reasoning in Large Language Models".
Ask your teacher
Here is the connection worth pinning down: in-context learning happens entirely in the forward pass - the frozen weights never change, so nothing is "learned" in the training sense. What lets a new token benefit from your examples is attention: the query token attends back to the demonstration tokens you placed earlier in the context and blends their pattern into its own representation. Ask me why bigger models are so much better at few-shot learning, how "zero-shot chain-of-thought" works with no examples at all, or why simply reordering the same examples can change the answer.