liveBook · Manning

Context

As explained in Introduction to Generative AI, Second Edition

Linguistic context is surrounding sequence information that informs the interpretation or prediction of a token.

“Who was the first president?” leaves something unsaid: president of what? Context is surrounding information that helps interpret a question or predict a token—a unit of text. It may come from nearby words, information supplied with a question, or patterns a language model learned during training. Without a stated country, a model may assume the United States; that answer reflects its learned patterns, not certainty about the user’s intent. section 2.2 section 2.3

Which context a model can use depends on the task:

  • A bidirectional model predicting a missing token can use words on both sides of the gap. In “They flew to _____ and had dinner in front of the Eiffel Tower,” the later words strongly suggest “Paris.” section 2.3
  • An autoregressive model generating a continuation uses the text before the next token, not words that have yet to be generated. It learns by repeatedly predicting the next token from earlier text. section 2.3

Context can also mean supporting information supplied for a question. In extractive question answering, a model takes an answer from supplied text or a table. In open-book generative question answering, it uses supplied information to answer in its own words. In closed-book question answering, only the question is supplied, so the answer depends on patterns learned during training. An obscure question may then receive an incorrect or made-up answer. section 1.6 section 2.2

Adding context to a request

“Summarize this” leaves the audience and purpose unclear. “Write a one-paragraph executive summary highlighting three key risks for a cybersecurity executive” supplies both. The added context gives the model a more specific target, though careful wording does not guarantee a sound answer. section 7.1

Table 7.1 Prompting strategies for common LLM challenges

Challenge

Prompting strategy

Example prompt

Ambiguity

Add context, clarify user intent, and specify output format

“Summarize the following memo in three bullet points for a technical project manager.”

Hallucination

Provide reference material; use step-by-step reasoning

“Based on the attached report, explain the drug’s mechanism of action step by step.”

Misalignment

Set tone, role, and boundaries explicitly

“You are a professional HR advisor. Provide neutral guidance and avoid offering legal advice.”

Complexity

Break the task into steps or chain prompts

“First, list all relevant deadlines from the document, then summarize their impact on project timelines.”

The table pairs common prompting problems with ways to add context, such as clarifying the audience and format or providing reference material. section 7.1

How Introduction to Generative AI, Second Edition covers it

How deep it goes
Contrasts left-only and bidirectional context through plain-language examples without detailing model internals.
Examples
Uses an Eiffel Tower sentence, an ambiguous president question, and a more specific executive-summary prompt.
What you can do after
Apply it via prompt engineering by specifying purpose, audience, and supporting information while checking answers that rely on unstated assumptions.
How it connects
Connects context to autoregression, bidirectional models, question answering, and prompt engineering.

Also explained in

Compare how 18 books explain context →

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.