Transformer architecture

The transformer is the design (architecture) behind almost every modern language AI. It was introduced by Google researchers in 2017 in a paper called "Attention Is All You Need", and it is the T in GPT. Its big idea is self-attention: instead of reading one word at a time, it looks at all the words together and works out which words relate to each other.

Everyday analogy

Older models read a sentence like passing a message down a line of people, where details get lost along the way. A transformer is like a meeting where everyone can hear everyone at once, so each word can directly check which other words matter to it.

Example

  • Encoder part: understands text. Used by models like BERT (Google search understanding).
  • Decoder part: writes text, one token at a time. Used by GPT, Claude and Gemini.
  • The original 2017 transformer had both, for translation.
🔤Tokenswords becomepieces🔢Embeddings+ position👀Attentionwords look ateach other🧮Feed-forwardprocess eachtoken🔁× manylayersrepeat➡️Next tokenprobabilities
Inside a transformer: tokens go through many layers of attention and processing, ending in a prediction.

Self-attention in action: what does "it" mean?

Theanimaldidn'tcrossthestreetbecauseitwastootired

Here "it" pays most attention to animal, because animals get tired.

Theanimaldidn'tcrossthestreetbecauseitwastoowide

Change one word and "it" now points to street, because streets are wide. Darker colour = more attention.

Inside a transformer, step by step

1. InputYour prompt: "Write a poem about rain"
→
2. TokensText is split into tokens
→
3. Embeddings + positionEach token becomes numbers for its meaning, plus its place in the sentence
→
4. Self-attentionEvery token checks which other tokens matter (many attention "heads" at once)
→
5. Feed-forward layersEach token's meaning is refined. Steps 4–5 repeat in dozens of layers
→
6. Next-token predictionScores every possible next token and picks a likely one
↻
7. RepeatThe new token is added and the loop runs again until the answer is complete

Try it yourself

About 10 min

Find what attention links

  1. Write the sentence: The trophy didn't fit in the suitcase because it was too big.
  2. Ask an AI chatbot what it refers to. Then change big to small and ask again.
  3. Notice how one word changes the meaning of another.

What you should see: Transformers use attention to connect words across a sentence, which is how they work this out.

Use any free AI chatbot (ChatGPT, Claude, Gemini or Copilot). Never paste private or confidential information.

Build it for real · guided projectLook inside a chatbot: tokens, temperature and hallucinationsAbout 45 min · No coding needed · step by step
Test what you learned

Take a quick quiz, or look up any word in the glossary.