# Transformer

> The Transformer is a neural network architecture based on the attention mechanism, used by modern language models.

## What is a transformer in AI?

The neural network architecture that processes whole sequences in parallel using the attention mechanism. It is the basis of LLMs and is also used for images, audio and code.

- Topic: Training & Architecture
- Type: architecture

## Interview questions

### Why did transformers replace RNNs?

Transformers process all tokens in parallel with attention, which trains much faster on GPUs and handles long-range links in text better than RNNs.

### Are all LLMs transformers?

Most current LLMs are based on the transformer, though other architectures, like state space models, are also being explored.

### What is the difference between encoder and decoder transformers?

Encoders read the whole input to build representations, useful for classification and embeddings. Decoders generate text token by token, as chat LLMs do.

## Related cards

- [Attention](https://wonderium.dev/ai/attention.md)
- [LLM](https://wonderium.dev/ai/llm.md)
- [Token](https://wonderium.dev/ai/token.md)
- [Mixture of Experts](https://wonderium.dev/ai/mixture-of-experts.md)
- [Context Window](https://wonderium.dev/ai/context-window.md)

---

- Level: [Artificial Intelligence](https://wonderium.dev/ai.md)
- HTML version: https://wonderium.dev/ai/transformer
- Last updated: 2026-11-25
