liveBook · Manning

Transformer architecture

As explained in Transformers in Action

A transformer is a neural network architecture that processes sequential and other structured data using attention mechanisms.

A transformer is a neural network architecture for processing sequences. Unlike an RNN, which passes a recurrent state from one element to the next, it uses attention so each position can draw on information from other positions. This supports parallel processing and helps capture long-range relationships, making transformers useful for tasks such as translation and text generation. section 1.1 section 1.1.2

In the encoder–decoder design, the encoder turns an input sequence into contextual information that the decoder uses to produce an output sequence. Attention determines which parts of a sequence matter to a given position; multihead attention captures different relationships at the same time. Stacked layers combine attention with point-wise feed-forward networks, residual connections, and layer normalization. Positional encoding supplies information about token order. section 2.2 section 2.3

Figure 2.5 The encoder of the transformer architecture is depicted on the left side of the figure, and the decoder is depicted on the right side.
figure

The architecture diagram places the encoder and decoder side by side, making their distinct roles and stacked components easier to trace. section 2.2

English-to-French translation

For “I don’t speak French” → “Je ne parle pas français,” the encoder processes the English sentence, and the decoder uses its contextual information to generate the French sentence. Attention relates each input element to the rest of the sequence rather than relying on a single state carried word by word. section 1.1.2

The design is a blueprint, not a single fixed model. Encoder–decoder variants suit translation, while decoder-only variants are common in text completion and conversational AI. Pretrained models in Hugging Face Transformers can be adapted to a task instead of trained from scratch, but model choice must account for computational and memory demands, especially at large scales. section 1.4 section 1.2 section 1.5

How Transformers in Action covers it

How deep it goes
Explains encoder–decoder flow and names attention, feed-forward networks, residual connections, layer normalization, and positional encoding; the supplied overview does not derive their implementations.
Examples
Illustrates encoder–decoder flow with English-to-French translation and multihead attention with the sentiment of “The movie was not bad.”
What it assumes
Builds from RNN and LSTM comparisons while introducing attention and the encoder–decoder structure rather than assuming transformer terminology.
What you can do after
Evaluate/understand it to choose between encoder–decoder and decoder-only models and weigh pretrained-model convenience against resource demands.
How it connects
Connects self-attention and multihead attention to RNNs, LSTMs, positional encoding, feed-forward networks, 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 Transformers in Action. The section links point to the parts of the book it draws on.