liveBook · Manning

Transformer architecture

As explained in The AI Pocket Book

A neural network architecture that contextualizes each token using surrounding tokens rather than compressing the whole prompt into one summary vector.

A transformer is a neural network architecture that keeps token information separate while progressively contextualizing each token. This helps an LLM distinguish “the dog’s bark was barely” from “the tree’s bark was barely,” leading to “audible” versus “visible.” section 1.18

The high-level flow is straightforward:

  • Map input tokens to embedding vectors. section 1.18
  • Contextualize those embeddings using the preceding tokens instead of compressing the entire prompt into one summary vector. section 1.18
  • Use the improved embeddings to predict the next token. section 1.18

Earlier LSTM-based language models summarized all preceding context in one fixed-size embedding. That made variable-length inputs convenient but could erase the fine-grained information needed to resolve ambiguity. Transformer layers instead calculate attention scores and use them to update embeddings. section 1.18 section 1.24

Disambiguating “bark”

Given “the dog’s bark was barely,” the model predicts “audible.” Given “the tree’s bark was barely,” it predicts “visible.” The surrounding noun changes the token’s contextual meaning. section 1.18

Figure 1.9 LLM overview. In step 1, the tokens are mapped to embeddings one by one. In step 2, each embedding is improved by contextualizing it using the previous tokens in the prompt. In step 3,
the much-improved embeddings are used to make predictions about
the next token.

Use the overview figure to trace the three-stage path from tokens to embeddings, contextualized representations, and next-token predictions. section 1.18

How The AI Pocket Book covers it

How deep it goes
Defines contextualization and attention-based updates, but stops short of exact calculations and implementation details.
Examples
Uses dog-versus-tree “bark” prompts, token embeddings, attention scores, and a compact GPT-2 implementation as concrete illustrations.
What it assumes
Introduces tokens and embeddings at a high level while assuming only basic familiarity with LLM next-token prediction.
What you can do after
Evaluate/understand why transformers preserve contextual information better than single-summary LSTM representations.
How it connects
Connects embeddings, attention, LSTMs, machine learning, deep learning, CNNs, and multimodal AI.

Also explained in

Compare how 28 books explain transformer architecture →

Related concepts

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