Transformer
Also: Transformer architecture, Transformer model, Attention-based model
A Transformer is a neural network architecture that uses self-attention to process sequences in parallel, powering most modern language and generative AI models.
What it is
A Transformer is a deep learning architecture introduced in 2017 in the paper "Attention Is All You Need." It processes sequential data (such as text, code, or audio tokens) using a mechanism called self-attention rather than the step-by-step recurrence used by earlier models like RNNs and LSTMs. This lets it weigh the relationships between all elements of a sequence at once, regardless of how far apart they are.
Why it matters
Before Transformers, sequence models processed tokens one at a time, which was slow to train and weak at capturing long-range dependencies. Transformers changed this by:
- Parallelizing computation: all tokens are processed simultaneously, making training on large datasets and hardware (GPUs/TPUs) far more efficient.
- Scaling well: performance keeps improving as data, parameters, and compute grow, which is the foundation of large language models (LLMs).
- Generalizing across domains: the same core design now powers text, images (Vision Transformers), audio, and multimodal systems.
The Transformer is the backbone of well-known model families such as GPT, BERT, T5, and many open models.
How it works (in brief)
- Tokenization and embeddings: input is split into tokens and mapped to numeric vectors.
- Positional encoding: since attention has no built-in order, position information is added so the model knows token sequence.
- Self-attention: each token computes Query, Key, and Value vectors to decide how much to "attend" to every other token.
- Multi-head attention: several attention computations run in parallel to capture different relationships.
- Feed-forward layers and residual connections: stacked blocks refine the representation, with normalization for stable training.
Variants include encoder-only (good for understanding, e.g. classification), decoder-only (good for generation, e.g. chatbots), and encoder-decoder (good for translation or summarization).
A concrete example
Consider the sentence: "The trophy did not fit in the suitcase because it was too big." A Transformer uses self-attention to link "it" to "trophy" rather than "suitcase," using context from the whole sentence. In practice, a customer support team might fine-tune a decoder-only Transformer on past tickets so it drafts accurate replies, while a finance team might use an encoder model to classify transaction descriptions at scale.