Context Management 2 min read

Few-Shot Learning

Also known as: Few-Shot, In-Context Learning, k-Shot Learning

A machine learning approach where models learn to perform tasks from only a small number of examples, typically provided within the prompt or during a brief adaptation phase.

Definition

A machine learning approach where models learn to perform tasks from only a small number of examples, typically provided within the prompt or during a brief adaptation phase.

Context Management 2 min read F

Overview

Few-shot learning enables AI models to adapt to new tasks using only a handful of examples, rather than requiring thousands or millions of labeled training samples. In the context of large language models, few-shot learning typically means providing a small number of input-output examples directly in the prompt to demonstrate the desired task pattern.

Variants

Zero-Shot

The model performs a task with no examples — only a natural language description of what's needed. This works because LLMs have learned general task-solving patterns during pre-training.

One-Shot

A single example is provided to demonstrate the desired behavior. Even one example can dramatically improve performance on structured output tasks.

Few-Shot (k-Shot)

Multiple examples (typically 2-10) are provided. More examples generally improve performance but consume more of the context window.

Context Management Considerations

Few-shot learning is a direct application of context management. Each example consumes tokens from the context window, so there's a tension between providing more examples (for better task understanding) and leaving room for the actual input data. Effective few-shot implementations carefully select the most representative and informative examples, often using semantic similarity to choose examples that are most relevant to the current query.

Best Practices

  • Diverse Examples: Include examples that cover different edge cases and patterns
  • Consistent Format: Use identical formatting across all examples
  • Relevant Examples: Select examples most similar to the expected input
  • Optimal Ordering: Place the most relevant examples closest to the query