LLM Library
Inside the TransformerAnimated
Encoder, Decoder and Encoder-Decoder Models
Three ways to arrange a transformer.
The idea
Encoders (BERT) read in both directions for understanding tasks. Decoders (GPT, Llama) generate text left to right. Encoder-decoders (T5) read an input and generate an output. Today's chat models are almost all decoder-only.
Watch it work
Press play, pause, or step through. Some animations have settings you can change.
Raw text enters the system, for example "The cat sat on the".
- stage:
- 1/10
- part:
- Text in
1/10
The green dot is one token travelling through the model. The boxed section repeats for every layer.
Step by step
- 1Encoder: bidirectional attention
- 2Decoder: causal attention
- 3Encoder-decoder: cross-attention between them
- 4Choose by the task
Where it is used
BERT for classification and search, T5 for translation, decoders for chat.
Watch out for
Decoder-only models won because they scale simply and handle many tasks with prompts.