Skip to main content

Few-Shot Prompting

A way of writing instructions that shows a few example answers in the prompt to convey the form and criteria you want.

Few-shot prompting is a way of writing instructions that shows a few example answers in the prompt to convey what you want. Writing without examples is called zero-shot. The model does not need to be trained again. Showing examples conveys rules that are hard to explain in words, such as where the line between categories falls or how long answers should be. Too many examples make answers lean too closely on them, so decide the number by testing, and write examples close to your actual work in the same format. Examples also add tokens.

Instructions That Show Examples

Few-shot prompting is a way of writing instructions that shows a few example answers in the prompt to convey what you want. Writing without examples is called zero-shot. Google's guide also calls prompts with a few examples few-shot and those without examples zero-shot.

The model picks up rules of form and phrasing from the examples and applies them to new questions. The GPT-3 paper showed that as models grow larger, they become able to handle new tasks from only a few examples in the text, without being trained again.

How It Differs from Zero-Shot

Zero-shot prompting conveys the task through instruction text alone, so the answer format and fine judgment criteria drift easily. Showing examples conveys rules that are hard to explain in words. These include where the line between categories falls, how long answers should be, and habits of writing style. For example, when sorting inquiries into three types, showing one example of each type makes judgments at the boundaries more consistent.

Google's guide recommends always including examples, and says that if the examples are clear enough you can sometimes drop the instruction text. Anthropic also says examples are one of the most reliable ways to set the answer format, tone, and structure.

Number and Quality of Examples

More examples are not always better. Google says too many examples can make answers lean too closely on them, and recommends deciding the number by testing. For quality, keep the following three points.

  • Make the examples close to your actual work
  • Do not use only similar examples; include ones that are easy to get wrong
  • Write every example in the same format

Examples are part of the prompt, so each one adds tokens. Through an API, the cost and waiting time of each call also grow by that much.

Was this page helpful?

Related Terms

Related Use Cases

  • Classification and extraction There is no public evaluation of classification or extraction yet, so this is ranked by human ratings on instruction following.
  • Writing Ranked by human ratings on creative requests (such as stories and poems).