liveBook · Manning

Attention

As explained in Introduction to Generative AI, Second Edition

Attention is a neural-network mechanism that computes the relative importance of input elements when producing a representation or output.

When translating “That cat chased a mouse,” a person focuses on “cat” and “mouse” rather than small connecting words. Attention applies a similar idea to neural networks: it assigns greater weight to input elements that matter most for producing a representation or output. section 1.2

In sequence-to-sequence translation, attention lets the decoder search across the entire input instead of processing it only piece by piece. Each position receives context from the sequence, helping the system connect words that may be far apart. section 1.2

Attention became especially important because it supports:

  • Long-term dependencies, by incorporating the whole input context at each step. section 1.2
  • Parallel computation, because transformer models replace lengthy sequential processing with attention information. section 1.2
  • Self-attention, which repeatedly builds new representations using relationships across the whole input. section 1.2

Resolving context

The word “it” can receive different attention distributions depending on the surrounding words, illustrating how context changes which input elements matter.

Figure 1.2 The distribution of attention for the word “it” in different contexts.
A screenshot of a video game

AI-generated content may be incorrect.

Explore how attention assigned to “it” changes across contexts. section 1.2

How Introduction to Generative AI, Second Edition covers it

How deep it goes
Explains weighting, context, long-term dependencies, and parallelization but stops short of implementation details or mathematics.
Examples
Uses machine translation, the sentence about a cat and mouse, and changing attention distributions for “it.”
What you can do after
Evaluate/understand how attention helps language models select relevant context and process sequences more efficiently.
How it connects
Connects attention with sequence-to-sequence models, encoder-decoder models, self-attention, and transformers.

Also explained in

Compare how 28 books explain attention →

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.