Show an example: few-shot
Lesson 12 of 23 in the course “AI basics”. Free, with animations and a quiz.
Zero-shot and few-shot
Here “shot” means example. Zero-shot: you give a task with no examples, like “write a caption for this photo”. Few-shot: first 2–3 ready “input → output” examples, then a new input. The model continues text, so it spots the pattern and writes the next answer in the same style. In short: instead of describing what you want, you show it.
An example beats an explanation
Example: you sell your old clothes online and want listings in your own style. Describing the style takes ages: “short, lowercase, one joke, size and price at the end”. Easier: show two of your past listings, then add the new item: “hoodie, grey, M”. The model picks up the length, tone and order of parts on its own. Spoiler: this lands closer than a paragraph of explanations.
How to build a few-shot prompt
A prompt, meaning your request, is built in three parts. 1. A short task: “Write product descriptions like in the examples.” 2. Examples with identical labels: “Item: … Description: …”. 3. A new “Item: …” and an empty “Description:”. Identical labels matter: they show the model where the examples end and its turn begins. Rule of thumb: 2–5 examples, more is rarely needed.
It copies the mistakes too
The model copies everything it sees in the examples, including things you didn't intend. A typo or a wrong price in an example? Expect the same. Both examples about sneakers? The hoodie description will start sounding like sneakers too. All examples short? No long answer. The trap: a mistake in an example is easy to miss. So examples must be correct and varied.
Where few-shot saves you
Tone: at your café side job you need short, friendly replies to reviews. Show 2 of your own replies. Sorting: putting expenses into “food”, “transport”, “subscriptions”. Give one example for each. Templates: “question / answer” flashcards from your notes. Show 2 finished cards. Bottom line: if explaining doesn't work, show an example.
Check yourself
- What is few-shot in a prompt?
Correct answer: A few “input → output” examples before the new task. “Shot” means example. Few-shot: you show 2–5 ready pairs, and the model continues in the same style. - Both of your examples write the date wrong. What happens?
Correct answer: The model will most likely repeat the mistake. The model copies what it sees in the examples, mistakes included. So check your examples before sending. - You need to sort expenses into categories. Which examples are best?
Correct answer: Varied: food, transport, subscriptions, all correct. Varied, correct examples show the whole task. Three coffee examples teach the model to see “food” everywhere.