What is a transformer in AI?
A transformer is a neural network built on attention. Google researchers introduced it in 2017, and BERT, GPT-3 and most current LLMs use it.
In short. A transformer is a neural network architecture that relates every token in a text to every other token through attention. Google researchers introduced it in the 2017 paper Attention Is All You Need, for machine translation. It drops the step-by-step reading of earlier networks, so training runs in parallel. BERT, GPT-3 and most current large language models are transformers.
On this page 7 sections
The evidence
The Transformer is based only on attention mechanisms, with no recurrence and no convolutions. The paper that introduced it was submitted to arXiv on June 12, 2017.1
1arXivarXiv, Jun 12, 2017. Last revised Aug 2, 2023.The base model in the paper stacks 6 encoder layers and 6 decoder layers. Each layer has multi-head attention with 8 heads and a feed-forward network.1
1arXivarXiv, Jun 12, 2017. Section 3 of the paper.The Transformer scored 28.4 BLEU on the WMT 2014 English-to-German translation task, more than 2 BLEU above the best earlier results, including ensembles.1
1arXivarXiv, Jun 12, 2017. Machine translation benchmark.The large language models that write AI search answers are transformers, and Google has used transformer models in Search since 2019, when it said BERT would help Search understand one in 10 searches in the US in English.
A transformer is a type of neural network that processes a whole sequence of tokens at once. For each token, it computes how much every other token in the input should affect it. This mechanism is called attention, and the transformer is built almost entirely from it.
#Origin
Google researchers introduced the architecture in Attention Is All You Need, submitted to arXiv on June 12, 2017. The abstract proposes the Transformer as an architecture "based solely on attention mechanisms, dispensing with recurrence and convolutions entirely."1
Earlier language models were mostly recurrent networks, which read a text one token at a time. The paper says this sequential design prevents parallel computation within a training example, a limit that grows with sequence length. The Transformer removed that step, and the paper reports state-of-the-art translation quality after 12 hours of training on eight GPUs.1
What did the Attention Is All You Need paper introduce? covers the history that followed, from BERT to ChatGPT, Claude and Gemini.
#How a transformer works
The paper describes an attention function as a mapping from a query and a set of key-value pairs to an output. The output is a weighted sum of the values. Each weight comes from how well the query matches the corresponding key.1
In self-attention, the queries, keys and values all come from the same sequence. In the encoder, each position can attend to every position in the previous layer. Multi-head attention runs several attention functions in parallel, 8 in the base model. The paper says this lets the model attend to information from different representation subspaces at once.1
The original model has two stacks of 6 identical layers:
- The encoder maps the input tokens to a sequence of representations. Each encoder layer has a self-attention sublayer and a feed-forward network.
- The decoder generates the output one token at a time. It adds a third sublayer that attends to the encoder's output.
- A mask in the decoder stops each position from attending to later positions, so a prediction depends only on earlier tokens.
Attention by itself does not use word order. The paper adds positional encodings, built from sine and cosine functions, to the input embeddings so the model can use the order of the tokens.1
#Encoder and decoder models
Later models often use one half of the original design. BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding, submitted in October 2018, describes BERT as a multi-layer bidirectional Transformer encoder. BERT uses the context on both sides of each token. Its larger version has 24 layers and 340 million parameters.2
The BERT paper contrasts this with OpenAI GPT, a left-to-right Transformer in which every token can attend only to earlier tokens.2 This design suits text generation, because the model predicts each next token from the tokens before it. Language Models are Few-Shot Learners describes GPT-3 as an autoregressive language model with 175 billion parameters, built on the same architecture as GPT-2.3
How do large language models work? explains how such a model predicts text from its context window, one token at a time.
#Transformers in search
Transformer models were part of web search before chat assistants. Google announced the change on October 25, 2019, in Understanding searches better than ever before. Google had started to apply BERT models to ranking and featured snippets, and it described transformers as models that process words in relation to all the other words in a sentence. It said BERT would help Search understand one in 10 searches in the US in English.4
AI search products write their answers with large language models, which are transformers. A model reads the retrieved passages and the question in its context window and attends across all of them. What are vector embeddings? covers how transformer-based models also turn text into vectors for retrieval.
Read next
LLMs
What did the Attention Is All You Need paper introduce?
The 2017 Google paper Attention Is All You Need introduced the Transformer, the architecture behind ChatGPT, Claude, Gemini and AI search.
LLMs
How do large language models work?
LLMs predict text one token at a time from what fits in their context window. Tokens, context window sizes and the lost-in-the-middle effect.
LLMs
What are tokens in AI?
A token is the unit of text a language model reads and writes. OpenAI estimates that 100 tokens are about 75 English words. Counts and limits by provider.
LLMs
What are vector embeddings?
A vector embedding is a list of numbers that represents the meaning of text. OpenAI's text-embedding-3-large returns 3,072 of them by default.
Questions
What is the difference between a transformer and a large language model?
A transformer is an architecture, a design for a neural network. A large language model is a trained model that predicts text. Most current large language models use the transformer architecture and are trained on large amounts of text.
What are encoder and decoder transformers?
The original Transformer has an encoder, which turns the input into representations, and a decoder, which generates the output one token at a time. BERT uses only the encoder. OpenAI's GPT models use a left-to-right transformer, in which each token can attend only to the tokens before it.
Why does a transformer need positional encodings?
Attention by itself does not use word order. The paper adds positional encodings, built from sine and cosine functions, to the input embeddings. They give the model information about the position of each token.
Notes
- 1
- 2
- 3
- 4
About this page
Researched and reviewed by Promptly Found. Reviewed Nov 20, 2026. Next review due Feb 2027.
Cite this page
Promptly Found. (2026, November 20). What is a transformer in AI? https://promptlyfound.com/glossary/transformer
Revisions 1
- First published.