liveBook · Manning

Attention

As explained in Coding with AI

An attention mechanism computes the relevance of elements in an input sequence so a model can emphasize information important to the current computation.

Attention helps a model identify which elements of an input sequence matter most for the current computation. In a Transformer, each word is compared with other words so stronger relationships provide more useful context. section 1.4

A Transformer uses attention as part of a broader sequence-processing workflow:

  • Converts words into numerical representations. section 1.4
  • Tracks word positions so sequence order contributes to meaning. section 1.4
  • Checks relationships among words and emphasizes closely related elements. section 1.4
  • Processes entire sequences in parallel through multiple self-attention layers. section 1.4

Context in a sentence

In “The dog chased the cat,” attention helps a Transformer relate “dog,” “chased,” and “cat” while interpreting the sentence’s meaning. section 1.4

Figure 1.2 A transformer takes a sentence and analyzes word positions and relationships to try and extract meaning from the text it sees.
A diagram of a text

Use the figure to trace how a Transformer analyzes word positions and relationships before producing meaning from a sentence. section 1.4

How Coding with AI covers it

How deep it goes
Explains contextual relationships, parallel sequence processing, and layered self-attention without detailing the underlying calculations.
Examples
Uses “The dog chased the cat” and “Jane helps Joe” to illustrate relationships and word positions.
What it assumes
Teaches word representations, sequence order, and contextual relationships as the basic steps of Transformer processing.
What you can do after
Evaluate/understand how Transformers use word relationships and positions to interpret sequence context.
How it connects
Connects attention to Transformers, large language models, recurrent neural networks, and LSTMs.

Also explained in

Compare how 28 books explain attention →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Coding with AI. The section links point to the parts of the book it draws on.