Zubnet AILearnWiki › Few-Shot Learning
Using AI

Few-Shot Learning

Few-Shot Prompting, One-Shot, In-Context Learning
Providing a handful of example input-output pairs in your prompt to teach the model a pattern, format, or behavior. "Zero-shot" means no examples (just an instruction). "One-shot" is one example. "Few-shot" is typically 2–10 examples. The model learns the pattern from your examples and applies it to the actual input, without any training or fine-tuning.

Why it matters

Few-shot prompting is the fastest, cheapest way to customize model behavior. Need consistent JSON output? Show three examples. Need a specific writing style? Include two samples. It works because LLMs are extraordinary pattern matchers — they infer the rule from examples and generalize it. This is often called "in-context learning" and it's one of the most surprising capabilities to emerge from scale.

Deep Dive

The original GPT-3 paper (Brown et al., 2020) demonstrated that large language models could perform tasks they were never explicitly trained on, simply by being shown a few examples in the prompt. A model trained only to predict text could suddenly do translation, arithmetic, and classification with just 3–5 examples. This was the finding that launched the modern era of prompt engineering.

How Many Examples?

The optimal number of examples depends on the task complexity and the model. For simple formatting tasks (convert name to "Last, First"), 2–3 examples usually suffice. For nuanced classification with edge cases, 5–10 examples may be needed. Beyond ~10 examples, you're often better off fine-tuning. More examples also consume context window, so there's a practical trade-off between example quality and available space for the actual input.

Example Selection Matters

The examples you choose affect performance dramatically. Diverse examples that cover edge cases outperform repetitive ones. Examples that are similar to the target input outperform generic ones. The order of examples can matter too — models sometimes show recency bias, paying more attention to the last example. When building few-shot systems in production, dynamically selecting the most relevant examples for each input (using embedding similarity) outperforms static example sets.

Related Concepts

← All Terms
← Feedforward Network Fine-tuning →