What is few-shot prompting?
Few-shot prompting means adding a few worked examples to your prompt. The model picks up the pattern and answers in the same way.
What is few-shot prompting?
When you teach someone a new task, you often show two or three examples instead of explaining at length. Few-shot prompting works the same way: you put a few solved examples of the task into the prompt and the model infers the pattern. With a single example it is called one-shot; with none, zero-shot.
A model's ability to pick up a new task from examples in the prompt, without retraining, is called in-context learning. It became widely known with the GPT-3 paper in 2020, titled "Language Models are Few-Shot Learners".
An example
Task: label customer reviews as positive, negative or neutral. The prompt could look like this:
- Review: "Arrived in a day, nicely packed." Label: positive
- Review: "Smaller than in the photo." Label: negative
- Review: "Ordered it, have not used it yet." Label: neutral
- Review: "Lovely color, but it faded after the first wash." Label: ?
The model answers the last review with a one word label in the same format. Without the examples it might have written a paragraph.
When does it help?
When the output format matters (a specific JSON structure, a fixed set of labels or your brand's tone), few-shot is often the cheapest and fastest fix. Including borderline cases, like the "lovely color, but" review above, shows the model how to decide where it would otherwise hesitate.
Things to watch
Keep the examples varied; if they are all positive, the model leans positive. Models are also sensitive to the order of examples, and the last one has an outsized effect. Every example costs tokens. If you find yourself needing dozens of examples, fine-tuning may become the cheaper option.