What is a transformer? The architecture behind every modern LLM | AI Terms Guide
AI Explainers

What is a transformer? The architecture behind every modern LLM

GPT, Claude, Gemini, Llama — every modern large language model is built on the transformer architecture. If you want to understand how LLMs actually work, the transformer is the one concept to learn. Here's the plain-English explainer.

SK
Sana K. October 25, 2026 · 10 min read

If you've read anything about AI in the past few years, you've seen the word "transformer" — probably without a clear sense of what it means. It's not a product, not a company, not a model. It's an architecture: a specific way of structuring the mathematical operations inside a neural network. And it's the architecture behind essentially every major LLM in use today. GPT-5 is a transformer. Claude Opus is a transformer. Gemini, Llama, Mistral, DeepSeek — all transformers. The architecture was introduced in 2017 and reshaped the entire field within five years.

This post explains what the transformer is in plain English, why it works, and why it took over AI so completely. No math beyond what's necessary; no code required. By the end, you'll have a mental model of what's actually happening when an LLM reads your prompt and generates a response.

The problem transformers solved

To understand why the transformer mattered, understand what came before it.

Before transformers, the dominant architecture for language tasks was the recurrent neural network (RNN), and its improved variant the LSTM. These processed text one word at a time, in order. Each word's processing depended on what came before, like reading a sentence left-to-right.

This sequential approach had two big problems:

It was slow. Processing one word at a time meant you couldn't parallelize across words. On modern hardware (GPUs, designed for massive parallelism), this was wasteful. Training large RNNs took forever.

It forgot context. By the time an RNN finished processing the end of a long paragraph, it had largely "forgotten" the beginning. The information had passed through so many sequential steps that early content lost influence. For long-range dependencies — understanding how word 50 relates to word 2 — RNNs struggled.

Various fixes were attempted. None fundamentally solved the problem. The whole field was waiting for an architecture that could process text in parallel AND handle long-range relationships well.

What the transformer did differently

In 2017, a Google research team published a paper titled "Attention Is All You Need." The paper introduced the transformer architecture. The core innovation: instead of processing words sequentially, the transformer looks at all words at once, with a mechanism that lets each word "attend to" every other word in the input.

This had two immediate benefits:

Parallelism. Since all words are processed simultaneously, GPUs can crunch through text much faster. Training is dramatically more efficient per hour of compute.

Direct access to any word. When processing word 50, the model can directly consider word 2 (or word 500) without that information passing through intervening steps. Long-range relationships become easy.

These two properties, together, meant transformers could learn from more text, learn richer patterns, and scale up to sizes RNNs could never reach. The field flipped from RNNs to transformers in a couple of years. Every major language model since 2020 has been a transformer.

The core idea: attention

The "attention" in "Attention Is All You Need" is the key mechanism. Here's what it does, in plain English:

For each word in the input, the attention mechanism asks: which other words in this input are relevant to understanding this word? It computes a weighted combination — a weighted mix of all the other words' meanings, with weights determined by how relevant each one is.

A simple example. Consider the sentence: "The dog chased the cat because it was hungry."

What does "it" refer to? Grammatically, "it" could be the dog or the cat. Humans use context to figure out "it" probably means "the dog" (because dogs chase things when they're hungry). An attention mechanism learns to make this kind of connection — when processing "it," it attends more heavily to "dog" than to "cat," producing a representation of "it" that incorporates information from "dog."

Attention learns these patterns from massive amounts of text. After training on billions of sentences, the attention mechanism has internalized which word relationships matter in which contexts.

Importantly, every word gets this treatment in parallel. The model isn't marching through the sentence; it's considering all word-to-word relationships at once.

Self-attention and multi-head attention

The specific attention mechanism in transformers is called self-attention, because the input attends to itself — each word in the input relates to other words in the same input.

Transformers don't do this just once per layer. They do it multiple times in parallel, with each "attention head" learning different kinds of relationships. This is called multi-head attention.

You can think of each attention head as asking a different question about the relationships between words. One head might learn to track subject-verb relationships. Another might track pronoun antecedents (like our "it" example). A third might focus on topical connections across the sentence. By combining many heads, the model captures many kinds of linguistic patterns simultaneously.

Modern transformer models have dozens of attention heads per layer, and dozens of layers. Each layer builds on the previous one's output, producing progressively richer representations. By the top layers, each word's representation incorporates meaning from potentially every other word in the input, filtered through many kinds of learned relationships.

The full transformer, in rough shape

Zooming out, a transformer is a stack of layers, each layer doing roughly the same thing:

  1. Multi-head self-attention. Each word attends to every other word, producing a context-aware representation.
  2. Feed-forward network. A standard neural network transforms each word's representation independently, extracting features.
  3. Residual connections and normalization. Mathematical plumbing that keeps the training stable as the model gets deeper.

A small transformer might have 6 of these layers; a large one might have 80 or more. Information flows upward through the stack, with each layer adding more sophisticated understanding.

Modern LLMs are decoder-only transformers (one of a few variants from the original paper) with layer counts and parameter counts that have grown dramatically — from GPT-1's 117 million parameters in 2018 to models with hundreds of billions of parameters today.

The three-sentence summary

A transformer processes text by letting every word attend to every other word in parallel. Each layer refines the representations through multi-head attention plus a feed-forward network. Stacking many layers produces increasingly sophisticated understanding, which is what makes modern LLMs possible.

Why transformers scale so well

Beyond their immediate benefits, transformers turned out to have one property that reshaped the field: they scale smoothly. Making a transformer bigger — more parameters, more training data, more compute — reliably produces a better model. This isn't true of all architectures; some get diminishing returns or hit walls.

The predictability of transformer scaling led to the "scaling laws" research of 2020–2022, which showed that model capability improves in a predictable way as you add parameters and training data. Companies could invest confidently in building bigger models because they could estimate roughly how much better the next model would be before training it.

This scaling behavior is why we went from GPT-2 (1.5B parameters, mediocre) to GPT-5 (hundreds of billions of parameters, dramatically more capable) in a few years. The architecture didn't fundamentally change; the scale did, and transformers kept getting better at scale.

No prior architecture would have supported this kind of scaling. Transformers were the right structure to ride the GPU wave and the massive-data wave into the modern era of AI.

Variants: encoder, decoder, encoder-decoder

The original transformer paper actually described a specific setup for machine translation, with an encoder (processes the input language) and a decoder (generates the output language). Modern LLMs typically use only one of these halves:

Decoder-only transformers. Used by GPT, Claude, Llama, most LLMs you've heard of. These are generative — they take a prompt and produce text continuation. Best for conversational AI, writing, code generation.

Encoder-only transformers. Used by BERT and models for classification/understanding. These produce rich representations of input text, useful for tasks like search, classification, or extracting meaning.

Encoder-decoder transformers. The original setup. Used in translation (T5, BART) and some multimodal models. Takes input, encodes it, then generates output based on the encoding.

For general-purpose AI assistants and the models most people interact with, decoder-only is the dominant pattern as of 2026. That's what you're using when you talk to Claude, GPT, or Gemini.

What transformers don't do (that people often think they do)

Three common misconceptions worth clearing up:

They don't "understand" text the way humans do. Transformers learn statistical patterns in text — which words tend to follow which, in which contexts. This produces outputs that look remarkably coherent and often are correct, but it's not comprehension in a human sense. The model doesn't have beliefs or awareness; it has learned patterns.

They don't reason step-by-step unless prompted. A transformer generates one token at a time, each informed by all the tokens before it. "Reasoning" in LLMs emerges from the model being prompted or trained to produce intermediate steps (chain-of-thought). Without that, it's more pattern-matching than reasoning.

They don't have a knowledge "database." Everything a transformer knows is encoded in its parameters, which are learned during training. There's no lookup table or database inside. When a model gives you a fact, it's reconstructing it from learned patterns, not retrieving it from storage. This is why hallucinations happen — the pattern-reconstruction can be plausible-sounding but wrong.

Understanding these limitations helps you use LLMs well. They're extraordinarily capable pattern-processors — they're not oracles, databases, or minds.

Why transformers specifically, and not other architectures

After eight years of transformers dominating AI, researchers have proposed alternatives — Mamba, state-space models, retrieval-augmented hybrid architectures. Some show promise. None have displaced transformers at the frontier.

Three reasons transformers have been so sticky:

Enormous accumulated investment. The AI industry has spent years optimizing transformer training — specialized hardware, software stacks, scaling techniques. Switching architectures means abandoning that investment.

Scaling behavior. Transformers scale predictably. Alternative architectures often match or beat transformers at small scales but haven't demonstrated the same reliable scaling to the sizes current frontier models reach.

Flexibility. The same transformer architecture handles text, images, audio, video, code, and more. This versatility makes it the general-purpose workhorse of the field.

Someday, a successor architecture may emerge. For now and the near future, transformers remain the architecture everyone else measures themselves against.

Attention is a mechanism for letting every word in a sentence consider every other word simultaneously. Stack that mechanism in layers, train on enough text, and modern AI emerges.

Related concepts worth knowing

If you're building a mental model of modern AI, these related concepts fit directly on top of the transformer:

Attention mechanism: The specific mechanism inside the transformer, in more depth.

Large language model (LLM): A transformer trained at scale on text to produce fluent language. Every well-known LLM is a transformer underneath.

Foundation model: A broader term for large pretrained models (including LLMs) used as a starting point for downstream tasks. Mostly transformers today, though not required to be.

Tokenization: How text gets broken into pieces (tokens) before the transformer processes it. Not part of the transformer itself, but tightly connected in practice.

Context window: How much text a transformer can consider at once. Determined by model architecture and training; a key practical limit when working with LLMs.

A short history, for context

The transformer's arrival in 2017 is often described as a "moment" in AI history, and it genuinely was. A quick timeline for perspective:

2017: "Attention Is All You Need" paper published. Introduces the transformer for machine translation.

2018: BERT (encoder-only transformer) achieves state-of-the-art on language understanding benchmarks. GPT-1 (decoder-only transformer) shows generative capability.

2019–2020: GPT-2, GPT-3 show that scaling transformers produces dramatic capability improvements. Scaling laws research formalizes this.

2022: ChatGPT (GPT-3.5-based) brings transformers into public awareness. Suddenly everyone has used one.

2023–2026: The transformer era in full swing. Claude, Gemini, Llama, Mistral, DeepSeek, countless others — all transformers. The architecture has barely changed; what's changed is scale, training recipes, and the ecosystem around them.

From "obscure architecture in a research paper" to "the architecture behind every AI product you've heard of" in less than a decade. One of the fastest paradigm shifts in computing history.

The takeaway

The transformer is the architectural idea that made modern AI possible. It processes language (and other sequence data) by letting every token attend to every other token in parallel, through multiple layers of refinement. This parallelism plus the attention mechanism's ability to capture long-range relationships gave transformers the scaling properties that drove the AI revolution of the 2020s.

You don't need to understand the matrix math to understand why transformers matter. The core intuition — attention lets each word consider all other words at once — captures most of what you need. From that foundation, every modern LLM concept (context windows, scaling laws, attention bottlenecks, the whole thing) becomes easier to understand.

If you learn one AI architecture, learn this one. It's the structure under every model you're using when you talk to ChatGPT, Claude, or Gemini — and will likely remain so for the next several years at minimum.

SK

Written by

Sana K.

Sana covers AI evaluation, benchmarks, and the methods teams use to measure whether their AI systems actually work.