A decoder-only transformer generates a sequence of tokens from an input sequence using only the transformer’s decoding stack. Unlike the original encoder–decoder design, it does not use a separate encoder to provide representations. GPT-style models, including GPT, Claude, and Llama, use this architecture for coherent text generation. section 9.12 section 9.6
A decoder block combines several mechanisms:
- Multiheaded attention uses parallel query, key, and value projections so different heads can capture different relationships in the sequence. section 9.6.1
- Residual connections let gradients flow around layers, while layer normalization stabilizes the block. section 9.6.1
- Feed-forward layers extend the attention block before repeated decoder blocks transform the sequence representation. section 9.6.1
A small GPT-style model
A PyTorch implementation embeds characters and positions, passes their sum through repeated TransformerBlock instances, and projects the result to vocabulary logits. Training the model on names can produce samples such as “journe,” “huxson,” and “bailanie.”







