GlossaryTransformer
Transformer
A transformer is a neural network architecture that processes a sequence, such as the tokens of a sentence, by letting every element weigh its relationship to every other element through a mechanism called attention. It is the architecture behind most large language models and many vision, speech and multimodal models.
How it works
Input is first split into tokens and each token is turned into a vector, its embedding, with information added about its position. The model then runs the vectors through a stack of identical layers. In each layer, self-attention compares every token with every other token and mixes in information from the ones most relevant to it. A feed-forward network then transforms each token's vector on its own. After many layers, each vector carries context from the whole sequence.
The original transformer, introduced for machine translation, had an encoder that reads the input and a decoder that writes the output. Encoder-only models, such as those used for classification and embeddings, read text in both directions. Decoder-only models generate text one token at a time, each prediction attending to everything before it, which is how most large language models work. Many large models use a mixture-of-experts design, in which a router sends each token through only a few of many feed-forward sub-networks, so the total parameter count grows without the compute per token growing with it.
Attention compares all pairs of tokens, so its cost grows with the square of the sequence length. That is a main reason context windows have limits and why long prompts are slower and costlier.
Transformer vs recurrent neural network
Recurrent networks read a sequence one step at a time, passing a hidden state forward, which makes them slow to train and weak at linking distant elements. Transformers process all positions in parallel and connect any two positions directly through attention. That parallelism let models train on far larger datasets, which made foundation models possible.
Why it matters
Knowing the architecture explains the practical limits of the models built on it: why inputs are measured in tokens, why context windows are finite, why long inputs cost more and why generation happens token by token. Those limits shape how applications are designed, from how documents are chunked, such as splitting a long datasheet by section, to how latency is managed.
How to get it right
- Budget prompts in tokens, since cost and speed scale with them.
- Keep inputs focused instead of filling the context window.
- Use encoder models for embeddings and classification, and decoder models for generation.
- Expect longer sequences to cost more than proportionally.
- Choose model size for the task, since larger transformers are slower per token.
Transformers in robotics and drone hardware
Transformers appear in hardware work in several forms: language models that read datasheets and logs, vision transformers that inspect boards and detect objects, and models that fuse camera and sensor data on a robot. Running them on embedded hardware depends on the same properties: model size, sequence length and the memory each layer needs.