Interactive lab · Transformer from the paper · Part 1

The Transformer from the paper, running live

Figure 1 of Attention Is All You Need, with every block moving and every value real: a Transformer built line by line from the 2017 paper and trained on a laptop CPU, normalising a Belgavi's Book Store order date.

Encoder

1 · Input characters → token ids

2 · Embedding × √dmodel + positional encoding §3.4, §3.5

embedding × √
+ sin/cos position
= encoder input
negative · 0 · positive. One row per character, one column per dimension.

3 · Self-attention softmax(QKᵀ/√dk)V

4 · Add & Norm → Feed-forward → Add & Norm max(0, xW₁+b₁)W₂+b₂

Decoder

5 · Outputs, shifted right

The decoder reads what it has written so far, starting from the start symbol.

6 · Masked self-attention future set to −∞

7 · Encoder–decoder attention Q from decoder, K and V from encoder

Output shared weights

8 · Linear + softmax §3.4

9 · Answer

This run vs the paper's base model

Why the paper dropped recurrence

An RNN must finish position 1 before it can start position 2, so its sequential work grows with the length of the input. Self-attention looks at every position in one matrix multiply. The paper's Table 1 makes this argument with big-O; here it is measured on the same laptop that trained the model.

Where the numbers come from

The series: the Transformer, built from the paper

    Views are my own and do not represent any employer, past or present.