Few-shot Prompt
Definition
A prompting technique that extends the one-shot approach by providing multiple examples (typically 2-5) to the model before asking it to perform a similar task. This method gives the model more context and pattern recognition opportunities.
Characteristics
- Contains multiple examples (usually 2-5)
- Shows various input-output relationships
- Demonstrates pattern consistency
- Provides broader context than one-shot
- Balances guidance with context efficiency
Example
Prompt:
Classify the emotion in the following statements:
Statement: "I just got promoted at work!"
Emotion: Joy
Statement: "I can't believe I lost my keys again."
Emotion: Frustration
Statement: "The movie made me cry."
Emotion: Sadness
Now classify this statement:
Statement: "I'm so excited for the weekend!"
Emotion:
Expected Response: "Joy" or "Excitement"
Use Cases
- Complex classification tasks
- Pattern recognition
- Style transfer with variations
- Multi-faceted tasks requiring diverse examples
- Tasks with subtle distinctions
Benefits
- Higher accuracy than zero-shot and one-shot
- Shows pattern variations and edge cases
- Reduces overfitting to single examples
- Provides robust task understanding
- Better handles task complexity and nuance
Limitations
- Uses more context tokens
- Requires careful example selection
- May still miss rare edge cases
- Can be overkill for simple tasks
- Example quality and diversity critical
Best Practices
- Use diverse, representative examples
- Include edge cases when relevant
- Maintain consistent output format across examples
- Order examples logically (simple to complex)
- Ensure examples cover the task scope
- Balance positive and negative examples when applicable
Example Selection Strategy
- Cover different input types
- Show various difficulty levels
- Include common and uncommon cases
- Demonstrate consistent labeling
- Avoid contradictory examples
When to Use
- Complex or nuanced tasks
- When accuracy is critical
- Tasks with multiple valid patterns
- Classification with subtle distinctions
- When context space allows for multiple examples