Stage 3 of 4

Transformer

Self-attention and a small Transformer: watch attention learn where to look, and the model write its answer one token at a time. Checked against PyTorch.

algorithms
2
in every lab
2D + 3D
articles for every lab
EN / 中文

Live · computing in your browser

—

Algorithms in Transformer

In the recommended learning order. Hover a card to replay how that algorithm computes.

  1. q1k1q2k2q3k3q4k4q5k5q6k6q7k7q8k8q9k9softmax(QKᵀ/√dₖ)·VQ · Kᵀ÷ √dₖsoftmax
    01

    Self-attention and multi-head attention

    Scaled dot-product and multi-head attention, trained live: every Q, K, V, score, mask and softmax, and the patterns heads learn.

    2D3DOpen the lab
  2. LayerNormMulti-head attentionLayerNormFeed-forward · GELU++residual× L3718>3718>83718>83718>813718>813718>8173718>8173718>81733718>8173P(next | prefix)
    02

    Transformer

    A small GPT trained in your browser on copy, reverse, sort and addition: residual stream, every block, attention maps and sampling.

    2D3DOpen the lab