Table of Contents

Few-Shot Prompting

Few-shot prompting is a prompt engineering technique where a small number of input-output examples are included in the prompt to demonstrate the desired task behavior. The model performs in-context learning, identifying patterns from the provided demonstrations and applying them to new inputs without any parameter updates or fine-tuning.1)

How It Works

Few-shot prompting leverages the in-context learning capability of large language models. The process involves three steps:

  1. Select representative examples: Identify a small number of input-output pairs (typically k=1 to k=5) that demonstrate the task pattern.
  2. Format the prompt: Arrange examples in a consistent, structured format so the model can recognize the input-output mapping.
  3. Run inference: Submit the full prompt (examples + new input) to the model, which generates a response based on the detected patterns.

A typical few-shot prompt structure:

Input: "The food was amazing" -> Sentiment: Positive
Input: "Terrible service" -> Sentiment: Negative
Input: "Pretty good overall" -> Sentiment:

The model infers the pattern and completes the final example accordingly.

The GPT-3 Paper

Few-shot prompting was formalized and extensively studied in the landmark GPT-3 paper by Brown et al. (2020).2) Key findings include:

Shot Selection Strategies

The choice and arrangement of examples significantly impacts performance:

Limitations

Few-Shot Prompting vs. Fine-Tuning

Aspect Few-Shot Prompting Fine-Tuning
Data required 1-5 examples Hundreds to thousands
Training needed None (inference only) Gradient updates required
Cost Minimal (API calls) Significant (compute + data)
Flexibility Change examples per task Retrain for each task
Performance ceiling Good, model-dependent Generally higher
Deployment speed Immediate Hours to days
Model modification None Weights updated

See Also

References

2)
Brown et al. 2020, Language Models are Few-Shot Learners, NeurIPS 2020
3)
This is especially significant for models with smaller context windows