liveBook · Manning

Few-shot learning

As explained in The Complete Obsolete Guide to Generative AI

Few-shot learning is adapting a model to a task by conditioning it on a small number of task-specific examples or demonstrations.

Few-shot learning is the art of giving a model a tiny cheat sheet instead of a mountain of labeled data. Supply a few task-specific examples or demonstrations, then ask for a new result in the same pattern. The examples condition the model on the task, format, or style so it can adapt quickly to unseen inputs. section 9.6 section 10.12

In prompt work, those examples can be placed directly before the request. This differs from zero-shot prompting, where instructions alone guide a pretrained model. Few-shot approaches are useful when labels are scarce, expensive, or slow to obtain, but outputs still need verification rather than blind trust. section 6.15 section 6.9

A practical few-shot prompt usually includes:

  • A clear task and desired output format. section 9.6
  • A small set of representative input-output examples. section 9.6
  • A new input that follows the demonstrated pattern. section 6.9
  • A check of the result, especially when the task depends on factual accuracy. section 6.15

Teach translation by example

Give the model paired English and French sentences, then present a new English sentence with its French translation left blank. The earlier pairs demonstrate the mapping and expected response format, making the final request a small pattern-completion task rather than a vague “please translate this” gamble. section 6.9

Summarize a new article

Provide several articles alongside their summaries, then add another article and request a summary. The demonstrations show what counts as a summary for the task and help the model adapt without extensive fine-tuning. section 9.6

English sentence: “I love to travel.”

French translation: “J’adore voyager.”

English sentence: “The cat is sleeping.”

French translation: “Le chat dort.”

English sentence: “Where is the nearest train station?”

French translation: “Où se trouve la gare la plus proche?”

Browse the paired translation examples to see how demonstrations establish both the task and the output pattern before a new request. section 6.9

How The Complete Obsolete Guide to Generative AI covers it

How deep it goes
Defines few-shot learning, contrasts it with zero-shot prompting, and illustrates prompting examples while naming meta-learning and metric-based methods without detailing them.
Examples
Uses English-to-French translation pairs, article-summary demonstrations, and a dialogue-writing prompt comparison.
What it assumes
Introduces the approach from basic prompts and examples while assuming a pretrained language model is available.
What you can do after
Apply it via prompts by supplying a few representative demonstrations before a new task input.
How it connects
Connects few-shot learning to zero-shot prompting, pretraining, fine-tuning, data efficiency, transfer learning, active learning, and meta-learning.

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 The Complete Obsolete Guide to Generative AI. The section links point to the parts of the book it draws on.