V. Artificial Intelligence · Chapter 48
The Transformer
In 2016, Google launched the Google Neural Machine Translation system—an overhaul of Google Translate’s backend that replaced its phrase-based statistical engine with deep neural networks. The system followed the sequence-to-sequence “encoder–decoder” blueprint that Ilya Sutskever and colleagues had introduced in their 2014 paper. The shift marked a dramatic leap in translation quality: the new system could model entire sentences end-to-end and capture context far beyond the reach of earlier methods.
In this encoder–decoder paradigm, one network, the encoder, reads a source sentence and turns it into a numerical summary; a second network, the decoder, takes that summary and generates a sentence in the target language. In the earliest seq2seq models, this summary really was a single vector—one fixed-length bundle of numbers that was supposed to capture everything important about the input sentence. That worked surprisingly well for short sentences, but it created an obvious bottleneck: the longer and more complex the input, the harder it was to squeeze all the needed information through a single numerical “neck of the hourglass.”
At the time Sutskever left Google in late 2015, the dominant way to build these encoder and decoder networks was with Recurrent Neural Networks (RNNs), particularly their more advanced variant, the Long Short-Term Memory (LSTM) network. RNNs handle variable-length sequences by processing each token in turn through a long chain of identical cells, each one passing forward a compressed summary of everything it has seen so far. Simple RNNs struggle with long-range dependencies; their memory fades. LSTMs tried to fix this with gating mechanisms that decide what information to remember or forget, allowing the network to preserve important context over longer spans.
Google’s translation system used deep stacks of LSTM layers on both the encoder and decoder, and added an “attention” mechanism on top. Attention offered a simple but powerful idea: instead of relying solely on a single compressed vector, the decoder could look back at all the encoder’s intermediate states and decide, dynamically, which words in the source sentence mattered most for predicting the next word in the translation. You can think of it as a matrix of little connection weights that brightens the relevant parts of the source sentence and dims the irrelevant ones. In effect, attention lets the model build a temporary map of relationships—who refers to what, which adjectives modify which nouns, what events depend on which others—and reshape that map at each decoding step. This gave LSTM-based systems a major boost in expressiveness and helped alleviate the “single bottleneck vector” limitation.
Even so, the LSTM-based approach still had two important drawbacks. First, despite attention, information still had to thread its way through long recurrent chains, which made it hard to model very long-range dependencies and complicated training. Second, because LSTMs process tokens one after another, their computation can’t be parallelized across time—each step depends on the previous one—making them slow and inefficient to train on GPUs.
In 2017, researchers at Google Brain found a way around both constraints. The landmark paper “Attention Is All You Need” proposed a new architecture called the Transformer. The key move was not inventing attention—that was already in use—but making attention the core building block and discarding recurrence entirely. Instead of a chain of RNN cells carrying state forward one token at a time, the Transformer uses layers of “self-attention” in which every word in a sentence can look at every other word directly and assign weights to them in parallel.
At each layer, the Transformer essentially asks, for every position, “Given this current word, how relevant is every other word?” While generating the translation for, “The animal didn’t cross the street because it was too tired,” when producing the output for “it” the model will focus more on “animal”; but for the sentence, “The animal didn’t cross the street because it was too wide,” the model will focus more on “street.” Over millions of examples, the model learns statistical regularities of co-reference and dependency: in contexts like “it was tired,” animate nouns tend to be the right referent; in contexts like “it was wide,” inanimate nouns such as “street” or “river” tend to be favored.
The Transformer quickly surpassed recurrent networks on translation and other benchmarks. Its fully parallel structure made training dramatically faster: instead of a slow procession through time, each Transformer layer computes attention weights between all pairs of words in a single dense GPU operation. Within months, research groups worldwide adapted and extended the architecture, setting off an intense period of experimentation that would redefine the field.