Decoder
A decoder is the part of a neural network that turns an internal representation into output such as text, an image or a translation; in a transformer it generates output one token at a time.
Google's machine learning glossary defines a decoder broadly as any system that converts a processed, compact, internal representation into a rawer, external one. Decoders usually come paired with encoders, which do the reverse. In an autoencoder, the encoder squeezes an image into a short code and the decoder rebuilds the image from it. In an image generator built on latent diffusion, a decoder turns the compressed representation the model works in back into pixels.
The term is most often used for transformers. The original transformer of 2017 was built for translation and had two stacks. The encoder read the whole source sentence. The decoder then wrote the translation token by token, attending to the output it had produced so far, but never to later positions, and consulting the encoder's representation of the source through cross-attention. This encoder-decoder arrangement goes back to earlier recurrent networks: the 2014 paper that introduced attention was a fix for decoders that had to work from a single fixed-length summary of the source sentence.
Many later models kept only one half. Encoder-only models such as BERT are used to understand text. Decoder-only models drop the encoder and treat the prompt and the response as one continuous sequence. Hugging Face's course notes that most modern large language models, including Llama, Gemma and DeepSeek V3, use this decoder-only design.
In news about model speed and serving, the related word decoding usually refers to the step-by-step process of producing output tokens, as distinct from the prefill stage in which the model first reads the prompt. Techniques such as speculative decoding aim to make that step faster.
It generates the output sequence one token at a time. Each new token is predicted from the tokens already produced, using a mask so the decoder cannot look ahead. In an encoder-decoder model it also attends to the encoder's representation of the input, for example the sentence being translated. An encoder turns raw input into a compact internal representation, and in a transformer it can look at the whole input at once. A decoder turns a representation into output and, in a transformer, works left to right. Encoders suit understanding tasks; decoders suit generation. GPT models are decoder-only transformers: they keep the decoder half of the original design and drop the encoder. Most current large language models, such as Llama and Gemma, are built the same way. Decoding is the process of producing output tokens one after another from the model's predictions. It follows the prefill stage, in which the model processes the whole prompt in one go. Decoding speed largely determines how quickly a chatbot's answer appears.Common questions
What does a decoder do in a transformer?
What is the difference between an encoder and a decoder?
Is GPT a decoder?
What does decoding mean for large language models?
Search for "transformer decoder explained", "encoder vs decoder transformer" or "prefill and decode" depending on whether you are interested in architecture or serving. The original transformer paper on arXiv, the Hugging Face course and Google's machine learning glossary are reliable sources. Be aware that decoder means slightly different things in autoencoders, translation models and language models, so check the context.Finding more
Working out what this means for your business?
Aileron Shift builds the systems behind this site: AI newsrooms that research, write and publish on their own, marketing automation and WordPress hosting for companies that need to move faster than their competitors.