Preview

As generative AI technology advances, leveraging AI models like ChatGPT is no longer optional—it’s essential.

With OpenAI’s recent release of GPT-4.5, capable of real-time communication and emotional interaction, interest in prompt engineering—the art of optimizing prompts for AI—has surged.

Following our previous post on Zero-Shot Prompting, let’s now dive into Few-Shot Prompting.


What is Few-Shot Prompting?

In AI learning, a shot refers to an example. Thus, Few-Shot means providing a few examples to guide the model.

Few-shot prompting involves presenting an AI model with a small number of examples when introducing a new task. This helps the model understand and perform the task more accurately.

Few-shot prompting typically consists of:

  • Instructions: A description of the task the model should perform.
  • Examples: Sample inputs and outputs to guide the AI’s response.
  • Input Data: Additional input that may be required for analysis (optional).

Here’s how Few-Shot Prompting works in practice.



Example 1: Translating English Sentences into Spanish

Prompt
Translate the following English sentence into Spanish.

Examples:
1. English: "How are you?"
Korean: "¿Cómo estás?"
2. English: "What is your name?"
Korean: "¿Cuál es tu nombre?"

### Sentence to Translate
English: "I am learning Few-Shot prompting."
AI Response
English: "I am learning Few-Shot prompting."
Korean: "Estoy aprendiendo a utilizar el método de Few-Shot prompting."

In this example, the prompt includes two translation examples. This helps the AI properly format its response and execute the task (translating English into Korean).



Example 2: Generating a Cooking Recipe

Prompt
Based on the following recipe examples, create a new recipe using the given ingredients.

Example 1:
Ingredients: Chicken, salt, pepper, garlic
Recipe: Cut the chicken into small pieces. Season with salt and pepper. Heat oil in a pan and sauté the garlic. Once golden, add the chicken and cook until done. Serve hot.

Example 2:
Ingredients: Eggs, milk, sugar, vanilla
Recipe: Beat the eggs in a bowl and mix with milk, sugar, and vanilla. Lightly grease a pan and heat over medium. Pour the mixture in and stir gently as it cooks. Once golden, serve on a plate.

### Ingredients: Potatoes, olive oil, salt
AI Response
Recipe: Wash the potatoes thoroughly and peel them. Slice them thinly and place in a large bowl. Drizzle with olive oil and toss to coat evenly. Sprinkle with salt and mix again. Preheat the oven to 400°F (200°C). Spread the potatoes on a baking tray and bake for 20-25 minutes until golden and crispy.

In this example, the AI is given two recipe examples, allowing it to generate a response following the same format.


How Many Examples Should You Use in Few-Shot Prompting?

Generally, 2-5 examples are ideal for few-shot prompting.


Advantages of Few-Shot Prompting

Few-shot prompting enables AI models to better understand and execute tasks with minimal data.

While it requires more effort in prompt design compared to zero-shot prompting, it allows for greater control over the model’s responses.


Limitations of Few-Shot Prompting

Since few-shot prompting provides only a limited number of examples, poor-quality examples may lead the AI to generate inaccurate responses.

To ensure optimal results, it’s crucial to carefully curate consistent, high-quality examples.


Learn More