Beginner-Friendly Topic
Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on. You've got this! 🚀
Providing Examples
Showing the AI an example of what you want is one of the most powerful ways to improve output quality. This technique is called few-shot prompting and it works because examples communicate your intent far more precisely than instructions alone.
What is Few-Shot Prompting?
Few-shot prompting means including one or more examples in your prompt to show the AI the format or style you want.
Zero-shot: no example, just an instruction.
One-shot: one example before the task.
Few-shot: two or more examples before the task.
Examples are especially useful when:
- The output format is very specific
- The style or tone is unusual
- The task is creative and hard to describe in words
Deep Learning ⊂ Machine Learning ⊂ Artificial Intelligence
Few-Shot Example
# Few-shot prompting: showing examples before the task
few_shot_prompt = """
Convert these customer reviews into one-sentence summaries.
Keep the tone neutral and factual.
Review: "I bought this laptop 3 months ago and the battery already died.
Customer service was no help at all. Very disappointed."
Summary: Customer reports battery failure within 3 months and poor customer service experience.
Review: "Amazing product! Fast delivery, beautiful packaging,
and the quality is even better than I expected. Will buy again."
Summary: Customer reports fast delivery, good packaging, and quality exceeding expectations.
Now summarize this review:
Review: "The headphones sound great but the ear cushions started falling apart
after 2 weeks of normal use. I expected better build quality at this price point."
Summary:
"""
print("Few-shot prompt sent to AI:")
print(few_shot_prompt)
print()
print("Expected AI output:")
print("Customer reports good sound quality but poor build quality with cushions deteriorating after 2 weeks.")