|
|
Zero-Shot, One-Shot and Few-Shot Prompting
Author: Venkata Sudhakar
Shot-based prompting refers to how many examples you include in your prompt before asking the LLM to perform a task. The term comes from machine learning, where a "shot" means one labelled training example. In prompting, instead of retraining the model, you provide examples directly in the input text to demonstrate the pattern you want the model to follow. Zero-shot prompting gives the model no examples at all - you simply state the task and rely entirely on the knowledge the model already has from pre-training. One-shot gives one example to establish the pattern. Few-shot gives two to five examples to make the pattern even clearer. Generally, more shots lead to more consistent and accurate outputs, especially for tasks with specific output formats or classification taxonomies the model has not seen before. The choice between zero, one, and few-shot depends on how specific your output requirements are. Simple tasks like translation or summarisation work well with zero-shot. Structured tasks like classification with custom labels or JSON extraction benefit greatly from a few examples. The below example shows all three approaches for the same sentiment analysis task.
It gives the following output,
Zero-shot: NEGATIVE
One-shot: NEGATIVE
Few-shot: NEGATIVE
For simpler tasks like sentiment analysis all three approaches give the right answer. The real difference shows up with complex or unusual output formats. The below example shows a case where zero-shot fails but few-shot succeeds - extracting structured data in a specific custom format.
It gives the following output,
Zero-shot output:
Name: John Smith
Company: Acme Corp
Join Date: January 15, 2023
Role: Senior Engineer
Few-shot output:
NAME=John Smith | COMPANY=Acme Corp | DATE=2023-01-15 | ROLE=Senior Engineer
The few-shot output precisely matches the required pipe-delimited format, while zero-shot produces a different structure. This demonstrates why few-shot prompting is essential whenever you need consistent, machine-parseable output formats in production applications.
|
|