liveBook · Manning

Few-shot chain of thought

As explained in Generative AI in Action

Few-shot chain of thought is a prompting technique that provides a small number of examples containing reasoning chains before asking the model to solve a new instance.

Few-shot chain of thought (CoT) prompts a language model with a small set of examples that include high-quality reasoning chains, then asks it to solve a new instance. The examples demonstrate both the task format and a step-by-step solution pattern. section 6.4.5

Use the technique to:

  • Improve accuracy and reliability on tasks such as question answering, translation, and code generation. section 6.4.5
  • Distinguish example-driven few-shot CoT from zero-shot CoT, which adds an instruction such as “Take a step-by-step approach.” section 6.4.5

Arithmetic prompt pattern

Provide worked examples such as calculating computers installed over several days or golf balls remaining after losses, then pose a similar question and request the final answer.

How Generative AI in Action covers it

How deep it goes
Defines the prompt pattern and shows worked arithmetic, but omits implementation code for the completion API call.
Examples
Demonstrates computer counts, golf-ball subtraction, and bagel-cost arithmetic through question-and-answer reasoning chains.
What it assumes
Builds on basic prompt construction and completion API usage while contrasting example-based prompting with zero-shot instructions.
What you can do after
Apply it via few-shot prompts to elicit step-by-step reasoning and support more accurate or debuggable model outputs.
How it connects
Connects few-shot chain of thought with zero-shot chain of thought, prompt engineering, and completion APIs.

Also explained in

Compare how 2 books explain few-shot chain of thought →

Related concepts

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