Rudy Lai

Notes on using examples in prompts (X-shot prompting)

2024-09-27

There are different approaches for providing instructions or examples to a model to perform a task. In particular, one method is to give the LLM some examples. As usual, the terminology is complex, but the ideas are simple.

Let's break down each one and compare them:

Zero-shot Prompting

Zero-shot prompting is when a model is asked to perform a task without being given any examples. Instead, the task is described using only the natural language prompt, and the model has to rely solely on its pre-trained knowledge.

Example prompt for zero shot

Translate the following sentence to French: 'I am happy' → 'Je suis content.'

One-shot Prompting

In one-shot prompting, the model is provided with a single example along with the prompt to help it understand the task better. This can help the model generate more relevant responses by learning from that one instance.

Example prompt for one shot

Translate the following sentence to French: 'I am happy' → 'Je suis content.'
Now translate this sentence: 'I am hungry.'

Few-shot Prompting

Few-shot prompting involves providing the model with a small number (typically 2–5) of task-specific examples before asking it to perform the task. This approach helps the model better understand the structure or context required.

Example prompt for few shots

Translate the following sentence to French: 'I am happy' → 'Je suis content.'
Translate the following sentence to French: 'She is tall' → 'Elle est grande.'
Now translate this sentence: 'I am hungry.'

How they compare

AspectZero-shot PromptingOne-shot PromptingFew-shot Prompting
Number of ExamplesNoneOneA few (usually 2–5)
Task UnderstandingRelies entirely on the model's pre-trained knowledge and inferenceHas minimal help from a single exampleGains better understanding with multiple examples
Model GeneralizationRequires strong generalization ability since no specific task info is providedSlightly easier for the model since it sees an exampleMore guidance is provided, improving performance on the task
Ease for ModelHarder for the model to perform well since no guidance is givenEasier than zero-shot, but still somewhat challengingEasiest among the three; the model has better context from examples
Potential ErrorsMore prone to errors or confusion due to lack of task clarityCan still misunderstand if the task is complexFewer errors, as multiple examples help disambiguate the task
Use CaseUseful when there are no available examples or when testing model's generalized capabilitiesBest when limited task-specific data is availableEffective when a few high-quality examples can be provided
← Back to articles