AI Glossary / Generative AI and language / Intermediate
Transformer
Definition
A Transformer is a neural-network architecture built around attention mechanisms that combine information from different positions in an input. Standard Transformer blocks also include feed-forward transformations, residual connections, and normalization. Introduced for sequence-to-sequence tasks, the architecture became a foundation for many language and other AI systems. A Transformer is an architectural family, not a specific chatbot, training dataset, or guarantee of intelligent behavior.
What it means
Language depends on relationships between words and their context. A Transformer represents input units as vectors and repeatedly updates them using information from other permitted positions. This allows a representation to reflect surrounding content rather than only the isolated token.
The original architecture used an encoder and decoder for tasks such as translation. Later models use encoder-only, decoder-only, and encoder-decoder arrangements for different objectives. These arrangements share important ideas but do not have identical information access or output behavior.
Transformers can also process representations of image patches and other data. Calling a model a Transformer therefore does not, by itself, tell you whether it generates text or what tasks it was trained to perform.
How it works
Input tokens are converted to vector representations, with positional information supplied so the system can distinguish order. Attention computes relationships between queries and keys, then uses the resulting weights to combine value vectors. Multiple attention heads provide separate learned projections for these calculations.
Feed-forward layers transform each position's representation. Residual connections carry information around sublayers, and normalization helps manage the numerical behavior of the stacked network. The precise ordering and implementation vary across models.
An output head converts the resulting representations into the form required by the task. In a causal language model, a mask prevents a position from reading future tokens during next-token prediction. Parallel processing of positions during training does not mean an ordinary autoregressive generator emits an entire new answer in one independent step.
Three practical examples
1. A translation system uses an encoder-decoder Transformer to relate a source sentence to a generated sentence in another language.
2. A text-classification system uses contextual representations from an encoder to assign a document to a category.
3. A vision system supplies image-patch representations to Transformer layers before producing a classification or another task-specific output.
Think of it this way
Think of a team revising a set of notes through several rounds. Each round lets a note incorporate selected information from other notes, then refines its own contents before the next round.
The analogy has limits. The network manipulates vectors rather than human-readable notes, and attention weights are learned numerical relationships rather than conscious focus. The architecture can combine context without guaranteeing that the final conclusion follows logically or accurately from it.
Worked example
Consider a simplified attention step at one position. Three permitted value vectors are represented by single numbers 4, 10, and 16, with attention weights 0.2, 0.5, and 0.3. Their weighted combination is 0.2 × 4 + 0.5 × 10 + 0.3 × 16 = 10.6.
This shows how information from multiple positions can influence one output representation. If the third position were forbidden by a causal mask, its contribution would be excluded and the weights over permitted positions would be calculated accordingly.
The example deliberately omits query-key score calculation, multidimensional projections, additional heads, and the rest of the block. The number 10.6 is not a word probability or a confidence score. A complete Transformer applies many such learned operations before its task-specific output is produced.
Illustrative case study
Fictional case: Alder Archive wants to classify short historical descriptions. The team considers a Transformer encoder because category clues can depend on surrounding phrases rather than isolated keywords.
It compares the candidate with a simpler baseline on a separated evaluation set, including descriptions with ambiguous words and unusual names. It records classification errors, runtime, and memory requirements before deciding whether the added complexity is useful.
This fictional decision illustrates evaluating an architecture in context. It does not assume that a Transformer is always the best choice or that success on one document collection transfers automatically to another.
Common misconceptions and mistakes
Do not equate “Transformer” with “large language model.” Some Transformers are small, serve non-language tasks, or do not generate text.
Do not describe attention as a complete explanation of an answer. It is one computation within a larger network, and a visible weight does not by itself establish causal importance for the final prediction.
Avoid assuming all positions can always communicate freely. Masks and architecture choices constrain information flow. Also avoid claiming that the architecture eliminates factual errors, bias, or the need for suitable training and evaluation data.
Business use
The term helps a business team understand the broad design of a proposed AI system, but architecture alone is insufficient for selection. Ask what task the model was trained for, what inputs it supports, how long-context behavior was evaluated, and what resources deployment requires.
Compare end-to-end performance with the actual workload. A model's ability to represent contextual relationships matters only if the implemented system uses them effectively for the intended task and meets its operational constraints.
People also ask
Are Transformers only for language?
No. They can process suitable representations of images and other data, although the input preparation and training objectives differ.
Is every Transformer an encoder-decoder model?
No. The original architecture used both, but encoder-only and decoder-only designs are also common.
Does attention mean the model understands like a person?
No. Attention is a numerical mechanism for combining representations. Human-like language does not establish human-like understanding or experience.
Check your understanding
A model uses Transformer layers to classify images. Must it also be able to answer questions in natural language?
Answer: No. Its input representation, training objective, and output head determine its supported task. Sharing an architectural family does not give every model the same capabilities.
Related terms
- Self-attention
- Multi-head attention
- Encoder
- Decoder
- Positional encoding
- Feed-forward network
- Transformer block
- residual connection
- causal mask
Learn next
Learn self-attention and positional information next. Then compare encoder-only, decoder-only, and encoder-decoder systems by tracing which inputs each position can access and what the training objective asks the output head to predict.
More in Generative AI and language
- Tokenizer - A tokenizer is the component that converts text into the token units and numerical identifiers expected by a language-processing system.
- Top-k sampling - Top-k sampling is a text-generation method that limits each next-token draw to the k highest-scoring candidate tokens.
- Top-p sampling - Top-p sampling, also called nucleus sampling, generates text by sampling from the smallest leading set of next-token candidates whose cumulative probability...
- Transformer Language Model - A Transformer Language Model is a language model that uses Transformer layers to build contextual token representations and make language predictions.
- Transformer Network - A Transformer Network is a neural network assembled from Transformer-style components, especially attention and feed-forward layers that build contextual...
- Undersampling - Undersampling reduces the number of training examples from selected groups, commonly an overrepresented class, to change the balance of a dataset.
Sources
Vaswani and colleagues, Attention Is All You Need: https://arxiv.org/abs/1706.03762 and https://arxiv.org/pdf/1706.03762
Jurafsky and Martin, Transformers and Pretraining: https://web.stanford.edu/~jurafsky/slp3/7.pdf
Primary architecture descriptions and the textbook's block and masking discussion were read. The scalar attention calculation and Alder Archive case are original teaching material. Modern implementations can differ from the original architecture.
Previous: Transform coding Next: Transformer Language Model