Few Shot Prompting with Examples
In the previous lesson, we learned that shot
refers to the number of examples used by an AI model to learn or understand a specific task.
Zero Shot Prompting is a method where the AI performs a new task using only pre-trained data without additional examples.
Few Shot
Prompting involves presenting the AI with a few related examples and requesting it to perform a specific task based on those examples.
The AI derives context and optimal output formatting from the provided examples to generate appropriate responses to the input.
For instance, when analyzing review data from a shopping mall, you might construct a prompt as follows with a few examples:
Below are examples of shopping mall reviews.
Please identify the sentiment to fill in the [?].
---
'I really love this product!' : Positive
'It wasn't good. I'll never buy it again.' : Negative
'Great value for the price!' : Positive
'The delivery was way too late.' : Negative
'It wasn't as good as I expected.' : Negative
'I recommend this product' : [?]
Positive
In the above example, the AI learns from the answers to questions like I really love this product!
and It wasn't good. I'll never buy it again.
and provides an appropriate answer for the [?]
in the new question I recommend this product
.
The AI analyzes the tone and format of the provided questions and answers, then applies the analyzed results to new questions to provide consistent answers.
Thus, while Few Shot Prompting is characterized by providing diverse and detailed examples, it generally involves using 2-3 examples as implied by the name Few Shot.
How is a Prompt Constructed in Few Shot Prompting?
Few Shot Prompting is mainly composed of
-
Instruction: A statement directing the AI to perform a task
-
Examples: Examples the model can reference for generating responses
Typically, Few Shot Prompting uses 2-5 examples.
### Instruction
Based on the examples below, please translate the following sentence into a business-specific professional tone.
"""
Our company specializes in providing solutions that
enhance business efficiency through the use of cutting-edge technology.
"""
### Examples
Example 1:
- English: "As per your request, we have estimated the time required for the task as follows."
- Translation: "Following your request, we have estimated the time required for the task as follows."
Example 2:
- English: "Please send me the estimate by tomorrow."
- Translation: "Please provide the estimate by tomorrow."
Key Features of Few Shot Prompting
-
Efficient Context Learning: AI quickly learns and adapts to the prompt based on a small number of examples.
-
Cost Optimization: Saves time and cost (input token count) by using optimized inputs with just a few examples.
-
Consistent Response Generation: Responds consistently to new questions based on the provided examples.
Is Few Shot Prompting Comprised of Multiple Prompts?
Few Shot Prompting consists of one prompt that includes multiple examples, not multiple prompts.
Using the examples below, please rewrite the following sentence in a formal tone.
"""
Long time no see! How have you been?
"""
---
1.
- Informal: "Hey, are you free tonight?"
- Formal: "Hello, I am wondering if you are available this evening."
2.
- Informal: "I think that's a really good idea."
- Formal: "I believe that is an excellent idea."
The above prompt uses delimiters ---
to separate one instruction and two examples in a single prompt.
The generative AI understands the context of the prompt based on the two examples and generates formal sentences for the given informal one.
Few Shot Prompting helps AI to more accurately understand the prompt and perform tasks with just a small amount of data.
However, because only a few examples are provided, low-quality examples increase the likelihood of incorrect results produced by the AI.
Thus, when utilizing Few Shot Prompting, it's important to carefully review the consistency and quality of the examples.
Practice
Compare AI responses through various prompt examples.
Want to learn more?
Join CodeFriends Plus membership or enroll in a course to start your journey.