Few-Shot Learning & Example Selection
From the course Advanced Prompt Engineering: Master AI Communication
Few-shot prompting — providing examples in your prompt — is one of the most effective ways to control AI output quality and format. The art is in selecting the right examples.
Zero-Shot vs Few-Shot vs Many-Shot
- Zero-shot — No examples. "Classify this review as positive or negative."
- One-shot — One example. Shows the model the expected format.
- Few-shot (2-5) — Multiple examples covering different cases.
- Many-shot (5+) — More examples for complex or ambiguous tasks.
Selecting Effective Examples
Your examples should:
- Cover the range — Include easy cases AND edge cases
- Be representative — Match the distribution of real inputs
- Show the format — Demonstrate exactly the output structure you want
- Include reasoning — For complex tasks, show WHY each example has its label
Example: Sentiment Classification
"Classify customer feedback as Positive, Negative, or Mixed.
Feedback: 'The product is amazing but shipping took forever' Classification: Mixed (positive about product, negative about delivery)
Feedback: 'Worst purchase I've ever made. Total waste of money.' Classification: Negative (strong negative sentiment, no positive elements)
Feedback: 'Works exactly as described. Fast delivery too!' Classification: Positive (satisfied with both product and service)
Now classify: 'It's okay I guess. Does the job but nothing special.'"
Dynamic Few-Shot Selection
In production systems, dynamically select examples that are most similar to the current input. Use embedding similarity to find the most relevant examples from a library. This dramatically improves accuracy for diverse inputs.
Anti-Patterns to Avoid
- All positive examples — Model may be biased toward positive classifications
- Too-simple examples — Don't show the model how to handle hard cases
- Inconsistent format — Each example should follow the exact same structure
- Contradictory examples — Conflicting labels confuse the model
The Example Library Pattern
For production use:
- Build a library of 50-100 high-quality examples
- Categorize them by input type and difficulty
- For each new input, select 3-5 most relevant examples
- Include at least one edge case in every prompt
Key Takeaways
- •Few-shot prompting dramatically improves output quality and format consistency
- •Select examples that cover the full range including edge cases
- •Include reasoning in examples to help the model understand the WHY
- •Dynamic example selection based on input similarity improves accuracy
- •Build an example library for production systems with categorized, high-quality cases
Progress is kept in this browser only.