What is few-shot learning?

Few-shot learning is adding a few worked input and output examples to the prompt so the model can infer the target task from them and apply it to a new input.

It differs from fine-tuning in the weights: fine-tuning retrains the model on examples and changes its weights, while in few-shot learning weights stay the same and examples only form that request's context. It is the few-example form of in-context learning.

Topic
Prompts, context, reasoning and generation
Also known as
Few-shot, few-shot prompting

How few-shot learning works

  1. A few examples of inputs and expected outputs that represent the task are added to the prompt, followed by the new input.
  2. The model applies the style, decision criteria and output format shown in the examples to the new input.
  3. Choice, order and class balance of examples affect results noticeably, so the example set is tested.
  4. Examples are resent with every request; fixed ones are kept in a prompt template.

In more detail

Classic machine learning versus few-shot prompting in language models

Classical machine learning approaches few-shot learning through meta-learning (such as MAML) or metric learning (such as Prototypical Networks), updating parameters or embedding distances across episodes. Modern LLMs instead achieve few-shot behaviour at inference time through in-context learning without parameter updates.

From few-shot to many-shot and prefix caching

With modern long-context models, teams can scale from few-shot (typically 2 to 10 examples) to many-shot in-context learning (hundreds or thousands of examples) inside a single prompt. Many-shot learning can rival supervised fine-tuning on narrow tasks, though inference memory scales with context length unless prefix caching is enabled.

Dynamic example selection

Static prompts can fail when input diversity is high; dynamic few-shot prompting uses a vector store at runtime to retrieve the k most similar labelled examples for each incoming query. This improves accuracy across heterogeneous categories while keeping prompt token counts bounded.

Commonly confused terms

TermHow it differs
Zero-shot learningZero-shot prompting gives only task instructions with no solved examples, whereas few-shot prompting supplies a handful of input-output demonstrations inside the context window.

Why few-shot learning matters for on-premises AI

It adapts a model to organisational tasks quickly without preparing large labelled datasets or training; a few well-chosen examples often improve format and consistency markedly. If real customer data is used in examples it is masked; otherwise personal data is processed again with every request. Too many examples fill the context window and raise latency and cost. If gains flatten as examples grow, fine-tuning may be more efficient.

ON-PREMISES EXAMPLE

A bank adds one masked example per category to the prompt of its in-house complaint classification assistant and compares results with a labelled test set.

Common questions

How many examples are enough?

It depends on the task and model; a few are often enough. Too many fill the context window and add cost; the right number is found by testing.

Do the examples change the model's weights?

No. They are used only within that request's context; their effect ends with the request and they are sent again each time.

Sources

In the glossary: Glossary, D to L

What does this term mean for your infrastructure?

We can work out together in a technical assessment how it maps onto your data, hardware and security requirements.

Request a technical assessment →

This site sets no cookies. Visitor numbers are counted in aggregate using a cookieless method that does not identify anyone. See the Privacy Policy for details.