Exercises — Zero-shot and few-shot prompting
Before we start, some ground terms and symbols we will reuse (so nothing appears unexplained):

The figure above is the map for every exercise on this page: your prompt is a string of tokens that flows left-to-right, and the answer is whatever the model judges the most likely continuation under . Shots are extra tokens you place before the query to bend that "most likely" toward the answer-shape you want. Keep it in view — Exercise 1.2 asks what in this picture changes when you add shots (the prefix , not ), and Exercise 5.1 makes that argument precise in the chain-rule notation printed inside the model box.
Level 1 — Recognition
Exercise 1.1
For each prompt, state whether it is zero-shot, one-shot, or few-shot, and give .
- (a)
Translate to French: "good morning". - (b)
dog -> chien / cat -> chat / house -> - (c)
apple -> fruit / car -> vehicle / rose -> flower / tulip ->
Recall Solution 1.1
Count the completed input -> output pairs (a pair needs both sides filled).
- (a) No completed pairs. Zero-shot, .
- (b)
dog -> chienis complete andcat -> chatis complete;house ->is the query. Two completed pairs ⇒ few-shot, . - (c) Three completed pairs (
apple,car,rose),tulip ->is the query. Few-shot, .
Rule: = number of demonstrations whose output is already filled in. The trailing dangling one is the query, not a shot.
Exercise 1.2
Which of these does a few-shot prompt change? (A) the model's weights (B) the model's output distribution for this one request (C) the model's memory after the chat closes.
Recall Solution 1.2
Only (B). Few-shot is in-context learning: the shots become part of — recall this is all the tokens before the current position, i.e. everything the model has read so far — so they reshape for this forward pass only. Point back at the top figure: you lengthened the token stream feeding the model, nothing else. (A) is false — no gradient update happens, so (the weights) is untouched. (C) is false — close the chat and the conditioning is gone (see Fine-tuning vs prompting for the alternative that does persist).
Level 2 — Application
Exercise 2.1
You are given the task "label each sentence as SPAM or HAM" and two demos:
"You won $1000!!!" -> SPAM and "Lunch at 1pm?" -> HAM.
Write a clean, parseable few-shot prompt that classifies the new sentence "Free crypto, click now".
Recall Solution 2.1
Use an instruction, consistent delimiters, and a trailing label cue so the next tokens are forced to be the answer:
Classify each message as SPAM or HAM.
Message: "You won $1000!!!"
Label: SPAM
Message: "Lunch at 1pm?"
Label: HAM
Message: "Free crypto, click now"
Label:
Expected output: SPAM.
Why each piece: the instruction pins the task; identical Message:/Label: delimiters make the model copy the format; the trailing Label: collapses the distribution onto the two-token label space SPAM, HAM.
Exercise 2.2
Convert this zero-shot prompt into a one-shot prompt that guarantees integer JSON output:
Extract the year as JSON: "Released in 1994."
Recall Solution 2.2
One demo that shows the schema (year as a bare integer, not "1994" the string):
Extract the year as JSON.
Text: "Came out in 1980." -> {"year": 1980}
Text: "Released in 1994." ->
Expected: {"year": 1994}.
Why one shot suffices: the schema ambiguity (int vs string, key name) is what pretraining can't guess from instruction alone. A single demo defines it, which is exactly the disambiguation few-shot is for.
Level 3 — Analysis
Exercise 3.1
A student's few-shot sentiment prompt keeps returning negative for everything, even clearly positive reviews. Their demos are:
"terrible" -> negative, "awful" -> negative, "worst ever" -> negative, "broke instantly" -> negative, "great!" -> positive.
Diagnose the failure and fix it.
Recall Solution 3.1
Diagnosis: the demo set is label-imbalanced — 4 negative vs 1 positive. The model reads the demos as evidence about the prior over labels and copies the majority, so its distribution is biased toward negative before it even reads the query.
Fix: balance the demos, e.g. 2 positive + 2 negative, and keep them representative:
"great!" -> positive
"loved it" -> positive
"terrible" -> negative
"broke instantly" -> negative
Now and start balanced, and the content of the query decides.
Exercise 3.2
Here is a prompt that returns chit-chat ("Sure! The sentiment is...") instead of a clean label. Find the single structural cause.
Classify sentiment.
Review: "Nice screen." Sentiment: positive
Review: "Slow and buggy."
Recall Solution 3.2
Cause: the query line is missing the trailing Sentiment: cue. Without it, the model's most-likely continuation is free prose, not the label token. Fix by adding the dangling cue:
Review: "Slow and buggy." Sentiment:
The trailing Sentiment: forces the very next tokens to be the answer, matching the demo format.
Level 4 — Synthesis
Exercise 4.1
Design a few-shot prompt for a novel label your model has never been named on: neutral-but-sarcastic. Distinguish it from plain neutral and plain negative. Use the minimum shots that disambiguate.
Recall Solution 4.1
The novelty is the label name/concept, so we need at least one shot per label that could be confused, plus the target label demonstrated on a clearly sarcastic line:
Label each review as: negative, neutral, or neutral-but-sarcastic.
Review: "It stopped working on day two."
Label: negative
Review: "It is a phone. It makes calls."
Label: neutral
Review: "Oh sure, a whole 4 hours of battery. Amazing."
Label: neutral-but-sarcastic
Review: "Wow, only crashed twice today. Incredible."
Label:
Expected: neutral-but-sarcastic.
Why this works: the third demo defines a label pretraining never named by pairing it with an unmistakably sarcastic sentence; the negative and neutral demos fence off the two nearest confusions. This is pure disambiguation — the model already could detect sarcasm, we just told it which bucket to call it.
Exercise 4.2
You must classify into 3 balanced labels and you have room for exactly 6 shots. State how many shots per label you allocate and why, then say what happens to accuracy if you were allowed 60 shots instead.
Recall Solution 4.2
Allocation: shots per label — balanced coverage so no label dominates the prior (Ex 3.1 lesson). At 60 shots: accuracy typically plateaus past a small (diminishing returns) while token cost grows ~10× and you risk the Context window limit. So going from 6 → 60 mostly buys cost, not accuracy. The 80/20 move is a few balanced, representative shots — not maximal .
Level 5 — Mastery
Exercise 5.1 (probability reasoning)
Recall the chain rule an autoregressive LM uses: . Explain, in this notation, precisely why prepending demos changes the answer, even though (the weights) is unchanged.
Recall Solution 5.1
The generated answer is . The weights are fixed, but the conditioning set changed: without demos the model conditions on query alone; with demos it conditions on D, query. Because is a conditional distribution, feeding it a longer, more informative prefix moves probability mass. The demos supply (a) the label space, (b) the output format, (c) the style — sharpening the conditional so it concentrates on the correct answer-shape. No term in was retrained; we only fed it a better .
Exercise 5.2 (token budget arithmetic)
A model has a Context window of tokens. Your instruction + query costs tokens. Each shot costs tokens, and you must reserve tokens for the model's answer. What is the maximum number of shots you can include?
Recall Solution 5.2
Budget constraint (all in tokens): Since must be a whole number of shots, . Sanity check: . Adding one more () gives — over budget.
Exercise 5.3 (cost trade-off)
Given Ex 5.2's numbers, if accuracy is at and at , and each shot bills you the same, is scaling to worth it? Reason quantitatively.
Recall Solution 5.3
Extra shots , at tokens each extra tokens per request — you pay this on every call, forever. The accuracy gain is percentage points. So you spend tokens to buy points, i.e. tokens per point — a textbook diminishing return. Unless those 2 points are mission-critical, (balanced) is the better engineering choice. This is the 80/20 principle made numeric.
Self-test recall
Number of shots symbol and meaning
input -> output demos in the prompt.A dangling final x -> with no output is
What does denote
What does denote
Fix for a prompt that returns prose instead of a label
Failure mode of 4 negative + 1 positive demos
negative.Why rarely beats much
Max shots when window=4096, fixed cost=350, 80 per shot
What changes when you add demos (in chain-rule terms)
Connections
- Zero-shot and few-shot prompting — the parent note these exercises drill.
- In-context learning — the mechanism behind every L5 answer.
- Context window — the token budget in Ex 5.2 / 5.3.
- Prompt engineering — the craft of writing the L2/L4 prompts.
- Fine-tuning vs prompting — the persistent alternative contrasted in Ex 1.2.
- Large Language Models — the next-token predictor being conditioned.