liveBook · Manning

Prompt engineering

As explained in Transformers in Action

Prompting is the practice of providing input instructions or context to a generative model to elicit a desired output.

Prompt engineering is the practice of crafting inputs to guide a generative model toward a desired output. A prompt may be a question, an instruction, or other task input; multimodal models can also receive audio, images, or video. Prompts specify what the model should do, while decoding and sampling strategies affect how its output tokens are chosen. section 4.2 section 4.3

Choose a prompting pattern according to the task:

  • Use zero-shot prompting without examples; add one example for one-shot prompting or several for few-shot prompting. section 4.2.2
  • Use chain-of-thought prompting to elicit intermediate reasoning steps for complex problems. Contrastive chain-of-thought, chain of verification, and tree-of-thought are further approaches to reasoning and reliability. section 4.3
  • For a large, chaotic context, thread-of-thought prompting asks the model to work through manageable parts, summarizing and analyzing as it goes. Combine that response with a conclusion cue such as “Therefore, the answer:” to refine the result. section 4.2.8

Few-shot sentiment classification

Start with the instruction “Sentiment classification.” Ask the model to classify “The movie was not bad” as positive or negative, and include sample texts labeled with those classes. The intended response is positive. The examples show the requested input–output pattern rather than changing the model. section 4.2.2

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 across model sizes; few-shot performance rises faster in the comparison shown. section 4.2.2

Prompt wording is only one part of the input. Context engineering also selects and formats information supplied before generation, such as retrieved documents or structured memory. For responsible use, prompt rules can target important keywords or topics, though such rules cannot cover every case. section 4.2 section 10.3

How Transformers in Action covers it

How deep it goes
Defines prompts, compares prompting patterns, and gives few-shot and thread-of-thought procedures without detailing model internals.
Examples
Uses few-shot sentiment classification and a SuperGLUE comparison of zero-shot and few-shot performance.
What it assumes
Defines prompts from the ground up while assuming access to a model that responds to inputs.
What you can do after
Practice/perform it by supplying task examples or staging a reasoning prompt for a chaotic context.
How it connects
Connects to decoding, sampling, context engineering, chain-of-thought prompting, and responsible AI.

Also explained in

Compare how 38 books explain prompt engineering →

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.