What Are Zero-Shot and Few-Shot Learning? Teaching AI by Showing Examples

What are zero-shot and few-shot learning? An explainer—based on OpenAI's GPT-3 paper—of 'in-context learning,' where you make an AI handle a new task by showing it zero or a few examples in the prompt without retraining the model, plus how it differs from fine-tuning.

What Are Zero-Shot and Few-Shot Learning? Teaching AI by Showing Examples

Show an AI like ChatGPT a few examples and say “keep going in this style,” and it will often handle the rest in the same pattern without your having to explain in detail. For instance, give it “apple → fruit, carrot → vegetable” and then ask “banana → ?”, and the AI answers “fruit.” At that moment, the AI has not been retrained. It is reading off the method on the spot from the examples shown in the prompt.

This mechanism of “teaching a task just by showing examples” is what’s called zero-shot and few-shot learning, collectively in-context learning. It is the idea underpinning prompt engineering, and it’s essential for understanding how it differs from fine-tuning. This article organizes the mechanism for non-specialists, drawing on OpenAI’s research.

Three Stages: Zero, One, or a Few Examples

In-context learning changes name depending on how many “examples” you show the AI. Japan’s @IT glossary distinguishes the three as follows 2.

  • Zero-shot: Show no examples at all; have the AI perform the task from instructions alone
  • One-shot: Show just one example
  • Few-shot: Show a small number (a few) of examples

“Shot” here means “the number of examples.” Zero-shot is “straight to the real thing,” while few-shot is like “showing two or three sample problems before the real one.”

What matters is that in every case, the AI’s own parameters (its internal weights) are not rewritten. @IT describes few-shot learning as “the ability to handle various tasks merely by suggesting a small number of examples in the context, without updating the language model’s parameters” 2. The AI temporarily picks up the method only within the given text—the context—and forgets it once that conversation ends. That is exactly why it is called “in-context learning” 2.

Why Call It “Learning”? What GPT-3 Showed

What brought this ability to wide attention was the paper OpenAI released in 2020, “Language Models are Few-Shot Learners” 1. The title itself captures the core of GPT-3, which at 175 billion parameters 1 was extraordinarily large for its time.

The paper’s claim is clear: make a language model large enough, and without task-specific additional training (fine-tuning), it becomes able to perform a task simply by being shown a few examples 1. The paper explains that this method is applied “without any gradient updates or fine-tuning, with tasks and few-shot demonstrations specified purely via text interaction with the model” 1. In practice, GPT-3 showed strong performance on many challenges, including translation, question answering, and reasoning-heavy tasks 1.

In other words, without doing the “real learning” of rewriting the model’s internals, it behaves as if it had learned on the spot—and it’s this phenomenon that we call “few-shot learning” or “in-context learning.” @IT likewise organizes it this way, noting that because larger language models can flexibly apply more diverse examples, this ability came to be called in-context learning 2.

How It Differs from Fine-Tuning

In-context learning is often compared with fine-tuning. The two are similar in that they both “get an AI to learn a specific task,” but their nature differs greatly.

Fine-tuning retrains the model itself with additional data, permanently rewriting its internal weights. Once installed, you don’t need to show examples each time, but it costs effort in data preparation and training. In-context learning, by contrast, leaves the model untouched and simply adds examples to the prompt on the spot. It is easy and instantly testable, but you must include examples in the prompt every time, and the amount you can show is bounded by the limit of the context window.

Roughly speaking, the rule of thumb is: in-context learning when you “just want to try it” or “the task changes frequently,” and fine-tuning when you “want to handle the same specialized task in large volume and with stability.” @IT also explains zero-shot as being able to “handle various tasks with the given prompt alone, without fine-tuning,” contrasting it with fine-tuning 3.

Relationship to Chain-of-Thought, and Practical Tips

In-context learning is also deeply tied to chain-of-thought (CoT). If you write “not just the answer but the intermediate thinking” into your few-shot examples, the AI imitates it and outputs a path of reasoning too, raising accuracy on complex problems. Moreover, it is known that even in zero-shot, where you show no examples at all, there is a technique called “zero-shot CoT” of adding the single line “let’s think step by step” 3.

On the practical side, there are a few tips. Don’t use too many examples, and clearly show the format you want the AI to follow (input-output pairs). The more you want to standardize the output format, the more effective few-shot examples are. Conversely, for work that a simple instruction can handle, zero-shot without bothering to prepare examples is often enough.

Note that the term “zero-shot learning” is also used in machine learning generally—such as image recognition—to mean “a method for handling unknown categories.” What we’ve explained here is the usage corresponding to in-context learning, where you show an LLM examples via the prompt.

If you want to learn systematically how to give instructions to AI, read this alongside prompt engineering; if you want to know how to remake the model itself, read it with fine-tuning, and the whole picture of the ways to tell AI “what you want done” comes into view.

Sources

  1. Language Models are Few-Shot Learners - The GPT-3 paper by Brown et al. (OpenAI), May 2020
  2. What Is Few-shot Learning? - Japanese explainer from @IT’s “AI/Machine Learning Glossary”
  3. What Is Zero-shot Learning? - Japanese explainer from @IT’s “AI/Machine Learning Glossary”

We publish the latest AI news every day.

Subscribe via RSS Get new posts the moment they go live.

Search other keywords →