Secure Systems Group
Menu×

Wiki Home

Transformer

Definition

A transformer maps a sequence of tokens to a sequence of vectors through a stack of identical blocks (Vaswani et al., 2017). Each token is first looked up in an embedding table, giving a vector per position. Every block then applies two operations in turn. Self-attention lets each position gather information from the others: the block projects each position into a query, a key, and a value, scores every query against every key, passes those scores through a softmax to get mixing weights, and returns the weighted sum of the values. The feed-forward network then transforms each position on its own through a widening and narrowing pair of linear maps with a nonlinearity between them, usually GELU. Both operations are wrapped in a residual connection, which adds the block’s output back to its input, and in layer normalization, which rescales a vector to fixed mean and variance. A final linear map turns the last block’s vectors into logits over the vocabulary.

Two properties follow from that design and matter downstream. Because attention reaches every position directly, the whole sequence is processed in parallel, and a token’s influence on a later token does not have to pass through the intervening steps. Because every block adds to its input rather than replacing it, the vectors flowing through the stack form a residual stream that each block reads from and writes to, which is the picture mechanistic interpretability works in.

The same block is reused everywhere. An autoregressive language model is a decoder-only stack whose attention is masked so a position may only see earlier ones; vision transformers apply the same stack to image patches.

Papers that use this concept

Variants and traps

  • Encoder-only, decoder-only, and encoder-decoder stacks are the same block wired differently, and papers often say “transformer” for whichever they mean. Which one is in play decides whether the model can see later tokens.
  • Matrix multiplication is the cheap part. For cryptographic and hardware backends the binding cost is softmax, GELU, and layer normalization, because each needs comparison, exponentiation, division, or a square root rather than the additions and multiplications those backends do natively.
  • “Attention” names both the operation inside a block and the interpretability artifact people plot. An attention weight says which positions were mixed, and reading it as an explanation of the model’s reasoning is a further claim.

See also

References

  • Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A.N., Kaiser, Ł., and Polosukhin, I. “Attention Is All You Need.” Advances in Neural Information Processing Systems (NIPS), 2017.