liveBook · Manning

Transformer architecture

As explained in Grokking AI Algorithms, Second Edition

The Transformer is a neural-network architecture based primarily on attention mechanisms for processing sequences and modeling context.

A Transformer is a neural-network architecture that processes a sequence while letting each word weigh the importance of every other word. This self-attention builds a rich understanding of context, unlike recurrent networks that compress earlier text into a fixed-size memory. section 11.11

A Transformer block combines attention mechanisms, feed-forward neural networks, and normalization layers. Modern language models may use only the encoder or decoder portion of the original design; GPT models, for example, are decoder-only. section 11.1

Design a Transformer by choosing:

  • Vocabulary size: the number of unique tokens after byte-pair encoding merges. section 11.11
  • Context window: how many tokens the model can see at once. section 11.11
  • Width, depth, attention heads, and feed-forward size: capacity choices that control token detail, processing steps, simultaneous patterns, and neural-network size. section 11.11

A toy language model

A small example can use 34 tokens, a 32-token context window, width 4, two layers, one attention head, and feed-forward layers with 8 and 4 neurons. A larger context window supplies more preceding text, while additional width or depth provides more representational capacity. section 11.11

Figure 11.24 A simplistic overview of the Transformer framework
11_24

Use the overview to trace how tokens, attention, feed-forward processing, and normalization fit together in the Transformer framework. section 11.11

How Grokking AI Algorithms, Second Edition covers it

How deep it goes
Explains self-attention, block components, architecture alternatives, and hyperparameters, but stops short of equations or implementation details.
Examples
Uses a toy language model with 34 tokens, 32-token context, two layers, one attention head, and small feed-forward networks.
What it assumes
Assumes familiarity with neural networks and tokens while introducing attention, context windows, embeddings, layers, and heads intuitively.
What you can do after
Evaluate Transformer designs by comparing vocabulary, context, width, depth, attention-head, and feed-forward-size choices.
How it connects
Connects self-attention with recurrent neural networks, convolutional neural networks, feed-forward neural networks, normalization, and large language models.

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 Grokking AI Algorithms, Second Edition. The section links point to the parts of the book it draws on.