Transformer

“Attention Is All You Need”

Definition

The Transformer is a neural network architecture introduced in 2017 in the paper “Attention Is All You Need”. It processes sequences with self-attention instead of recurrent layers.

What for?

Self-attention captures relations between all positions of a sequence and parallelises well. Today's language models such as GPT are built on it.

Technical architecture

flowchart TB
  IN[Input tokens] --> EMB[Embeddings + positional encoding]
  EMB --> MHA[Multi-head self-attention]
  MHA --> AN1[Add and norm]
  AN1 --> FF[Feed-forward network]
  FF --> AN2[Add and norm]
  AN2 -->|repeat N layers| MHA
  AN2 --> OUT[Output probabilities]

Core components

Self-attention
Each token weighs how important the other tokens are for its meaning.
Multi-head attention
Several attention heads capture different relations in parallel.
Positional encoding
Adds information about the order of tokens.
Feed-forward layer
Processes each position further; residual connections and normalisation stabilise training.

Practical examples

  • In “the bank of the river”, attention helps read “bank” as a riverside.
  • Translation models use the encoder and decoder of the original Transformer.

Enterprise use cases

  • Language models
  • Machine translation
  • Vision and speech models (e.g. Vision Transformer)

Quiz

1. In which paper was the Transformer introduced?

2. What is an advantage of self-attention over RNNs?

3. What is positional encoding for?

Related news