Few-Shot Learning
Learning from examples
The Problem: Sometimes the AI doesn't understand exactly what format or style you want. How can you show it precisely what you need without lengthy explanations?
The Solution: Show, Don't Tell
Few-shot prompting means giving the AI a few examples of what you want before asking it to do the task. It's like showing a new employee sample work instead of writing a 10-page instruction manual. Unlike Zero-Shot (no examples), few-shot teaches by demonstration. For reasoning tasks, combine it with Chain-of-Thought.
Think of it like training a new employee:
- 1. Example 1: "When a customer says 'I'm angry', we respond: 'I understand your frustration...'"
- 2. Example 2: "When they say 'This is broken', we respond: 'I'm sorry to hear that...'"
- 3. Now you try: "Customer says 'I want a refund'..."
- 4. Employee learns: The pattern of empathetic, helpful responses
Where Is This Used?
- Custom Formatting: Specific output formats, styles, or structures
- Domain-Specific Tasks: When you need industry-specific language
- Classification: Teaching categories through examples
- Data Transformation: Converting data from one format to another
Fun Fact: Research shows that just 3-5 well-chosen examples often work better than 20+ random ones. Quality over quantity! The examples should cover different cases and edge scenarios.
Try It Yourself!
Use the interactive example below to see how adding examples changes the AI's output. Try adding more examples and see how the pattern recognition improves.
📚 Few-shot — a technique where we show the model several examples BEFORE the task. More examples = better format understanding!
This expresses mixed feelings with slight disappointment...
| Mode | Examples | Quality | When to use |
|---|---|---|---|
| Zero-shot | 0 | ⭐⭐ | Simple tasks |
| One-shot | 1 | ⭐⭐⭐ | Show format |
| Few-shot | 2-5 | ⭐⭐⭐⭐⭐ | Complex/unusual tasks |
Ready-to-use templates for copying. Replace {review} with your text.
Zero-shotNo examples
Classify the review as positive or negative:
"{review}"Suitable for simple tasks where the response format is clear from the instruction.
One-shotSingle example
Classify the review as positive or negative.
Example:
Review: "Great product, highly recommend!"
Answer: positive
Now classify:
Review: "{review}"
Answer:Shows the exact response format. Sufficient for tasks with a clear pattern.
Few-shot (5)Multiple examples
Classify the review as positive or negative.
Examples:
Review: "Great product!"
Answer: positive
Review: "Terrible quality, waste of money"
Answer: negative
Review: "Fast delivery, everything works"
Answer: positive
Review: "Don't recommend, disappointed with purchase"
Answer: negative
Review: "Price/quality ratio is excellent"
Answer: positive
Now classify:
Review: "{review}"
Answer:Ideal for complex tasks. Diverse examples cover more edge cases.
- Start with zero-shot, add examples only if results are imprecise
- 3-5 examples are usually enough, more = more tokens without guaranteed better quality
- Examples should be diverse and cover edge cases
- Use consistent format for all examples (Input/Output, Question/Answer, etc.)
Few-shot examples work like "calibration" — they show the model the EXACT format you expect. 3-5 diverse examples are usually enough. More examples = more tokens, but not always better quality.
Try it yourself
Interactive demo of this technique
Classify this review as positive, negative, or neutral: "The food was okay, but the service leaves much to be desired."
This is a mixed review. The customer notes both positive and negative aspects.
negative
Few-shot examples showed the model the exact answer format (one word) and established a classification standard. Without examples, the model answers "in its own way".
Create a free account to solve challenges
4 AI-verified challenges for this lesson
This lesson is part of a structured LLM course.
My Learning Path