Introduction to Few-Shot Prompting
What you'll learn: How providing a few example input-output pairs dramatically improves a language model's ability to understand and perform tasks without any parameter updates.
The Core Idea
Zero-shot prompting asks a model to perform tasks from description alone. Few-shot prompting goes further by showing the model several concrete examples of what you want. Instead of just saying "classify sentiment," you show:
Review: "This movie was terrible." → Negative
Review: "I loved every minute!" → Positive
Review: "Best film of the year." → Positive
Now classify: "It was okay, nothing special." → ?
The model learns the pattern from your examples and applies it to new inputs.
Why Examples Matter
Think of few-shot prompting like showing a recipe to a chef instead of just describing the dish. When you provide 2-5 input-output pairs (called "shots"), you're demonstrating:
- Format expectations: How inputs and outputs should be structured
- Task pattern: The transformation rule you want applied
- Edge cases: How to handle ambiguous or unusual inputs
- Style and tone: The manner of response you prefer
The model performs in-context learning—adapting its behavior based solely on the prompt context, without updating any weights.
Building on Zero-Shot
Where zero-shot prompting relied on clear task descriptions, few-shot prompting addresses its limitations by reducing ambiguity. The examples serve as unambiguous specifications. If your zero-shot classification struggled with neutral sentiment, a few-shot example showing neutral cases resolves the confusion immediately.
Example Structure
Few-shot prompts typically follow this pattern:
- Optional task description
- Example 1: input → output
- Example 2: input → output
- Example N: input → output
- New input → (model generates output)
Key Takeaway: Few-shot prompting boosts model performance by demonstrating desired input-output patterns through concrete examples, enabling the model to infer task structure and format without fine-tuning.