liveBook · Manning

Few-shot learning

As explained in Introduction to Generative AI, Second Edition

Few-shot prompting is a technique that guides a model by providing a small number of task-specific examples in the input.

Suppose you want a language model to translate a sentence. Instead of giving only an instruction, you put a few translations in the prompt before the new sentence. This is few-shot learning: examples in the input show the model the task and the output format to follow. section 2.14 section 7.3

A translation prompt

“Hello” → “Hola”; “Goodbye” → “Adiós”; now translate “How are you?” The first two pairs demonstrate the pattern; the last sentence is the request. section 7.3

The number of examples distinguishes related approaches. Zero-shot prompting gives an instruction without examples; one-shot gives one example; few-shot gives a small set. These examples are part of the prompt, not a fine-tuning step. They can help with tasks such as classification, summarization, and code generation, but the response still needs checking. Clear instructions, relevant examples, and revision based on results remain important. section 2.14 section 7.3

Examples can also show an AI agent when and how to call a tool. Some agents place sample instructions and tool invocations in a system prompt without additional model training. For complex multistep tasks, prompting alone may not be the best approach. section 8.11 section 7.13

Table 7.2 Foundational prompting techniques

Technique

Description

Example use case

Example prompt

Zero-shot

Provide an instruction without examples

Language translation, Q&A

Translate the following sentence into Spanish: “Good morning, how are you?”

Few-shot

Include a small set of examples in the prompt

Summarization, classification, language translation, code generation

Translate: “Hello” → “Hola”; “Goodbye” → “Adiós”; Now translate: “How are you?”

Multi-turn

Carry information forward across multiple exchanges

Customer support, tutoring agents

User: My internet isn’t working.

Model: What device are you using?

User: MacBook Pro.

Model: Let’s run a few tests.

Compare the example translation prompt with zero-shot instructions and multi-turn conversation in the table of foundational prompting techniques. section 7.3

How Introduction to Generative AI, Second Edition covers it

How deep it goes
Defines and illustrates example-based prompting and contrasts it with zero-shot prompting and fine-tuning, without specifying a fixed example count.
Examples
Uses paired English–Spanish translations and sample tool invocations to show how examples establish a pattern.
What it assumes
Introduces prompts and example counts in plain terms, rather than requiring prior knowledge of prompting techniques.
What you can do after
Apply it via prompts containing a few task examples, then check responses and refine the prompt.
How it connects
Links few-shot learning to prompt engineering, zero-shot prompting, fine-tuning, and AI agent tool calls.

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 Introduction to Generative AI, Second Edition. The section links point to the parts of the book it draws on.