The paper's Figure 1, live

This is the transformer as the paper draws it: the encoder reads the English on the left, the decoder writes the German on the right, both from the bottom up. Click any box to see what it computes for your sentence, or press Play to watch a whole translation pass through it.

Watch a whole translation step by step

English sentence

The model's German: Anna hat einen kleinen Hund . Sie mag ihn .

Playback speed
The paper's Figure 1 redrawn: the encoder on the left and the decoder on the right, each box a button that shows its numbers. N× ×N N = 2 N = 2 Inputs Input Embedding + Positional Encoding Multi-Head Attention Add & Norm Feed Forward Add & Norm Outputs (shifted right) Output Embedding + Positional Encoding Masked Multi-Head Attention Add & Norm Multi-Head Attention Add & Norm Feed Forward Add & Norm Linear Softmax Output Probabilities
After Figure 1 of Vaswani et al. (2017), redrawn.

Multi-Head Attention

In the encoder, paper section 3.2.2

Every English token looks at every other one through four heads at once, mixes in what it finds, and the heads' results are joined and projected back to 64 numbers.

Trace step enc.0.self.out: 64 numbers per token
Token12345678… 56 more
Anna−0.290.61−0.56−0.10−0.09−0.460.35−0.12…
has−0.110.32−0.35−0.06−0.04−0.300.28−0.07…
a−0.560.39−0.43−0.370.05−0.550.81−0.33…
small−0.780.09−0.46−0.54−0.17−0.690.62−0.44…
dog−0.320.41−0.49−0.160.13−0.470.25−0.10…
.−0.45−0.29−0.32−0.35−0.54−0.110.23−0.20…
She−0.140.51−0.43−0.03−0.01−0.290.25−0.10…
likes−0.230.35−0.44−0.08−0.15−0.380.32−0.12…
it−0.580.17−0.13−0.390.06−0.350.49−0.28…
.−0.80−0.640.17−0.52−0.480.100.01−0.36…
</s>−0.850.08−0.63−0.69−0.41−0.840.83−0.47…
An unhandled error has occurred. Reload 🗙

Reconnecting…

Your connection to the Transformers and Attention Lab dropped, probably a Wi-Fi blip. Hold on while it reconnects.

The connection could not be restored. The page will reload in a few seconds.