Overview

12 Beyond recurrence: Google Brain and the transformer architecture

In this chapter, the transformer is presented as a turning point in how neural networks handle sequence data. Earlier recurrent models processed information step by step, which made them intuitive but also forced distant relationships to pass through repeated state updates and prevented full parallelization during training. The transformer kept the same basic learning framework of prediction, loss, backpropagation, and optimization, but replaced sequential state propagation with self-attention, allowing context to be built from direct relationships among tokens rather than compressed memory passed along a chain.

The chapter then explains how self-attention works through queries, keys, values, dot products, masking, and softmax. Using simplified examples, it shows how a token such as it can weigh surrounding words, produce a contextual representation, and support next-token prediction. The same mechanism is then extended to more complex behavior: semantic association can connect a prompt with learned facts, and autoregressive generation can chain predictions together into longer responses. Causal masking ensures the model only uses information available at each position, while the output layer turns the final contextual state into a probability distribution over possible next tokens.

Finally, the chapter places the transformer in a broader intellectual and practical setting. It argues that the architecture is not a new theory of learning, but a reorganization of established ideas from neural networks, probability, likelihood, and information theory. Its influence comes from the combination of direct relational modeling, multi-head attention, modular blocks, and parallel-friendly computation, which made scaling more effective and opened the door to large language models and other generative systems. At the same time, the chapter stresses limits: high computational cost, finite context windows, imperfect reliability, and the possibility of fluent but wrong outputs. The result is a balanced view of the transformer as a foundational architecture whose core ideas are likely to persist even as future systems evolve.

The transformer architecture introduced in Attention Is All You Need. Stacked encoder and decoder layers combine multi-head attention with feed-forward transformations, residual connections, and normalization. Positional encodings preserve sequence order without recurrence. The decoder uses masked self-attention to prevent access to future tokens and cross-attention to incorporate encoder outputs. Within each multi-head attention block, individual heads use dot products to calculate compatibility scores and softmax to convert those scores into attention weights, as demonstrated in the worked examples that follow. Reproduced from Vaswani et al (2017), Attention Is All You Need, Proceedings of the 31st Conference on Neural Information Processing Systems (NeurIPS 2017).

Summary

  • Recurrent neural networks modeled sequence by carrying context through an evolving hidden state. This approach worked well for many tasks but made distant relationships harder to preserve and required token positions to be processed sequentially.
  • In 2017, Vaswani and his Google Brain colleagues reorganized sequence modeling around self-attention. Attention already existed, but eliminating recurrence and making attention the architecture’s central operation represented the decisive break.
  • Self-attention uses queries, keys, values, compatibility scores, and learned weights to construct context from relationships among tokens. Multi-head attention allows several relational patterns to contribute simultaneously rather than forcing context into one dominant relationship.
  • Direct relational access made long-range dependencies easier to preserve, while parallel token processing substantially accelerated training. Repeated transformer blocks provided a modular architecture that could expand systematically in depth, width, data, and parameter count.
  • When combined with large data sets, improved training, and greater computation, the transformer helped make practical a major leap in capability. Models could sustain extended text, translate languages, generate code, analyze documents, maintain dialogue, and integrate multiple forms of data with unprecedented breadth and coherence.
  • Transformer-based language models nevertheless generate one token at a time. Attention helps construct relevant context, but factual recall and multistep generation depend on all the model’s learned components working together. Even then, fluent output may be factually or logically incorrect.
  • The transformer preserved rather than displaced established foundations. Probability continued to represent possible outcomes, likelihood and cross-entropy continued to guide learning, neural networks continued to develop representations through backpropagation, and generalization remained essential beyond the training data.
  • Its historical significance lies in combining these accumulated foundations with a new relational architecture suited to modern computation. By pushing outward earlier constraints on context, training, and scale, the transformer expanded the range and complexity of uncertainty that learning systems could address.
  • Scalability, adaptability, and accumulated technological investment position the transformer for continued influence, but computational demands, reliability limitations, and emerging alternatives make its future dominance uncertain. Even if the original architecture changes, its central ideas may carry forward into successor systems.

FAQ

What problem did the transformer solve that recurrent neural networks struggled with?The transformer addressed two major recurrent-model constraints: distant relationships were hard to preserve through repeated hidden-state updates, and training was inherently sequential. By replacing recurrence with self-attention, it made context more directly accessible and enabled parallel computation during training.
What is self-attention in the transformer architecture?Self-attention is the mechanism that lets each token evaluate how relevant other tokens in the same sequence are to it. It assigns weights to those relationships and combines the resulting information into a new, context-sensitive representation.
Why are queries, keys, and values important in attention?Queries represent what a token is looking for, keys represent how other tokens can be matched as relevant, and values hold the information that can be contributed if selected. Their interaction lets the model compute compatibility scores and build context from weighted relationships.
Why does the transformer use softmax after computing attention scores?Softmax converts raw compatibility scores into normalized attention weights that sum to 1. This makes it possible to combine multiple context tokens proportionally, with more relevant tokens receiving greater influence.
What is causal masking, and why is it needed?Causal masking blocks a token from attending to future tokens. It preserves the next-token prediction task by ensuring that each position can only use information already available up to that point in the sequence.
How does the transformer generate text one token at a time?It uses autoregressive generation: the model predicts one token, appends it to the sequence, and then predicts the next token using the expanded context. This continues until the response is complete.
How did the chapter’s pronoun example show attention in action?The sentence “The trophy didn’t fit in the box because it was too…” is ambiguous because “it” could refer to either “trophy” or “box.” Attention compares the relevant tokens directly, builds a contextual representation, and can favor the continuation that fits the stronger relationship, such as “small.”
How can a transformer recall factual associations like an author’s name?The model learns distributed associations during training across many contexts. In the example of “Who wrote The Count of Monte Cristo?”, the prompt representation interacts with learned output vectors so that the correct continuation, “Dumas,” receives the highest score.
Why is the transformer considered a major architectural innovation?Its novelty was not attention alone, but making self-attention the organizing principle of the model and removing recurrence. This created a modular, parallelizable architecture that scaled well with data, parameters, and hardware.
Will transformers remain dominant in the future?They are likely to remain influential because of their strong performance, scalability, and large supporting ecosystem. However, they also face limits such as high computational cost, finite context windows, and reliability issues, so hybrid or alternative architectures may eventually share or replace some of their role.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Timeless Algorithms, The Foundational Ideas ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Timeless Algorithms, The Foundational Ideas ebook for free