We use cookies to improve your experience and measure traffic. Cookie policy

    Scalor
    CONVINCE US →
    Glossary/Modelos & LLMs

    Few-shot Learning

    few-shot prompting

    Method of providing a few reference examples in the prompt to the AI so that it learns to perform a specific task without the need for additional training.

    What is it

    Few-shot Learning is a prompt engineering technique where we provide the language model with a small set of examples (usually between 2 to 5) before asking it to perform the final task. Instead of just telling the AI what we want it to do — which we call Zero-shot Learning — we show it how we want it to be done.

    In SMEs, this approach is the bridge between generic AI use and specialized use. Most modern AI models, such as those from OpenAI or Anthropic, are trained on billions of data points but do not know the specific details of your business, your brand's tone of voice, or the exact structure of your product catalog. Few-shot Learning allows you to "teach" these nuances instantly within a single conversation, without software development costs.

    How it works

    The logic behind Few-shot Learning is based on the pattern recognition capabilities of LLMs (Large Language Models). When we include examples in the prompt, we are using the so-called "context window" to activate specific knowledge within the model.

    The typical structure of a prompt with Few-shot Learning is:

    1. Instruction: A clear description of the task.
    2. Example 1 (Input/Output): A sample of a real case and the correct answer.
    3. Example 2 (Input/Output): Another sample to reinforce the pattern.
    4. Final Task: The new data we want to process.

    The model does not change its architecture nor is it re-trained. It simply uses the examples as a statistical guide to predict the next word more accurately, aligned with the constraints we have just defined. It is the equivalent of giving a new intern three completed invoices so they understand how to fill out the fourth.

    When to use

    This technique should be your first choice when text instruction (Zero-shot) is not enough to ensure consistency. It is particularly useful in four scenarios:

    1. Structured Data Extraction: When you need the AI to pull information from emails and put it into a specific format (e.g., JSON or CSV) to integrate with your ERP.
    2. Tone of Voice and Style: If the AI writes too robotically or enthusiastically for your company culture, providing three examples of emails written by you helps it replicate your natural style.
    3. Complex Classification: When you have categories that may be ambiguous. For example, distinguishing whether customer feedback is a "Technical Complaint" or a "Support Request" requires nuances that only practical examples define well.
    4. Limitation of Hallucinations: By seeing examples of correct answers, the AI is less likely to invent information or deviate from the intended format.

    It is a much cheaper and faster alternative to Fine-tuning, which requires thousands of examples and high computing costs.

    Common Errors

    The most frequent error is the lack of diversity in examples. If you give three examples of complaints about invoices, the AI may forget how to handle complaints about delivery delays. The examples should cover the range of situations you expect the model to encounter.

    Another error is poor formatting. If the examples are disorganized, the AI will confuse what is an instruction and what is content. Use clear labels like "Input:" and "Output:" to delimit each case.

    Finally, there is the risk of selection bias. The AI tends to give more importance to the last example provided. If the last example is very short, subsequent responses tend to be short. Try to maintain consistency in length and tone across all examples you include in the prompt.

    Practical Example for an SME

    Imagine an industrial consultancy in Aveiro that needs to analyze audit reports and extract only the critical risks in a simple format for the manager.

    Without Few-shot, the prompt would be: "Read this report and list the risks". The result would likely be a long and vague text.

    With Few-shot Learning, the prompt would be:

    "Read the report and extract the critical risks following this pattern:

    Example 1: Report: Leak detected in the secondary valve with risk of contamination. Risk: Critical - Infrastructure - Valve

    Example 2: Report: The fire extinguisher in the engine room has been expired since last month. Risk: High - Safety - Equipment

    Task: Report: The main electrical panel shows signs of constant overheating during the night shift."

    With these two examples, the AI immediately understands that it should categorize by (Level - Area - Component), maintaining the brevity that the company needs.

    Frequently Asked Questions

    Q: How many examples should I include in the prompt? A: Typically, between 2 to 5 examples are sufficient. Including too many examples consumes more tokens (which increases cost) and may end up confusing the model or reaching the context window limit.

    Q: Do I need to know how to program to use Few-shot Learning? A: No. This technique is based solely on text and logical organization. It can be applied directly in ChatGPT, Claude, or through the APIs that your IT team already uses.

    Q: Is Few-shot Learning the same as Fine-tuning? A: No. Few-shot happens "in real-time" in the request and the AI does not save this learning for the next session. Fine-tuning permanently changes the model through training, which is more complex and expensive.

    Q: Can I use negative examples (what not to do)? A: Yes. Often, including an example of a wrong answer with the note "Avoid this" helps the AI stay within the desired boundaries, although positive examples are generally more effective.

    Practical examples

    • 01Including 3 transcripts of previous meetings for the AI to learn how to make minutes in the company format.
    • 02Providing 2 examples of converting informal language to legal language before drafting a contract.
    • 03Showing 5 examples of how to classify support tickets by urgency and department.
    • 04Giving 3 examples of product descriptions in the catalog to maintain the same sales structure.

    Want to use Few-shot Learning in your company?

    30 minutes, free, no commitment. We map where it fits.

    Free AI diagnosis