Prompt Engineering
Implement few-shot learning
Provide the model with a few examples of the desired output to guide it to produce responses that closely align with your expectations.
What is few-shot learning
Few-shot learning involves including a small number of input-output examples (usually between 1 to 5) within your prompt to demonstrate the task you want the model to perform. This approach helps the model understand the pattern or format you’re seeking, effectively “teaching” it how to generate the desired output without the need for extensive training data or fine-tuning.
How to implement few-shot learning
- Provide clear examples
- Separate the example from the prompt using a delimiters (For example, use lines like
---
or phrases likeExample:
to separate sections). - Keep examples concise
- Use examples that are reflective of desired outputs
Examples
Tips for effective few-shot learning
- Use relevant and high-quality examples. Accuracy matters since incorrect examples can mislead the model. Make sure examples are clear and free of errors.
- Maintain consistency in formatting. Uniform structure: Consistent formatting helps the model recognize patterns. Use the same separators or markers throughout.
- Limit the number of examples. Be mindful of the model’s context window (maximum token limit). Often, 1-3 examples are enough to guide the model effectively.
- Position examples strategically. Place examples before the main task instruction. Use phrases like “Now,” “Based on the above,” or “Your turn” to signal the shift to the new task.
Was this page helpful?