Dashboard

What Is a Transformer Model? A Plain-English Explanation

Transformers replaced older word-by-word models by processing an entire sequence at once through self-attention. Here's what that architectural shift actually explains about context windows, AI costs, and multimodal models.

Cecilia Iona
Cecilia Iona
Senior Editor, AI & Product
20 August 20261 min read

A transformer is a neural network architecture that processes an entire sequence of input, a sentence, a paragraph, an image broken into patches, all at once, using a mechanism called self-attention to work out how every part relates to every other part. That is different from older architectures, which read a sequence one piece at a time, in order, keeping a running summary as they go. Introduced in 2017, the transformer's ability to look at a whole sequence in parallel rather than one step at a time is the specific design choice that made it faster to train and better at handling long, complicated text. It is now the architecture under nearly every major AI model you interact with, and understanding that one design choice explains a lot about how AI models work more generally.

The word-by-word problem transformers solved

Before transformers, the dominant architectures for processing text were recurrent neural networks, including a variant called LSTMs. These are still a type of neural network at their core, so if you want the basics of what a neural network is and how one learns, that groundwork is covered elsewhere. What matters here is how they handled sequences.

A recurrent model reads input one token at a time, updating an internal state as it goes, the way you might read a sentence and keep a mental summary of what you've read so far. To understand word 50, it has already folded words 1 through 49 into that running summary. Two problems fall out of this.

First, it's slow to train. Because word 50 depends on the state produced after word 49, which depends on word 48, and so on, the computation has to happen in order. You cannot hand the whole sentence to a GPU and let it crunch every position simultaneously, because each step needs the previous one's output.

Second, it's forgetful. Information from early in a long sequence has to survive being compressed and re-compressed through dozens or hundreds of steps before it reaches the end. In practice, recurrent models struggled to hold onto relationships between words that were far apart in a passage.

Self-attention was built to fix both problems at once.

Self-attention: reading the whole page, not word by word

Here's a simple way to picture the difference. A recurrent model reads a page one word at a time with a notepad, jotting down a running summary and hoping the important details survive to the end. A transformer instead lays the whole page in front of itself and, for every single word, checks it against every other word on the page simultaneously, asking how relevant each one is to understanding this word right now.

That comparison is what self-attention actually computes. Each token in the input is turned into a set of vectors, and the model uses them to score how much every other token should influence its understanding of the current one. A pronoun can pull in the noun it refers to from three sentences earlier. A closing bracket can immediately connect back to the opening one. None of it depends on information passing sequentially through a chain of steps, so all of those comparisons can happen at the same time, across the whole sequence, on parallel hardware. This is the core idea from the original transformer paper, published by Google researchers in 2017, which proposed dropping recurrence entirely in favor of attention.

That's the actual reason transformers displaced recurrent networks: not that self-attention is a cleverer trick in the abstract, but that it turns a sequential problem into a parallel one, which trains dramatically faster on modern hardware and keeps distant words in reach of each other instead of losing them in a compressed summary.

Why this matters if you're building with AI

The parallel, compare-everything-to-everything design isn't just a training detail. It explains several things you run into directly as soon as you start building with these models.

Why context windows exist

Comparing every token to every other token means the amount of computation grows with the square of how many tokens you feed in. Double the input length and you roughly quadruple the attention computation, not just double it. That's a hard ceiling, not a policy choice: a model has a maximum context window because processing arbitrarily long input eventually becomes computationally impractical, no matter how much hardware you throw at it. When you hit that limit, that's the transformer's architecture showing through directly.

Why longer inputs cost more and take longer

The same math explains your bill and your latency. A prompt with more tokens means more pairwise comparisons for the model to compute, so processing time and cost both climb as your input grows, and they climb faster than linearly. This is also where the KV cache comes in: as a model generates each new token, it reuses stored representations of everything that came before rather than recomputing attention from scratch every time. That cache has to hold something for every token in your context, so a long conversation or a large document pasted into a prompt carries a real memory and compute cost the whole way through, not just at the start. If you're trying to control your AI API costs, understanding this relationship between input length and compute is a reasonable place to start.

Why the same architecture handles text and images

Self-attention doesn't actually know or care whether it's comparing words. It operates on a sequence of vectors, whatever those vectors represent. For text, each vector starts life as a token. For images, a common approach chops the picture into a grid of patches and treats each patch the same way a language model treats a word, as one item in a sequence to be compared against all the others. Feed the model patches instead of tokens and the same self-attention mechanism finds relationships between them, this patch is part of the same object as that patch, this region looks related to that one, without needing a different architecture. That's the practical reason a single underlying design can sit inside multimodal models that read, write, and interpret images, and increasingly audio too, rather than needing a completely separate approach for each type of input.

FAQ

Is a transformer the same as an LLM? Not exactly. A transformer is the architecture, the design for how the model processes sequences. A large language model is a specific application of that architecture, trained on huge amounts of text to predict and generate language. Most current LLMs are built on the transformer architecture, but the architecture itself is more general than any one model.

Why is it called a transformer? The name comes from the original 2017 paper, which described a model that transforms an input sequence into an output sequence using attention mechanisms instead of recurrence or convolution. The name stuck as the architecture became the default choice for sequence tasks.

Do transformers only work on text? No. The same self-attention mechanism works on any input that can be broken into a sequence of vectors, which is why it also powers image models, speech models, and multimodal models that combine several input types in one system.

Why can't a transformer just have an unlimited context window? Because the attention computation grows quadratically with sequence length, an unlimited context window would require an unlimited amount of compute and memory for a single request. Every model ships with a maximum context length as a practical tradeoff, not an oversight.

Are transformers the only neural network architecture still used? No, but they're the dominant one for language, vision, and increasingly audio tasks. Other architectures still show up in specific use cases, but transformers became the default because parallel training scales so much better on modern hardware.

The same architecture also powers image and video generation once paired with a diffusion process, covered in what is a diffusion transformer.

How did this land?

About the author

Cecilia Iona
Cecilia Iona

Senior Editor, AI & Product

Cecilia leads the Swarmz editorial desk. She has spent a decade turning complex AI and product topics into writing people actually finish, and she owns the blog's quality bar.

Share

Get the next post in your inbox

One email a month. Product updates, engineering posts, and the best of Built with Swarmz.

I agree to receive emails about AI building tips and Swarmz product news. Unsubscribe any time.