The AI Handbook Open in the app →

Few-Shot Learning

Inference & Prompting · Beginner · 4 min read

What is it?

Few-shot learning is giving a model a handful of examples in the prompt so it can pick up the pattern and handle a new task without any retraining.

Explain like I'm 5

Show someone two or three worked examples and they get the gist. Few-shot does the same for a model — examples in, correct pattern out.

Why was it created?

Retraining a model for every small task is expensive. Large language models turned out to learn tasks from just a few in-prompt examples, so few-shot prompting became a fast, free alternative.

Where is it used?

  • Classification and labeling
  • Formatting output consistently
  • Style or tone matching
  • Data extraction

Why should developers care?

It's one of the quickest ways to steer a model toward the exact format and behavior you want, without fine-tuning or extra infrastructure.

How does it work?

You include several input-output examples in the prompt, then the new input. The model infers the pattern from the examples (in-context learning) and applies it to the new input — no weights change. Zero-shot uses none, one-shot uses one, few-shot uses several.

Real-world example

To classify support tickets, you show three tickets each labeled 'billing' or 'bug', then a new ticket — the model labels it in the same scheme.

Common use cases

  • Consistent output format
  • Quick classification
  • Teaching a niche pattern
  • Bootstrapping before fine-tuning

Advantages

  • No training or infrastructure needed
  • Fast to iterate
  • Strongly steers format and behavior
  • Works with any capable model

Disadvantages

  • Examples consume context window
  • Sensitive to example choice and order
  • Less reliable than fine-tuning at scale
  • Adds cost per call

When should you use it?

When you need to steer behavior or format quickly and a few examples capture the pattern.

When should you avoid it?

When you have many examples and high volume (fine-tuning is cheaper per call) or when examples won't fit the context window.

Alternatives

Zero-shot promptingFine-tuningRetrieval-augmented generation (RAG)

Related terms

Prompt EngineeringLarge Language ModelFine TuningContext Window

Interview questions

Beginner

  • What is the difference between zero-shot and few-shot?
  • Where do the examples go in few-shot learning?

Intermediate

  • Why can example order affect results?
  • When is fine-tuning better than few-shot?

Senior

  • How does in-context learning differ from gradient-based learning?
  • How would you select examples for a few-shot prompt at scale?

Common misconceptions

  • "Few-shot updates the model" — nothing is trained; it's all in the prompt.
  • "More examples always help" — they cost context and can even hurt if poorly chosen.

Fun facts

  • GPT-3's paper was literally titled 'Language Models are Few-Shot Learners'.
  • The examples are sometimes called 'shots'.

Timeline

  • 2020 — GPT-3 demonstrates strong few-shot in-context learning
  • 2020s — Few-shot prompting becomes everyday practice

Learning resources

Quick summary

Few-shot learning puts a few examples in the prompt so a model infers the pattern and handles a new task with no retraining.

Cheat sheet

  • Examples in the prompt, no training
  • Zero/one/few = 0/1/several examples
  • Great for format and classification
  • Costs context; order matters

If you remember only one thing

Show a model a few examples in the prompt and it learns the task on the spot — no training required.

Further reading