Okay, here are 3 examples of few-shot prompts, each designed for a different type of task, along with explanations.
What is a Few-Shot Prompt?
A few-shot prompt provides the Language Model (LLM) with multiple examples (typically 2-5) of the task you want it to perform before giving it the actual input you want processed. This helps the model understand the desired format, style, tone, or specific transformation required, especially for more nuanced or less common tasks where a simple instruction (zero-shot) might be ambiguous. It leverages the model's in-context learning ability.
Example 1: Sentiment Analysis with Specific Categories
Task: Classify customer feedback into specific, predefined categories beyond just positive/negative.
Why Few-Shot? Zero-shot might just give "Positive" or "Negative." Few-shot helps define custom categories like "Suggestion" or "Bug Report" clearly.
Classify the following customer feedback into one of these categories: Positive, Negative, Suggestion, Bug Report.
---
Example 1:
Feedback: The new interface is much cleaner and easier to navigate. Great job!
Classification: Positive
---
Example 2:
Feedback: It would be really helpful if we could export the data to a CSV file.
Classification: Suggestion
---
Example 3:
Feedback: Every time I click the 'Save' button, the application freezes and I have to restart it.
Classification: Bug Report
---
Example 4:
Feedback: The checkout process is confusing and took way too long. I almost gave up.
Classification: Negative
---
Feedback: I love the dark mode option, makes it much easier on the eyes at night.
Classification:
Explanation:
Instruction: Clearly states the goal and lists the exact categories the model should use.
Examples (Shots): Provides four examples (Feedback/Classification pairs) demonstrating how different types of feedback map to the specific categories. This is crucial for differentiating between a "Negative" comment and a "Bug Report," or a "Positive" comment and a "Suggestion."
Delimiters: Uses --- and clear labels (Feedback:, Classification:) to structure the prompt and separate the examples.
Final Input: Presents the new feedback the model needs to classify, followed by the Classification: label, prompting the model to fill in the blank according to the pattern it learned from the examples.
Example 2: Extracting Structured Data (JSON Format)
Task: Extract specific pieces of information from unstructured text and format them as JSON.
Why Few-Shot? Zero-shot might guess the JSON structure, miss fields, or use inconsistent key names. Few-shot enforces the exact desired schema and handles variations in input phrasing.
Extract the product name, color, and price from the following descriptions and format the output as a JSON object.
---
Example 1:
Description: Introducing the new SkyLark Drone, available in midnight black for $499. It features a 4K camera.
JSON Output: {"product_name": "SkyLark Drone", "color": "midnight black", "price": "$499"}
---
Example 2:
Description: Get the comfy CozyKnit Sweater today! Only $59.95 in heather grey. Perfect for fall.
JSON Output: {"product_name": "CozyKnit Sweater", "color": "heather grey", "price": "$59.95"}
---
Example 3:
Description: Limited Edition AquaFlow Water Bottle (Ocean Blue). Stay hydrated for just $25.
JSON Output: {"product_name": "AquaFlow Water Bottle", "color": "Ocean Blue", "price": "$25"}
---
Description: The durable TerraGrip Boots cost $150 and come in forest green. Ready for any trail.
JSON Output:
Explanation:
Instruction: Specifies the task (extract info) and the desired output format (JSON object with specific keys).
Examples (Shots): Provides three examples showing different phrasing in the input Description: and the consistently formatted JSON Output:. This teaches the model the exact keys (product_name, color, price) and value format expected. It also shows how to handle variations like parentheses or price locations.
Delimiters: Uses --- and labels (Description:, JSON Output:) for clarity.
Final Input: Provides a new description and the JSON Output: label, cueing the model to generate the structured data following the established pattern.
Example 3: Style Transfer (Formal to Casual)
Task: Rewrite formal sentences into a more casual, conversational tone.
Why Few-Shot? "Make it casual" is vague. Zero-shot might make it too slangy, too simple, or not capture the right kind of casualness. Few-shot demonstrates the desired level and style of transformation.
Rewrite the following formal sentences into a more casual and conversational style.
---
Example 1:
Formal: Kindly ascertain the availability of the requested documentation prior to the meeting.
Casual: Hey, can you check if those documents are ready before the meeting?
---
Example 2:
Formal: We wish to express our profound gratitude for your timely assistance in this matter.
Casual: Thanks so much for helping out so quickly with this!
---
Example 3:
Formal: It is imperative that all attendees arrive punctually at the designated time.
Casual: We really need everyone to be on time.
---
Formal: Please remit the outstanding balance at your earliest convenience.
Casual:
Explanation:
Instruction: States the goal – transforming formal sentences into a casual style.
Examples (Shots): Gives three pairs (Formal: / Casual:) illustrating the specific type of transformation desired. It shows replacing formal words ("ascertain," "remit," "punctually") with simpler alternatives, using contractions, and adopting a more direct phrasing without losing the core meaning.
Delimiters: Uses --- and labels (Formal:, Casual:) to separate the inputs and outputs clearly.
Final Input: Presents the new formal sentence and the Casual: label, prompting the model to apply the learned transformation style.
No comments:
Post a Comment