liveBook · Manning

Few-shot learning

As explained in Transformers in Action

Few-shot learning is the adaptation of a model to a new task using only a small number of task-specific examples.

Few-shot learning uses a small number of task-specific examples to help a model perform a new task. It draws on knowledge acquired during broad pretraining, reducing the need for large task-specific datasets. In prompting, the examples appear in the prompt: the model uses them to guide its response without explicit retraining. section 1.3 section 1.5 section 4.2.2

The amount of guidance distinguishes related prompting approaches:

  • Zero-shot: state the task without showing an example. section 4.2.2
  • One-shot: include one example. section 4.2.2
  • Few-shot: include a couple of examples that demonstrate the desired task and output. section 4.2.2

Sentiment classification prompt

Instruction: Classify sentiment as positive or negative. Examples: “A wonderful little production” → positive; “Phil the Alien is one of those quirky films where the humor is based around the oddness of everything” → negative. Input: “The movie was not bad.” Expected response: positive. The labeled examples make the requested classification format concrete. section 4.2.2

Few-shot prompting is sufficient for many tasks, but reasoning tasks may require more advanced prompting techniques. It guides what the model should produce; decoding strategies separately control how output tokens are selected. section 4.2.2 section 4.3

Figure 4.6 In this plot we can clearly see how zero-shot performance steadily improves with model size; however, compared to few-shot, the performance increases faster. The chosen benchmark for evaluating the models was SuperGLUE, a standard natural language processing benchmark suite. Image is taken from [6].
figure

The SuperGLUE plot compares zero-shot and few-shot performance as model size grows; few-shot performance rises faster in the displayed comparison. section 4.2.2

How Transformers in Action covers it

How deep it goes
Defines the technique and works through a labeled prompt, but does not detail a training procedure.
Examples
Uses a positive-or-negative movie-review prompt and a SuperGLUE comparison across model sizes.
What it assumes
Assumes access to a pretrained model while explaining zero-, one-, and few-shot prompting through example counts.
What you can do after
Apply it via few-shot prompting by placing labeled examples alongside a new input.
How it connects
Connects few-shot learning to pretrained transformers, zero-shot prompting, one-shot prompting, and prompt engineering.

Also explained in

Compare how 18 books explain few-shot learning →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Transformers in Action. The section links point to the parts of the book it draws on.