Skip to content

Few-Shot Prompting

Few-shot prompting is how you give a base model a job. You do not describe the job. You show it — two to five worked examples, formatted identically, followed by your real input in the same format. The model, doing the only thing it does, continues the pattern. Done well, the continuation is your answer.

The name counts the examples: no examples is zero-shot, one is one-shot, a handful is few-shot. This chapter runs all three against the lab's 275M and reports what actually happened, including the failures — few-shot is a real technique with real edges, and the edges are the lesson.

The pattern

Every few-shot prompt has the same skeleton:

<example input 1>
<example output 1>
<example input 2>
<example output 2>
<your real input>
<the start of the output — then stop the model>

Three details decide whether it works:

  1. Format is the contract. Every example, and your input, must look exactly alike — same labels, same punctuation, same spacing. The model is matching a pattern, not reading instructions; a wobbly pattern is a wobbly contract.
  2. You must stop it yourself. After producing your answer, the model will cheerfully invent the next example. The lab's scripts cut the output at the first newline or the next example's label. Instruct models stop because they were trained to; you are the stop condition now.
  3. The examples are the specification. Whatever varies between your examples, the model treats as free to vary. Whatever is constant, it treats as law. Choose examples that differ only in the input.

Three worked examples, honestly graded

All from transcript t03, Olmicro 275M, greedy decoding.

Question answering. Three examples in Q:/A: form, answers kept to a name or a word:

Q: What is the capital of Japan?
A: Tokyo
Q: What is the largest planet in our solar system?
A: Jupiter
Q: Who wrote the play Romeo and Juliet?
A: William Shakespeare
Q: What is the chemical symbol for gold?
A: → Au

Correct — and note the style held: two letters, no sentence, because the examples' answers were names, not sentences. The format taught both the task and the brevity.

Extraction. Pull the date out of a sentence, two examples then a real one:

Sentence: The parcel, posted on 28 October, arrived a week late.
Date: → 28 October

Correct. Extraction is few-shot's home ground: the output is copied from the input, the pattern is rigid, and there is little room to invent.

Classification. Label a headline's topic, from a label set of sport, money, science:

Headline: Council approves funding for library repairs
Topic: → sports

Wrong — and instructively wrong. The format was followed perfectly; the answer is still wrong, twice over: a council funding story fits none of the three labels well, and the model bent the nearest one out of shape ("sport" became "sports"). Two lessons. First, few-shot cannot fix a bad label set: give the model labels that cover your inputs, including an escape hatch like other if the world needs one. Second, the smaller the model, the more few-shot is format teaching rather than judgement teaching. A 275M model learned where the answer goes more reliably than which answer is right. Expect the 1.4B and 2.7B to judge better; expect the pattern, not the prompt wording, to be what improves things at every size.

And with no examples at all

The same classification, zero-shot (transcript t03):

Headline: Council approves funding for library repairs
Topic: → Library
         Date: 2013-11-01
         Summary: Council approves funding for library repairs
         Date: 201...

No examples, no pattern — so the model invented a document instead: something like a news database record, complete with a made-up date. This is the single most common beginner experience with a base model, and it is not the model failing. It is the model succeeding at its actual job — continuing text — on a prompt that gave it nothing to continue in the shape of.

Rules of thumb

  • Start with three examples. Add more only when the failures are format failures; judgement failures need a bigger model or a better task design, not a longer prompt.
  • Keep example outputs in the exact form you want returned — length, capitalisation, everything.
  • Put your real input last, and cut the output at the first sign of the next example.
  • Test on inputs you know the answer to, including awkward ones, before trusting it on inputs you don't. Chapter 6 turns that habit into an instrument.

Check: olmicro-lab/t03_few_shot.py reproduces all four results above, including the wrong classification and the zero-shot drift. Fix the label set — add local and other — and rerun: the classification exercise becomes a different, better tool without the model changing at all.