Skip to content

AI Glossary · Concepts

What is Transformer?

Transformer

A transformer is a neural-network architecture built around attention and feed-forward layers. Attention combines token representations using weights computed from their representations; a mask controls which positions can attend to each other.

Also known as: transformer architecture

· Updated · Chain of Thought

Model ArchitectureAI Infrastructure

  • 1 explainer
  • 3 episodes
  • 1 guest clip
  • 2 sources

The 2017 transformer paper combines attention with feed-forward layers and position information. Token representations are stored in tensors; attention computes weighted combinations of those representations.

For a simplified example, one attention head attending to two allowed positions might assign weights 0.8 and 0.2. Its output is 0.8 × v₁ + 0.2 × v₂, where v₁ and v₂ are their value vectors. These illustrative weights show the weighted sum; actual attention weights depend on the query and keys.

An encoder can use tokens on both sides of a position. A text-generating model such as GPT-2, a generative pre-trained transformer, uses a causal decoder, which processes the current and earlier input positions. During training, the whole sentence may already be available: in “the cat sat on the mat,” the representation at “sat” must predict “on” without reading “on the mat.” A causal mask blocks those future connections.

Full self-attention compares pairs of positions, so its computation scales quadratically with sequence length when other dimensions stay fixed. State-space models offer another approach to sequence processing. A recurrent neural network is the older step-by-step alternative, and a vision transformer applies attention to image patches instead of words.

Liquid AI’s Maxime Labonne describes a hybrid built for on-device language models in the related episode. He says it combines some attention layers with short convolutions.

Try the weighted sum

One head, two allowed positions. Keep their value vectors fixed and change how much each contributes.

v₁ = (1, 2)
v₂ = (3, 0)

0.8 × (1, 2) + 0.2 × (3, 0)

Weighted sum
(1.4, 1.6)

The marked point is the weighted sum. It stays between the two fixed vectors.

These are illustrative vectors and weights. In scaled dot-product attention, query–key scores pass through softmax to produce the weights. This demo starts after that step; the coordinates have no assigned word meaning. See the original paper, section 3.2.1.

Hear it from the guest

“The architecture that we ended up with is a hybrid that has some attention layers.”

Quotes lightly edited to remove filler words.

Sources

Go deeper

From the conversation