Q1. What is few-shot prompting?
Few-shot prompting means providing the model with several input-output examples before asking it to perform the task on a new input.
Examples are typically presented as a sequence of exchanges or as pairs.
Example:
Few-shot helps the model learn the pattern, especially for unusual tasks or specific output formats.
Examples are typically presented as a sequence of exchanges or as pairs.
Example:
Input: I loved this movie! → Positive
Input: It was okay. → Neutral
Input: Terrible waste of time. → Negative
Now classify: The acting was superb but the plot was dull. →Few-shot helps the model learn the pattern, especially for unusual tasks or specific output formats.
Q2. How many examples are typically needed for effective few-shot prompting?
There is no fixed number, but research suggests 3–8 examples often work well.
Too few (1–2) may not demonstrate enough variation; the model might overfit to those examples.
Too many (10+) can increase token cost and context length, and may not add much benefit.
The optimal number depends on:
• Task complexity – complex tasks need more examples
• Output variety – if many possible outputs, provide diverse examples
• Model capability – stronger models need fewer examples
Start with 3 examples, test, and adjust up or down.
Too few (1–2) may not demonstrate enough variation; the model might overfit to those examples.
Too many (10+) can increase token cost and context length, and may not add much benefit.
The optimal number depends on:
• Task complexity – complex tasks need more examples
• Output variety – if many possible outputs, provide diverse examples
• Model capability – stronger models need fewer examples
Start with 3 examples, test, and adjust up or down.
Q3. What are the best practices for selecting examples in few-shot prompting?
Best practices include:
• Choose diverse examples that cover edge cases and different output possibilities
• Make sure the examples are correct and consistent
• Order examples logically (e.g., from simple to complex)
• Use the same format for all input-output pairs
• Include examples that show the desired output format precisely (e.g., exact punctuation, spacing)
• If the task has categories, include at least one example per category
• Avoid examples that are too similar; they may not teach the model the full range
• Choose diverse examples that cover edge cases and different output possibilities
• Make sure the examples are correct and consistent
• Order examples logically (e.g., from simple to complex)
• Use the same format for all input-output pairs
• Include examples that show the desired output format precisely (e.g., exact punctuation, spacing)
• If the task has categories, include at least one example per category
• Avoid examples that are too similar; they may not teach the model the full range
Q4. How does few-shot prompting differ from fine-tuning?
Few-shot prompting:
• Requires no training – works at inference time
• Examples are included in the prompt itself (tokens cost)
• Not permanent; you can change examples quickly
• Works best for pattern recognition and formatting
Fine-tuning:
• Requires training the model on a dataset (offline)
• Changes the model's internal weights permanently (for that version)
• More expensive but can achieve higher accuracy for specialized domains
• Useful when the same pattern repeats millions of times
Use few-shot for rapid prototyping; fine-tune when you need production reliability and lower token costs.
• Requires no training – works at inference time
• Examples are included in the prompt itself (tokens cost)
• Not permanent; you can change examples quickly
• Works best for pattern recognition and formatting
Fine-tuning:
• Requires training the model on a dataset (offline)
• Changes the model's internal weights permanently (for that version)
• More expensive but can achieve higher accuracy for specialized domains
• Useful when the same pattern repeats millions of times
Use few-shot for rapid prototyping; fine-tune when you need production reliability and lower token costs.
Q5. Give a scenario where few-shot prompting is essential over zero-shot.
Scenario: You need the LLM to extract structured data from emails into a custom JSON schema that the model has never seen before.
Zero-shot: The model might output random field names or forget required keys.
Few-shot with 2–3 examples:
Now the model learns the exact field names, data types, and date format.
Without few-shot, the output would be inconsistent.
Zero-shot: The model might output random field names or forget required keys.
Few-shot with 2–3 examples:
Example 1:
Email: "Order #A123, amount $45.99, date Jan 10"
Output: {"orderId": "A123, "amount": 45.99, "date": "2025-01-10"}
Example 2: ...Now the model learns the exact field names, data types, and date format.
Without few-shot, the output would be inconsistent.
