πͺ Few Shot Prompting
Abstract
This section covers few-shot prompting.
π¦ Video lecture for this chapter - Link
βοΈ Overview
Few-shot Prompting is a prompting technique which involves asking the model to do a task by giving some examples i.e., in simple terms, few-shot prompting means prompting with examples.
βοΈ How it works
Provide a few relevant examples ("shots") within the prompt along with instruction and other elements. The given examples serve as a mini-tutorial, helping the LLM to better understand the task. Moreover, the given examples act as references or samples for the desired output to be generated. By learning from these examples, the chatbot generates the output which resembles the examples in terms of format, style and content.
πΏ Example
Suppose you want to generate short product descriptions for different items on an e-commerce website. Instead of providing detailed instructions or rules for generating these descriptions, you can use few-shot prompting.
Prompt
Generate product descriptions in a playful tone.
Examples:
1.Funky headphones that rock your world!Β β‘
2.Cozy blanket that hugs you like a best friend.
Output
By providing a few examples, you're asking the LLM to generate product descriptions similar to the provided examples. The model understands the pattern and style of these descriptions and uses them as a reference to create product descriptions for the given item.
Here are some of the key points to remember while providing examples
Number of examples
-Β The optimal number of examples (shots) can vary depending on the task complexity.Β Experiment with different amounts to find what works best.Diversity
-Β Provide examples that demonstrate the range of language patterns or styles you want the LLM to apply.Clarity
-Β Ensure the examples are clear,Β concise,Β and relevant to the task at hand.
βοΈ Pros
- Improved accuracy and control over LLM outputs for specific tasks.
- Tailors responses to desired style or tone.
- Can better handle complex tasks compared to zero-shot prompting.
βοΈ Cons
- Requires crafting high-quality examples.
- Resource-intensive due to increased token usage.
- May result in bias or overfitting if the given examples are not diverse.
To summarize, few-shot prompting is a prompting technique where you provide a few illustrative examples within the prompt itself to guide the LLM towards the desired output. It's like giving the model a quick tutorial before asking it to perform a task.