liveBook · Manning

Few-shot learning

As explained in LLMs in Production

Few-shot learning is the adaptation or prediction of a model from only a small number of labeled examples.

Suppose you need an LLM to label customer reviews but have only a handful of labeled examples. Few-shot learning is the ability to use those examples to perform the task. A practical route is few-shot prompting: put example inputs and desired outputs in the prompt, then provide a new input. The model can follow the pattern without task-specific finetuning. section 2.4 section 7.1.1

Label a review

A prompt might pair “Worked as advertised, 10/10” with “positive” and “It was broken on delivery” with “negative,” then end with an unlabeled review. The examples establish both the task and the answer format. If more labels are acceptable, state the allowed options explicitly; you can also ask for only one label and no explanation. section 7.1.1

Few-shot does not mean that every model will benefit from the same examples. Larger LLMs can generalize to tasks with little labeled data, while a smaller, specialized model may struggle with an unfamiliar prompt format. In a coding copilot, plain-English instruction examples were a poor match for a model trained to take code as input and generate code. Trying code examples, finetuning, or a different model are practical next steps. section 2.4 section 10.4

Choose the amount of guidance the task needs:

  • Zero-shot: try the task without an example when the model can handle it directly. section 2.4
  • One-shot or few-shot: supply one or several examples when the desired behavior or format needs demonstration. section 2.4 section 7.1.1
  • Finetuning: consider changing the model when prompting alone cannot bridge a mismatch with its training or intended use. section 10.4

How LLMs in Production covers it

How deep it goes
Works through a labeled sentiment prompt and discusses model-fit limits, but does not detail a few-shot training procedure.
Examples
Demonstrates positive-or-negative review labeling and examines mismatched examples in a coding copilot.
What you can do after
Apply it via few-shot prompting to specify a task and output format, then assess whether the examples suit the model.
How it connects
Connects few-shot prompting to zero-shot prompting, one-shot prompting, finetuning, prompt engineering, and retrieval-augmented generation.

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 LLMs in Production. The section links point to the parts of the book it draws on.