מתי להשתמש
"Few-shot", "One-shot", "Examples in prompt", "In-context learning".
הוראות עבודה
1. What is Few-shot
Provide examples of input → output in the prompt. AI learns the pattern.
2. Performance Boost
- Zero-shot (no examples): baseline.
- 1-shot: +10-30% accuracy on classification.
- 3-shot: +20-50% on complex tasks.
- 5-10-shot: marginal improvement after.
3. When to Use
✅ Best For
- Classification (categorize text).
- Extraction (extract structured data).
- Style matching (match brand voice).
- Format consistency (JSON output).
- Edge cases that AI might miss.
❌ Skip For
- Simple Q&A.
- Creative tasks (limits creativity).
- One-off tasks (overhead).
4. Few-shot Template
Task: Classify customer emails into categories.
Categories: billing, technical, general, complaint
Examples:
Email: "I can't login to my account, getting error 500."
Category: technical
Email: "Charged twice this month, need refund."
Category: billing
Email: "What are your business hours?"
Category: general
Email: "Service has been down for 3 days, awful experience!"
Category: complaint
Now classify:
Email: "{{actual email}}"
Category:
5. Choosing Examples
Good Examples
- Diverse — cover different cases.
- Edge cases — tricky boundaries.
- Real-world — from actual data.
- Balanced — across categories.
Bad Examples
- All same type.
- Trivial cases only.
- Made-up data unlike reality.
6. Example Count — Trade-offs
| Count | Pros | Cons |
|---|---|---|
| 1-shot | Fast, cheap | Less learning |
| 3-shot | Sweet spot | Balanced |
| 5+ shot | Best accuracy | Costly, slow |
| 10+ shot | Marginal gain | Expensive |
7. Format Matters
Consistent Format
Q: ...
A: ...
Q: ...
A: ...
Or
Input: ... → Output: ...
Or JSON
[
{"input": "...", "output": "..."},
{"input": "...", "output": "..."}
]
8. Few-shot + CoT
Combine for hard tasks:
Example:
Input: ...
Reasoning: First I notice X, then Y leads to Z.
Output: ...
Now solve:
Input: ...
Reasoning:
Output:
9. Dynamic Few-shot (RAG-like)
For production:
- Store many examples in DB.
- Retrieve most similar to current input.
- Insert as few-shot examples.
- Best of both worlds.
10. Common Mistakes
❌ Too many examples — diminishing returns + cost. ❌ Examples too similar — narrow learning. ❌ Examples contradict instructions. ❌ Bad examples — AI learns wrong patterns.
11. Cost
- Few-shot adds tokens to every call.
- Long examples × many calls = expensive.
- Prompt caching (Anthropic) — caches examples = 90% cheaper.
12. אסיים בהמלצה.
פרומפט לדוגמה
3-shot prompt for sentiment classification.
Few-shot or fine-tuning? Decision criteria.
Examples for extracting data from invoices.
© 2026 AI Expert Pro | גרסה 1.0.0