# Anatomy of Transformers vs RNNs

A crafted bench model comparing the old one\-word\-at\-a\-time RNN reader with the Transformer, whose attention lets every word look at every other word at once

By Numa

Topic: Computing, AI &amp; Electronics

[Open the interactive Jig](https://ask.jig.com/j/aSHF2vjjMF3M)

## Transcript

### 1. Two ways to read a sentence

Before a computer can answer you, it has to read your words\. On the left is the old reader, a recurrent neural network, or RNN\. On the right is the Transformer, the design behind today's chatbots\. Both are reading the same seven words: The cat was tired so it slept\.

Drag empty space to turn the bench\. Scroll or pinch to zoom\.

### 2. The old way: one word at a time

An RNN reads like a relay race\. Each cell takes one word plus a purple baton of memory from the cell before, then passes the baton on\. Cell five cannot start until cell four is done, so seven words take seven turns in a row\.

A 10\-word sentence needs 10 turns, one after another\. The chips that train AI, called GPUs, are fastest when they can do many things at once\.

### 3. A memory that fades

The baton is small, so early words get squeezed out as new ones arrive\. By the last word, the memory of the cat has grown faint\. In 1997 the LSTM added little gates that decide what goes into its memory and what comes out, and a memory highway along the top\. It helped, but it still read one word at a time\.

Learning has the same problem: the correction signal shrinks as it travels back through many turns\. Experts call this the vanishing gradient\.

### 4. 2017: Attention Is All You Need

In 2017, a team of eight researchers, most of them at Google, tried something bold: they dropped the relay completely\. Their Transformer takes in every word at the same moment\. Each word becomes a list of 512 numbers, plus a stamp that records where it sits in the sentence\.

The paper was called Attention Is All You Need and was first posted in June 2017\.

### 5. Every word looks at every word

This is attention\. Each word asks a question and checks every other word for a matching answer\. The brighter the beam, the more that word matters\. In this example, the word it sends its brightest beam to cat\. That is how a Transformer can work out who it is\.

Any two words are one step apart, however far apart they sit\. Pick a word, or click a lit tile, to see where it looks\. The beam strengths here are an illustration\.

### 6. Eight heads, six layers

One look is not enough, so each layer runs eight attention heads side by side\. Each head can learn to notice a different kind of link, such as who did what\. A small network then mixes what the heads found, and the whole layer repeats six times, sharpening the meaning on the way up\.

Each head works with 64 numbers per word, and 8 heads times 64 makes 512\.

### 7. Writing the answer

The second tower, the decoder, writes the reply\. It adds one word at a time, and each new word looks back at the words already written and at the whole input\. So reading happens all at once, but writing still goes word by word\.

The first Transformer was built to translate\. It beat the best earlier systems at English to German and English to French\.

### 8. Why it changed the game

Race the two readers on the same sentence\. The RNN must wait for each word, while the Transformer works on every word together, which is exactly what GPUs are good at\. That speed let people train far bigger models on far more text, and it led to GPT and today's AI helpers\.

The large 2017 model trained in 3\.5 days on 8 GPUs\. GPT\-3, from 2020, stacks 96 Transformer layers and has 175 billion learned numbers\.
