# Transformer

> A transformer is the neural network design behind nearly all modern language models, which processes a sequence of tokens by letting each one weigh its relationship to every other through a mechanism called attention.

Also called: transformer architecture, transformer model, attention mechanism, self-attention. Category: Models and training. Source: https://aibuildindex.com/glossary/transformer

## In the index

- Deep learning: median $3,000, middle half $400 to $9,900, 1,501 priced briefs (https://aibuildindex.com/skills/deep-learning)
- Natural language processing: median $3,000, middle half $500 to $9,440, 1,428 priced briefs (https://aibuildindex.com/skills/natural-language-processing)

The transformer is the architecture that made today's AI boom possible. Introduced by Google researchers in 2017 in a paper titled "Attention Is All You Need", it replaced older designs that read text one word at a time. Language models, many image models, speech models and [embedding](https://aibuildindex.com/glossary/embedding) models are all built on it. A business buyer does not need to understand its mathematics, but knowing what it is helps make sense of terms such as tokens, context windows and attention that come up in technical conversations.

## How it works

A transformer takes a sequence of [tokens](https://aibuildindex.com/glossary/token) and turns each into a vector of numbers. It then passes them through many stacked layers. The key ingredient in each layer is attention: for every token, the model calculates how much each other token in the sequence matters to it, and blends their information accordingly. In the sentence "the bank raised its rates", attention lets "its" connect to "bank" and helps "bank" take its financial meaning.

Because attention looks at all tokens together rather than one after another, transformers can be trained efficiently on very large amounts of data using graphics processors. That scalability is why model sizes, and capabilities, grew so quickly.

There are a few main variants:

- **Decoder models**, used by most chat and text-generation models, predict the next token.
- **Encoder models** produce representations of input text and are common for classification and embeddings.
- **Encoder-decoder models** read an input and generate an output, a design used in some translation systems.

The cost of attention grows quickly as sequences get longer, which is one reason [context windows](https://aibuildindex.com/glossary/context-window) have limits and why long inputs are slower and more expensive.

## What it means for cost

Buyers rarely pay for transformer work directly, since builds use models that providers have already trained. The architecture still explains several cost behaviours: longer inputs cost more to process, larger models need more expensive hardware to run, and output is generated one token at a time, which sets limits on speed.

If a builder proposes designing or training a new transformer model rather than using an existing [foundation model](https://aibuildindex.com/glossary/foundation-model), ask why. That is research-scale work and only justified for unusual data or requirements.

## Common questions

### Is every AI model a transformer?

No. Many practical machine learning models, such as those used for forecasting or fraud scoring, use other methods. But most modern language, image and speech models are transformers or closely related designs.

### Why does the word "attention" come up so often?

Attention is the mechanism that lets a transformer relate each part of the input to every other part. It is the defining feature of the architecture and the reason it handles context well.

### Will transformers be replaced?

Researchers are exploring alternative and hybrid designs, especially for very long inputs. For now transformers remain the standard, and business builds are unaffected because they use models through stable interfaces.

## Related terms

- [Large language model (LLM)](https://aibuildindex.com/glossary/large-language-model): A large language model is an AI model trained on very large amounts of text to predict the next word, which lets it write, summarise, translate, classify and answer questions in natural language.
- [Foundation model](https://aibuildindex.com/glossary/foundation-model): A foundation model is a large AI model trained on broad data that can be adapted to many different tasks, such as writing, coding, image understanding or classification, rather than built for one job.
- [Token](https://aibuildindex.com/glossary/token): A token is the small unit of text, often a word or part of a word, that a language model reads and writes, and the unit that most AI providers use to measure and bill usage.
- [Context window](https://aibuildindex.com/glossary/context-window): A context window is the maximum amount of text, measured in tokens, that a language model can take in and produce in a single request, including instructions, documents, conversation history and its own reply.
- [Embedding](https://aibuildindex.com/glossary/embedding): An embedding is a list of numbers that represents the meaning of a piece of text, an image or another item, so that items with similar meanings end up close together and can be compared, searched or grouped by software.
