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 an important detail unstated: president of which country? A language model may supply an answer anyway, drawing on patterns in its training data rather than an explicitly provided context. Those patterns can reflect uneven geographic representation in the data. section 2.2

Linguistic context is the surrounding information that helps interpret or predict a word or token. It can include words before or after a missing token, as well as supporting information supplied with a question. A token is a unit of text that a model processes. section 2.3 section 1.6

A clue after the missing word

In “For their honeymoon, they flew to _____ and had a romantic dinner in front of the Eiffel Tower,” the words after the blank make Paris a likely answer. A bidirectional model can use both the left and right context to predict the missing token. An autoregressive model generating a continuation uses the text before the next token instead. section 2.3

In question answering, context may be a supplied passage or table. An extractive answer pulls information from it, while an open-book generative answer uses it to produce an answer in free text. In closed-book question answering, no supporting context is provided; the model answers according to what it learned during training. Obscure information may produce an incorrect or made-up answer. section 1.6 section 2.2

Context also helps communicate intent in a prompt. Instead of asking “Summarize this,” a user can specify the desired format, audience, and purpose—for example, a one-paragraph summary of three key risks for a cybersecurity executive. Such details guide the response, though models rely on patterns rather than understanding intent as people do. 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.”

Compare ways of adding context and other instructions to address common prompting challenges. section 7.1

How Introduction to Generative AI, Second Edition covers it

How deep it goes
Explains left and right context intuitively and distinguishes provided support from training-based answers, without implementation details.
Examples
Illustrates context with an Eiffel Tower sentence, an ambiguous presidential question, and a targeted executive-summary prompt.
What you can do after
Evaluate how surrounding text and supplied information can shape predictions and answers, including where unsupported assumptions may arise.
How it connects
Connects context to autoregression, bidirectional prediction, question answering, and prompt engineering.

Also explained in

Compare how 19 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.