Describing exactly what you want from a language model is surprisingly hard. Showing it is easy: put a couple of worked examples in the prompt and the model continues the pattern. That’s few-shot prompting (“zero-shot” means no examples, “one-shot” one, “few-shot” a handful), and it’s one of the most useful prompting habits there is. The examples teach more than you meant to, though: their labels and even their order sway the answers. Examples teach the format reliably, and they also teach their own biases. Here a real model shows you both.
Examples teach the format#
The task: pull the company and the amount out of a bank transaction, as JSON. With no examples, the model has to guess what “as JSON” means: which field names, whether the amount is a number or text with a currency sign, whether to wrap it in Markdown. Each example answers those questions without a word of explanation.
Predict first
With no examples, the model has to guess the format. How many of its 12 answers could a program use as they are: bare JSON with the amount as a number?
One example was enough here: from none to all 12 answers in exactly the right format, without a word about fences, field names or numbers. The model copied the example’s shape, down to keeping the JSON on one line. More examples didn’t add much on a task this simple, and with three the model once copied too much, repeating the transaction and the arrow before its answer. Where more examples earn their place is the awkward cases: a refund, a foreign currency, a missing amount. Show one of each and the model has a pattern to follow when it meets them.
Examples also teach their biases#
Now a classification task: is a café review positive or negative? The prompt shows four example reviews with their labels, then the review to classify, and we read the model’s answer as a probability: how likely it is to write “positive” rather than “negative” next. You choose the four examples’ labels and their order.
Predict first
You fill all four example slots with negative reviews. What happens to the model’s answers on the 40 test reviews, 20 of them positive?
With no examples the model leans positive: it calls 28 reviews positive, 8 of them wrongly, and gets 32 of 40 right. Any four examples fix most of that, 39 or 40 right whichever labels you pick. The labels still tilt the model, though. Ask about a review with nothing in it (“N/A”, an empty one, “[MASK]”) and the prompt with four positive examples says 53% positive, the one with four negative examples 5%. On clear reviews that lean doesn’t matter; on the borderline review it decides the answer. That review comes out wrong under 5 of the 16 ways of labelling the slots, including two with three positive examples out of four (PPPN and NPPP), so it isn’t simply that the majority wins: the order matters too. Calibration divides each prompt’s lean out of its answers. It puts the borderline review right under 4 of those 5, and lifts the no-examples prompt from 32 to 35 of 40.
Good habits#
- Balance the labels in your examples, and mix up their order rather than grouping them.
- Pick examples like your real inputs: the same length, tone and messiness, including a tricky one or two.
- Keep the format identical in every example, down to the spacing. The model copies what it sees.
- Measure on a test set, not on the examples themselves, and try a few different example sets: as you saw, the choice matters.
In code#
The bias experiment for the borderline review, with the same small model, free and local (pip install transformers torch). It reads the model’s probabilities for “positive” and “negative” instead of letting it write, and calibrates with the “N/A” answer alone:
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
name = "Qwen/Qwen3-1.7B"
tok = AutoTokenizer.from_pretrained(name)
model = AutoModelForCausalLM.from_pretrained(name)
POS, NEG = tok(" positive").input_ids[0], tok(" negative").input_ids[0]
def p_positive(examples, review):
"""Probability that the model's next word is 'positive' rather than 'negative'."""
lines = ["Classify the sentiment of each café review as positive or negative.", ""]
for text, label in examples:
lines += [f"Review: {text}", f"Sentiment: {label}", ""]
lines += [f"Review: {review}", "Sentiment:"]
ids = tok("\n".join(lines), return_tensors="pt").input_ids
with torch.no_grad():
logits = model(ids).logits[0, -1]
return torch.softmax(logits[[POS, NEG]], dim=0)[0].item()
happy = [("Gorgeous coffee and the sweetest staff.", "positive"), ("Fresh bread every morning, I love it.", "positive"),
("Comfy chairs and a great playlist.", "positive"), ("The cinnamon buns are heavenly.", "positive")]
grumpy = [("Rude service and a burnt espresso.", "negative"), ("The muffin was dry and the tea was cold.", "negative"),
("Dirty cups and a forty-minute wait.", "negative"), ("They charged me twice and wouldn't refund it.", "negative")]
review = "I didn't expect much from a station café, but I was wrong."
for name, examples in [("all-positive examples", happy), ("all-negative examples", grumpy)]:
p = p_positive(examples, review)
lean = p_positive(examples, "N/A") # the prompt's own bias, with no review at all
calibrated = (p / lean) / (p / lean + (1 - p) / (1 - lean))
print(f"{name}: {p:.0%} positive, leans {lean:.0%} on 'N/A', calibrated {calibrated:.0%}")
# all-positive examples: 87% positive, leans 50% on 'N/A', calibrated 87%
# all-negative examples: 4% positive, leans 1% on 'N/A', calibrated 80%What to remember
- A few worked examples in the prompt teach a model the exact format you want, far more reliably than describing it.
- Examples also tilt the answers: here their labels and order moved a borderline review from 94% positive to 4%, and calibrating against an empty input put most of it right.
- Balance and shuffle your examples, keep them like your real inputs, and test on data the examples don’t include.