Bookmarks

Transformer

A neural network architecture that processes a whole sequence at once and relates its elements through an attention mechanism rather than one by one.

Also: transformer architecture, transformer architecture, transformer neural network

checked 18 Nov

All terms

The transformer underlies modern language models and many models for images and audio. It repeats the same block many times: in each block an attention layer lets tokens exchange information, while a feed-forward network processes each token separately.

What a block consists of

  • attention: each token compares itself with the others and gathers what it needs from them; several “heads” do this in parallel and look at different relationships;
  • feed-forward network (MLP): transforms each token’s vector independently of its neighbours;
  • residual connections and normalisation: around each of the two parts, so that a deep network can be trained;
  • positional information: attention itself does not distinguish token order, so position is added separately.

In the original paper the stack consisted of N = 6 identical layers with a vector dimension of 512. Large modern models have dozens of layers and dimensions in the thousands.

Three variants

VariantHow it reads textExamples
Encoder onlyeach token sees the whole text in both directionsBERT
Decoder onlya token sees only the preceding ones; the model predicts the next tokenLlama, Gemma, Qwen
Encoder and decoderthe encoder reads the input, the decoder writes the output and refers back to itthe original transformer, T5

Most modern language models are decoder only. The architecture was proposed by Ashish Vaswani and co-authors in the paper “Attention Is All You Need” in 2017; they tested it on machine translation.

Sources

the term is written from these pages

Verified 18 Nov

Not to be confused with

what it is mixed up with and how it differs

  • LLMlarge language model

    An LLM is a class of models defined by purpose, while the transformer is the architecture they are usually built on.

  • attention mechanism

    Attention is a single mechanism inside a block, while the transformer is the whole network made of such blocks.

In depth in the references

where the topic is covered in detail

Appears in the references