XenonStack Glossary: AI, Data and Cloud Terms Explained

Few-Shot Learning: Methods and N-Way K-Shot Guide

Written by Dr. Jagreet Kaur | 17 Mar 2023

Few-shot learning is a machine learning framework in which a model learns to make accurate predictions from a very small number of labelled examples. It is typically used for classification when suitable training data is scarce, such as object categorisation in computer vision without thousands of training images.

This page is for teams who need a model to work on a new category or task with little data. It covers what few-shot learning is, the N-way K-shot setup, the main approaches, how it differs from one-shot and zero-shot learning, and how it applies to language models and AI agents.

What is few-shot learning?

IBM describes few-shot learning as a machine learning framework in which an AI model learns to make accurate predictions from a very small number of labelled examples (IBM few-shot learning). The goal is to avoid collecting and labelling large datasets for every new class. The model leans on what it has already learned, then adapts using the few examples it is given.

What does N-way K-shot mean?

Few-shot tasks are described as N-way K-shot, where N is the number of classes and K is the number of examples provided per class. Each task has a support set, with K labelled examples per class, and a query set of new examples to classify. A 3-way 2-shot task, for example, has three classes with two examples each.

What are the main approaches to few-shot learning?

IBM groups the approaches into four families.

ApproachHow it works
Transfer learningAdapts a pre-trained model to new tasks or unseen classes, often by fine-tuning or freezing inner layers to avoid catastrophic forgetting
Data-level methodsCreate more training samples, by generating them with models such as GANs or VAEs or by augmenting existing samples
Meta-learningTrains a model across many tasks so it gets better at learning new ones, often called learning to learn
Metric-based learningLearns embeddings and a distance function to compare samples, using methods such as Siamese, matching and prototypical networks

How does few-shot differ from one-shot and zero-shot learning?

SettingLabelled examples per classNote
Few-shotA small number (K)The general framework
One-shotOne (K=1)IBM calls it a challenging variant of few-shot learning
Zero-shotNone (K=0)IBM calls it a distinct learning problem needing its own methods

How does few-shot learning apply to large language models?

The term is also used for prompting. In the paper Language Models are Few-Shot Learners, the authors report that scaling up language models greatly improves task-agnostic few-shot performance. They applied GPT-3, with 175 billion parameters, to tasks without any gradient updates or fine-tuning, with tasks and few-shot demonstrations specified purely through text interaction. This is few-shot prompting, where examples sit in the prompt, as distinct from training a model on few examples.

How does few-shot learning relate to AI agents?

Agents often face tasks with few examples, such as a new document type or a rare case. Examples in a prompt can steer behaviour without retraining, though they do not replace tests or rules about what an agent may do. Platforms such as ElixirClaw, XenonStack's AI agents computing platform, are where such agents are built and run.

What should you do first?

  1. Define the new classes or tasks and how many labelled examples you really have.
  2. Start from a strong pre-trained model before building anything custom.
  3. Choose an approach: transfer learning, data-level, meta-learning or metric-based.
  4. Test with held-out query examples that look like real inputs.
  5. Add examples or augmentation where the model confuses classes.

To map one decision your agents make, and the data and policy it depends on, book a Context Workshop. See what happens in the workshop.

Frequently asked questions

What is few-shot learning in simple terms?

It is training or adapting a model to make accurate predictions from only a handful of labelled examples.

What does N-way K-shot mean?

N is the number of classes and K is the number of examples provided per class. A 3-way 2-shot task has three classes with two examples each.

What is the difference between few-shot and zero-shot learning?

Few-shot learning provides a small number of labelled examples per class, while zero-shot learning provides none and needs its own methods.

Is few-shot prompting the same as few-shot learning?

Not exactly. Few-shot prompting places examples in the prompt of a language model without gradient updates, while few-shot learning more broadly covers training approaches on small datasets.

Which approaches are used for few-shot learning?

Transfer learning, data-level methods, meta-learning and metric-based learning.