Few-Shot Prompting: Teaching the Model Through Examples

Reading time: approx. 5 min

In the previous moment, we explored zero-shot prompting, where the AI model is expected to understand and perform a task solely based on your instruction. But what happens when zero-shot is not enough, for example when you need a very specific format, a certain tone, or to handle complex nuances? That is when few-shot prompting comes into play. In this moment, we dive deep into this powerful technique where you give the model one or more examples directly in your prompt to clarify how the task should be performed.


1. What is few-shot prompting?

Few-shot prompting is a technique where you include a small number (typically 1 to 5) demonstration examples directly in your prompt before you give the AI model the actual task it should solve.

  • Learning through examples: The purpose is for the model to "learn" the pattern, style, or format from the examples you provide. It then uses this information to generalize and apply it to the new task.
  • Refinement of pretraining: Few-shot prompting builds on the model's existing pretraining but adds specific guidance that helps it deliver more precise and tailored answers.

2. Concrete examples of few-shot prompting

Let us see how few-shot prompting can look in practice, with a focus on a school context:


Example: Give positive feedback on student texts Assume you want the AI to give constructive and positive feedback on student texts, even if the student's wording can be perceived as negative. A zero-shot prompt might have difficulty getting the specific tone you want.

Prompt with 2-shot examples:

You are a supportive English teacher. Give positive and constructive feedback on the following student texts, focus on highlighting something good even if the text expresses resistance or difficulty.

**Example 1**
Input: "Write positive feedback on the following student text:"
Text: "I think history is boring and I don't understand anything."
Output: "I understand that history can feel challenging sometimes, but it's really great that you are honest about how you experience it! Your ability to express your feelings is strong, and we will together find new ways to make history more interesting for you."

**Example 2**
Input: "Write positive feedback on the following student text:"
Text: "I like solving math problems, but it's hard when there are too many steps."
Output: "It's wonderful to see your enthusiasm for problem-solving! You are good at identifying challenges, and that's an important step. We can focus on breaking down problems into smaller steps to make it clearer."

**Your task**
Input: "Write positive feedback on the following student text:"
Text: "I think English is difficult and I'm not good at it."
Output:

In this example, we have given the AI two complete "Input-Output" pairs that demonstrate what type of feedback we expect. The AI should then generate an answer for the last "Input" question based on the style and tone it "learned" from the examples.


3. Advantages and disadvantages of few-shot prompting

Using few-shot prompting has clear advantages, but also some trade-offs:

AdvantagesDisadvantages
AdvantagesDisadvantages
:----------------------------:----------------------------
Gives the model clear patterns to copy for format, tone, and structure.Increases the prompt's length, which means more tokens and can affect the context window.
Higher precision and consistency for complex tasks or when a specific output format is required.Requires that you yourself create meaningful and representative examples, which takes time.
Good for beginners to understand prompt design and how AI "learns" from input.Not always scalable for tasks that require very many different variants of examples.
Can help the AI handle nuances that are difficult to describe solely with instructions.The quality of output is directly dependent on the quality of your examples.

4. Practical tips for teachers

When you implement few-shot prompting in your teaching, consider the following:

  • Choose representative examples: Make sure the examples you include clearly show the desired result. If you want variation, include examples that cover different scenarios.
  • Keep the number of examples low: Often 2-5 well-chosen examples are enough for the model to understand the pattern. Too many examples can fill the context window unnecessarily and even confuse the model.
  • Reuse and build templates: Save the effective few-shot prompts you create as templates. This saves time and ensures consistency when you or your students are to perform similar tasks in the future. A "prompt bank" can be very valuable.

5. Reflection exercise

To practice applying few-shot prompting, do the following:

  1. Create a few-shot example: Choose a chapter in your course literature (or another text). Write a prompt that asks the AI to "Write a summary of the text, formulated as a short note to parents". Then include two demonstration examples that show how such a note can look (think about tone, length, and content).
  2. Compare with zero-shot: Test the same task with a zero-shot prompt (that is, without the examples). Compare the results. Which method gave a more precise and desired note? Why?
  3. Discuss in the staff: Consider what types of tasks in your subjects where few-shot prompting would be particularly valuable. When is it worth spending time creating these examples instead of just using zero-shot? Are there situations where it is absolutely necessary?

Next moment: Prompt technique: It's about clear instructions - now that we have gone through both zero-shot and few-shot prompting, we will gather the most important principles for effective prompt formulation and discuss how you can write instructions that are as clear and effective as possible, regardless of which prompting technique you choose to use.