Skip to main contentSkip to navigation
LLMs & language models · F

Few-shot learning

Few-shot learning (also few-shot prompting) denotes showing a language model a few examples of the task wanted within the prompt before the actual input follows. The model derives the pattern, format and behaviour wanted from these demonstrations and carries them over to the new case. Unlike classic training, no model weights are changed; the learning happens solely in the context window at runtime. Few-shot learning is therefore a fast, data-minimising method for steering a model's output deliberately without fine-tuning.

Also known as: few-shot prompting, few-shot learning, learning from a few examples

The principle of in-context learning

Few-shot learning is a form of so-called in-context learning. Rather than adapting a model to a task by retraining it, the guidance needed is put directly into the prompt. A typical few-shot prompt contains several input-output pairs as examples, followed by the actual, as yet unanswered input. The model recognises the pattern and completes it consistently.

The term comes from the observation that large language models are remarkably good at generalising from just a few demonstrations. Where older methods needed thousands of annotated data points, a handful of well-chosen examples is often enough here to set the answer's format and style reliably.

What matters is that this learning is fleeting: it applies only to the current call and disappears afterwards. On the next prompt the model has to see the examples again. That sets few-shot learning fundamentally apart from Fine-tuning, where the learned behaviour is anchored permanently in the weights.

Zero-shot, one-shot and few-shot compared

Depending on how many examples are supplied, there are three levels. With Zero-shot prompting the model gets only the instruction, with no example. With one-shotPrompting adds exactly one example, few-shot prompting several. More examples help especially when the desired format is unusual or the task contains subtleties that are hard to describe in words.

The table below compares the three variants. As a rule of thumb: the clearer and more common the task, the more likely zero-shot suffices; the more specific the format or tone has to be, the more examples pay off. Examples do use up space in the Context window and increase the cost per request.

In practice few-shot learning is a central tool of prompt engineering. It bridges the gap between a plain instruction and a fully trained specialised model and already gives very good results on many tasks without needing your own training data or infrastructure.

A vivid example is classifying customer messages into categories such as complaint, enquiry or praise. If you show the model one or two typical messages per category together with the correct classification, it then classifies new messages considerably more accurately than if it knows only the category names without an example. That demonstration of the behaviour wanted is exactly the heart of the few-shot principle.

Zero-shot, one-shot and few-shot compared
variantExamples in the promptWhen to use
Zero-shotnoClear, common tasks with an unambiguous instruction
One-shotexactly oneWhen the desired format has to be shown by example
Few-shotseveral (e.g. 2 to 5)Special formats, tone or fine distinctions
Many-shotmany (dozens)Difficult patterns, where the context window allows

Choosing good examples

A few-shot prompt's quality stands or falls with the choice of examples. They should be representative of the real input, demonstrate the desired output format exactly and be consistent with each other. Contradictory or badly formatted examples confuse the model more than they help.

The order and variety of the examples matter too. Covering various typical cases — different input lengths or special cases for instance — makes the model generalise more robustly. In classification tasks it is advisable to show the categories that occur in balance, so the model favours no class.

Finally, the balance between value and cost has to hold. Every example consumes Tokens and thus the context window and compute budget. More examples often bring rapidly diminishing returns, so choose the smallest number with which the results are reliably right.

  1. 1State the task clearly and define the desired output format
  2. 2Put together two to five representative input-output pairs as examples
  3. 3Check examples for consistent format and a balanced set of cases
  4. 4Append the actual input and assess the result
  5. 5Reduce the number of examples step by step while quality holds

Limits and alternatives

Few-shot learning is powerful but not right for everything. Examples take up space in the context window that is then missing for the actual input. With very long inputs or many examples needed, the method hits its limits and the cost per request rises noticeably.

When the same task has to be solved at volume and always the same way, fine-tuning can be cheaper and more reliable in the long run, because the behaviour is then anchored in the model without examples. For fact-heavy tasks, in turn, combining with retrieval — deliberately feeding in knowledge — is often the better route.

In many real-world AI solutions few-shot learning is therefore combined with other techniques: a clear system prompt for the role, a few examples for the format and, where needed, retrieved context for the facts. This layering often gives the best mix of control, accuracy and effort.

Frequently asked questions

What is few-shot learning, simply explained?

Few-shot learning means giving a Language model showing a few examples of the task you want directly in the prompt before the actual input. The model recognises the pattern and solves the new task on the same scheme. Nothing is retrained; the learning happens only for that one call, within the context window.

How many examples does few-shot learning need?

There is no fixed number; two to five well-chosen examples are often enough. More important than quantity is that the examples are representative, consistently formatted and balanced. Start with a few and only raise the number while the results measurably improve.

How does few-shot differ from fine-tuning?

In few-shot learning the model weights stay unchanged; the examples work only in the current prompt and have to be supplied again on every call. In fine-tuning the model is permanently adapted with training data. Few-shot is faster and light on data, fine-tuning pays off at large, steady volume.

When should I use few-shot instead of zero-shot?

Zero-shot is often enough for clear, common tasks with an unambiguous instruction. Few-shot pays off when an unusual output format, a particular tone or fine distinctions are wanted that are hard to describe in words. Examples then demonstrate the behaviour you want more reliably than any instruction.

What are the drawbacks of few-shot learning?

Examples take up space in the context window and raise the cost per request, since they consume extra tokens. With very long inputs or many examples needed, the method hits its limits. Badly chosen or contradictory examples can also make the results worse rather than better.

Can I combine few-shot learning with other techniques?

Yes, that is in fact usual. In practice few-shot is often combined with a clear system prompt for the role and retrieval for current facts. This layering joins format control through examples with accuracy through retrieved knowledge and often gives better results than any single technique.

Put AI to work for your business?

We help you integrate artificial intelligence into your processes, your marketing and your website — strategically and securely.

Request a project

Stefan

Your contact

Stefan

I look forward to hearing about your project and finding the best solution together.