TellWorldAI World Archive
Ask中文

Home›Practice›Practice

Practice

Few-shot prompting

Few-shot prompting attaches worked examples to the prompt so the model follows them. You will write your first few-shot prompt, learn how to pick demonstrations, and know when to switch to chain-of-thought or fine-tuning.

If a model keeps mishandling classification, extraction, or formatting tasks, few-shot prompting is usually the first fix worth trying: attach a handful of worked examples to the prompt, and the model completes the real input by following their pattern. After reading this page you can write your first few-shot prompt, choose demonstrations with a few evidence-backed rules, and recognize the point where a harder technique is needed.

What few-shot prompting is

Few-shot prompting enables in-context learning: demonstrations placed in the prompt steer the model toward better performance on the task at hand [1]. The demonstrations act as a condition for the examples that follow — you show "input looks like this, output looks like this", and the model continues that pattern when handling the actual input.

The contrast is with zero-shot prompting, where the prompt contains only a task description. Large language models show impressive zero-shot abilities, but in a zero-shot setting they still perform poorly on more complex tasks [1].

Unlike fine-tuning, prompting changes no model parameters: the demonstrations live only in the context of the current call. Swapping a few examples or adjusting the format and re-running costs almost nothing, which makes few-shot prompting a cheap way to validate a task before committing to fine-tuning.

Model scale matters too. According to Touvron et al. 2023, few-shot properties begin to emerge once the model scale is sufficiently large, consistent with the scaling analysis of Kaplan et al. 2020 [1]. A very small model may fail to learn from demonstrations no matter how many you add.

Writing your first few-shot prompt

A classic example from Brown et al. (2020) asks the model to use a made-up word correctly. The prompt shows one example with the word "whatpu", then asks for a sentence using "farduddle" [1]:

“whatpu”是坦桑尼亚的一种小型毛茸茸的动物。一个使用whatpu这个词的句子的例子是:
我们在非洲旅行时看到了这些非常可爱的whatpus。
“farduddle”是指快速跳上跳下。一个使用farduddle这个词的句子的例子是:

The model responds:

当我们赢得比赛时,我们都开始庆祝跳跃。

With a single demonstration (1-shot), the model has already learned the task: put the invented word into a fluent sentence. For harder tasks, increase the number of demonstrations — 3-shot, 5-shot, 10-shot and so on [1]. Whatever language your task uses, keep the input and output format of the demonstrations identical to the real input, because the model extends that format.

Choosing demonstrations: three useful findings

Research by Min et al. (2022) summarizes how demonstrations should be built [1]:

  1. Both the label space and the distribution of the input text in the demonstrations matter, even when the labels are not correct for individual inputs.
  2. The format used in the demonstrations plays a key role; even random labels are much better than no labels at all.
  3. Selecting random labels from the true label distribution, rather than a uniform one, also helps.

A sentiment prompt with randomly assigned labels looks like this [1]:

这太棒了!// Negative
这太糟糕了!// Positive
哇,那部电影太棒了!// Positive
多么可怕的节目!//

The output:

Negative

The labels were assigned at random, yet the model still classifies "What a horrible show!" correctly as Negative. Keeping the input // label format is what carries the task. Newer GPT models proved robust even to random formats; in the prompt below, label positions and separators are inconsistent [1]:

Positive This is awesome! 
This is bad! Negative
Wow that movie was rad!
Positive
What a horrible show! --

The answer is still Negative. For classification-style tasks, format tends to matter more than label correctness. This also means you can skip checking every demonstration label for correctness: put your data into a uniform format, drop it into the prompt, and you will see quickly how the model behaves. These findings come mostly from relatively simple tasks, so verify on your own task before relying on them.

A short checklist

  1. Start with 1-shot and add examples only if needed; every extra demonstration makes the prompt longer and the call slower and more expensive.
  2. Draw demonstration inputs from the same kind of text as the real input, and use the label space your output actually needs [1].
  3. Keep the output part of every demonstration in exactly the same format, for example always ending with // label, so a program can parse the model's reply.
  4. For classification tasks, bootstrap the format with random labels, then switch to labels sampled from the true distribution [1].

What few-shot prompting cannot fix

Standard few-shot prompting is not a perfect technique and breaks down on more complex reasoning tasks [1]. Here is a zero-shot failure case:

这组数字中的奇数加起来是一个偶数:15、32、5、13、82、7、1。

A:

The model answers:

是的,这组数字中的奇数加起来是107,是一个偶数。

That answer is wrong, and delivered confidently. Adding demonstrations does not rescue it. With four worked examples, the few-shot version still answers:

答案是True。

— still incorrect for the 15, 32, 5, 13, 82, 7, 1 case [1]. One detail of this example is worth noting: the four demonstrations have mixed answers, some True and some False, so demonstrations do not need uniform answers — what matters is that every one is written in the same format. The deeper limitation is structural: demonstrations show the model the shape of the answer (True or False) but not the intermediate reasoning steps. Tasks that require decomposing the problem into steps call for a different technique [1].

When to move on

A practical order: try zero-shot first, then add examples. If 3-shot or 5-shot demonstrations still fail, the model has not learned enough for the task, and two options remain — fine-tuning the model, or moving to more advanced prompting techniques [1]. For arithmetic, commonsense, and symbolic reasoning tasks, the common next step is chain-of-thought (CoT) prompting, which has recently become popular for exactly these task types [1].

Adapted from the few-shot prompting section of DAIR.AI's *Prompt Engineering Guide*[1], released under the MIT License.

Sources

  1. 1
    少样本提示 | Prompt Engineering GuideDAIR.AI Prompt Engineering Guide (MIT)

Cite this page: Few-shot prompting. TellWorld, https://www.tellworld.net/practice/practice-prompt-few-shot. Updated 2026-11-14

Related news

View all