Few-Shot Learning with Examples
What You'll Learn
You'll learn how to teach an LLM the exact behavior you want by showing it 2-5 concrete examples in your prompt, rather than just describing what to do.
The Core Idea
After learning zero-shot prompting (asking without examples), few-shot learning is the next level up: showing the model what you want through demonstration. Instead of describing your desired format or behavior in words, you provide a handful of input-output pairs that serve as a template.
Think of it like training a new employee. Rather than saying "format customer emails professionally," you'd show them 3 examples of good customer emails. The pattern becomes instantly clear.
Why Examples Work Better Than Instructions
LLMs are pattern-matching machines. When you provide examples, you're giving the model a concrete pattern to follow rather than abstract instructions to interpret. This dramatically improves consistency and format adherence.
Structure of a few-shot prompt:
- Optional: Brief instruction or context
- Example 1: Input → Output
- Example 2: Input → Output
- Example 3: Input → Output (optional but helpful)
- Your actual input (the real task)
How Many Examples?
2-3 examples usually suffice for simple formatting tasks. 4-5 examples help with more complex or nuanced behavior. More isn't always better—it uses more tokens and can sometimes confuse the model.
When to Use Few-Shot vs Zero-Shot
Use few-shot when:
- Output format must be precise and consistent
- The task is ambiguous or has multiple valid interpretations
- Zero-shot results were inconsistent
- The pattern is easier to show than describe
Key Takeaway: Few-shot learning uses 2-5 concrete input-output examples to demonstrate the exact format and behavior you want, making the model's job easier and outputs more consistent than describing requirements in words alone.