Few-Shot Prompting
Few-shot prompting gives the model several examples — typically two to five — before the real task. Where one-shot shows a single demonstration, few-shot shows a pattern across multiple cases, which teaches the model not just the format but also the variety and edge cases. This is the classic form of in-context learning: the model "learns" from examples in the prompt, with no change to its weights.
💡 In one line: Few-shot prompting includes several examples so the model learns the pattern from context — improving accuracy and consistency.
What is Few-Shot Prompting?
You provide an instruction, several examples (each an input paired with its ideal output), then the real input. The model infers the pattern from the examples and applies it. Because this happens entirely within the prompt, it's called in-context learning — powerful because it needs no fine-tuning.
Why It Helps
Multiple examples do more than one:
- They pin down the format firmly.
- They show variety — different phrasings and cases.
- For classification, they can cover all the categories.
- They demonstrate edge cases a single example would miss.
The result is usually more accurate and consistent output than zero- or one-shot.
How Many "Shots"?
- 2–5 examples is a common sweet spot.
- More can help — but costs tokens and context, with diminishing returns.
- Too many (or poorly chosen ones) can even hurt.
Quality and representativeness matter more than sheer count.
When to Use Few-Shot
- Complex or nuanced tasks.
- Specific output formats (structured data, labels, styles).
- When zero-/one-shot is inconsistent.
- Classification across several categories.
Example
Classify the sentiment as POSITIVE or NEGATIVE.
Text: "The food arrived cold and late." Sentiment: NEGATIVE
Text: "I loved the new design!" Sentiment: POSITIVE
Text: "The app keeps crashing on startup." Sentiment: NEGATIVE
Text: "The battery lasts forever, I love it!" Sentiment:Three examples cover both labels, so the model reliably answers POSITIVE.
Code Example
Best Practices
- Use diverse, representative examples.
- Keep the format identical across all examples.
- For classification, balance the examples across categories.
- Note that example order can matter — experiment.
- Favour quality over quantity.
Limitations
- Uses more tokens and context than zero-/one-shot.
- Example selection strongly affects results.
- The model can overfit to superficial patterns in your examples.
Summary
- Few-shot prompting includes several examples (usually 2–5) before the task.
- It's the classic form of in-context learning — learning from the prompt, no fine-tuning.
- Multiple examples improve format, variety, coverage, and consistency.
- Use diverse, balanced, consistently formatted examples — quality over quantity.
- The trade-off is more tokens and sensitivity to which examples you pick. EOF echo "created"