liveBook · Manning

Prompt engineering

As explained in Deep Learning with R, Third Edition

Prompt engineering is the systematic design and refinement of inputs to a generative model to improve its performance on a task.

Prompt engineering is the practice of formulating and refining inputs to a language model so it performs better on a task. Because a generative model predicts likely continuations rather than interpreting prompts conversationally, small wording changes can redirect its output. section 1.8 section 19.1.2

Turning autocomplete into a recipe

A bare prompt such as “How can I make brownies?” can produce a simulated forum exchange. Extending it with “The following brownie recipe is easy to make in just a few steps. You can start by” makes a recipe continuation more likely, producing concrete cooking instructions. section 16.3.1

Useful prompt-design moves include:

  • Specify the kind of output required by supplying an appropriate context or opening. section 16.3.1
  • Assign a role, such as giving short, helpful answers to questions. section 16.3.1
  • Add constraints, such as topics that generated responses should avoid. section 16.3.1
  • Test wording variations rather than assuming that a successful prompt will remain reliable. section 19.1.2

Prompting can access different regions of a model’s learned distribution, but responses remain difficult to predict. The same sensitivity that enables useful steering can also cause reasoning failures after minor rewordings or distractors. section 16.3.1 section 19.1.2

How Deep Learning with R, Third Edition covers it

How deep it goes
Explains prompt construction through continuations, role instructions, constraints, and phrasing sensitivity, but does not provide a formal optimization procedure.
Examples
Uses brownie recipes, role instructions, harmful-topic constraints, reasoning riddles, and an invented-president question to demonstrate prompt effects.
What you can do after
Apply prompt engineering by constructing contextual openings, role instructions, constraints, and wording variations for language-model tasks.
How it connects
Connects prompting with foundation models, language-model pretraining, hallucinations, reasoning, and latent-space retrieval.

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 Deep Learning with R, Third Edition. The section links point to the parts of the book it draws on.