Zero-Shot and Few-Shot Prompting
Understand the difference between asking the model directly versus providing examples, and learn when each approach produces better results for classification, extraction, and generation tasks.
What Is Zero-Shot Prompting?
Zero-shot prompting means asking the model to perform a task without giving it any examples of how to do it. You simply describe the task and let the model apply its pre-trained knowledge. This works well for tasks the model has seen many times during training, such as translation, summarization, or simple classification.
For example, asking the model to Classify this review as Positive or Negative is a zero-shot prompt. The model has absorbed thousands of sentiment classification examples during pre-training, so it can perform the task without being shown examples in the prompt itself.
A Simple Zero-Shot Example
Zero-shot prompts are concise and rely on the model built-in knowledge. They work best when the task is common and unambiguous. Notice that the prompt below defines the task clearly without showing any examples of correct outputs.
import openai
client = openai.OpenAI()
prompt = 'Classify the sentiment of the following customer review.\nRespond with only one word: Positive, Negative, or Neutral.\n\nReview: The delivery was fast but the packaging was damaged.\n\nSentiment:'
response = client.chat.completions.create(
model='gpt-4o-mini',
messages=[{'role': 'user', 'content': prompt}],
max_tokens=5
)
print(response.choices[0].message.content) # Expected: NegativeAll lessons in this course
- Zero-Shot and Few-Shot Prompting
- Chain-of-Thought and Step-by-Step Reasoning
- System Prompts and Persona Definition
- Prompt Iteration and Debugging