Skip to content

Transformer

AI glossary

Transformer

A transformer is the neural architecture introduced in the 2017 paper Attention Is All You Need, and by 2026 it is still the backbone of almost every widely used language model. Its central trick is attention: each token can look at other tokens in the sequence, not only at the one that came just before it.

Why attention changed language models

Older recurrent networks read a sequence mostly step by step and had to squeeze history into a single hidden state. Attention lets the model keep a set of vectors and, for each new position, weight the ones that matter. That is how a pronoun can point back to a noun many words earlier, and how a coding model can connect a function name to its definition in the same file.

Transformers also stack many identical layers, and they train well on large batches of text using GPUs. Those two practical facts, as much as the theory, are why labs scaled them into foundation models.

What “encoder” and “decoder” mean here

The original paper used an encoder-decoder setup for translation. Many chat models today are decoder-only: they generate the next token from the tokens so far. Encoder-style stacks still appear in embedding models and some retrieval models, where the job is to represent a passage rather than to write a continuation.

Limits you will still feel

Standard attention cost grows quickly as the context gets longer, which is why long-context serving is expensive and why researchers try sparse, linear, or hybrid designs. A transformer also has no built-in live memory of the world; if a fact is missing from the context and from training, it cannot look it up unless you add a tool.

A concrete example

Example A sentence about “the box in the hall” can let the word “it” attend to “box,” which is how the model keeps references straight.

FAQs about Transformer

Is every LLM a transformer?

Almost every production LLM in wide use is a transformer or a close hybrid. Research on other sequence models continues, but transformer-based stacks are still the default you will meet in APIs and open-weight releases.

Do I need to understand the maths to use one?

No. You do need to understand tokens, context limits, and the fact that the model predicts rather than retrieves, unless you add retrieval yourself.

What should I read if I want the original source?

The paper Attention Is All You Need (Vaswani and co-authors, 2017) is the starting point. Google’s machine learning glossary and the Hugging Face Transformers docs explain the same ideas in more applied language.

Why do long prompts cost more on transformers?

Attention compares tokens across the sequence. A longer prompt means more comparisons, more memory, and usually a higher bill, especially once a provider’s long-context price band kicks in.

Back to the full AI glossary