Course contentsShow
← Machine Learning and Deep Learning
Lesson 1832 of 3,53839. Prompt Engineering FundamentalsFree lesson

Introduction to Few-Shot Prompting

Providing example input-output pairs to demonstrate the desired task pattern and improve model performance.

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:

  1. Optional task description
  2. Example 1: input → output
  3. Example 2: input → output
  4. Example N: input → output
  5. 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.