# What is a transformer in AI? Attention explained simply · AI in Bed

https://www.aiinbed.com/blog/what-is-a-transformer · Published 2026-11-25

**Short answer:** A transformer is a type of neural network, introduced in the 2017 paper "Attention Is All You Need", that powers almost every modern large language model. Its key idea is attention: for every word, the model looks at all the other words in the text and decides which ones matter most for understanding it. Because it processes all the words at once instead of one by one, it trains fast on huge amounts of data.

### The problem transformers solved

Language is full of references. In "The trophy didn't fit in the suitcase because **it** was too big", you know "it" is the trophy. Change "big" to "small" and "it" becomes the suitcase. Understanding a word means looking at the right other words, sometimes far away.

Before 2017, the best language models were recurrent neural networks that read text one word at a time, carrying a running summary. They were slow to train, because each step waited for the last, and they tended to forget details from far back.

### Attention, in plain English

[Attention](https://www.aiinbed.com/glossary/attention) lets every word look directly at every other word and pull in information from the ones that matter. For each word the model asks, roughly: "which other words help me understand this one, and how much?"

Under the hood each word, as an [embedding](https://www.aiinbed.com/glossary/embedding), produces three vectors:

- a **query**: what I'm looking for,
- a **key**: what I contain, for others to match against,
- a **value**: the information I'll pass on if chosen.

Each word's query is compared with every key to get attention scores, the scores become weights that add up to 1, and the word takes a weighted mix of the values. So "it" can put most of its attention on "trophy" and absorb that meaning. When the words attend to others in the same text, it's called **self-attention**.

See it move in the [transformers lesson](https://www.aiinbed.com/learn/advanced/transformers), which has an attention demo.

### Inside a transformer

1. **Tokens in.** Text is split into [tokens](https://www.aiinbed.com/glossary/token) and each becomes an embedding. Position information is added so the model knows word order. See [what are tokens](https://www.aiinbed.com/blog/what-are-tokens-in-ai).
2. **Multi-head attention.** Several attention "heads" run side by side, each free to track a different kind of relationship, such as grammar, references or topic.
3. **Feed-forward layer.** A small neural network processes each position on its own, where much of the model's stored knowledge is thought to live.
4. **Repeat.** These blocks are stacked dozens of times. Each layer refines the meaning a bit more.
5. **Predict.** At the end, the model scores every token in its vocabulary for what comes next.

Models like GPT, Claude, Llama and Gemini use the "decoder" style, where each token can only attend to earlier ones, which suits writing text left to right. That's the loop described in [how ChatGPT works](https://www.aiinbed.com/blog/how-does-chatgpt-work).

### Why transformers took over

- **Parallel training.** All tokens are processed at once, which suits GPUs and made training on trillions of tokens practical.
- **Long-range understanding.** Any word can connect directly to any other, however far apart.
- **They scale.** Bigger transformers trained on more data kept getting better, which led to today's [LLMs](https://www.aiinbed.com/glossary/llm).
- **Not just text.** The same design works for images (vision transformers), audio, code, proteins and [multimodal](https://www.aiinbed.com/glossary/multimodal) models.

> The catch: attention compares every token with every other, so cost grows quickly with length. Tricks like the [KV cache](https://www.aiinbed.com/glossary/kv-cache) and [mixture of experts](https://www.aiinbed.com/glossary/mixture-of-experts) help keep big models affordable.

### Key takeaways

- The "T" in GPT stands for transformer.
- Attention lets each word gather meaning from the words most relevant to it.
- Transformers stack many layers of attention plus small feed-forward networks.
- Processing in parallel made it possible to train on internet-scale text.

### Questions

**What does GPT stand for?**

Generative Pre-trained Transformer: a model that generates text, is pretrained on a large amount of data, and uses the transformer architecture.

**What is attention in AI?**

Attention is a mechanism that lets a model weigh how relevant every other part of the input is when processing each part. It lets each word take in meaning from the words that matter most to it.

**What is the difference between attention and self-attention?**

Self-attention is attention where the words of one text attend to each other. Attention can also connect two different sequences, such as a sentence and its translation.

**Who invented the transformer?**

A team at Google, in the 2017 paper "Attention Is All You Need" by Vaswani and colleagues. It was first designed for translation.

### Sources

- [Attention Is All You Need](https://arxiv.org/abs/1706.03762) by Vaswani et al., 2017
- [The Illustrated Transformer](https://jalammar.github.io/illustrated-transformer/) by Jay Alammar
- [Neural networks (includes transformers)](https://www.3blue1brown.com/topics/neural-networks) by 3Blue1Brown
- [Let's build GPT: from scratch, in code, spelled out](https://www.youtube.com/watch?v=kCc8FmEb1nY) by Andrej Karpathy
