Transformers and Next-Token Prediction
A transformer block does more than attention
A typical language-model block combines attention, a position-wise feed-forward network, normalization, and residual connections. Exact ordering and activations vary. Attention mixes information across allowed positions; the feed-forward component transforms each position's representation. Residual additions preserve an easier path for information and gradients.
flowchart TD A[Token representations] --> B[Normalization and attention] B --> C[Residual addition] A --> C C --> D[Normalization and feed-forward] D --> E[Residual addition] C --> E E --> F[More blocks] F --> G[Vocabulary scores]
This diagram is one simplified arrangement, not a specification of every transformer.
Three architectural families
Encoder-only models commonly use bidirectional context and are useful for classification and representation tasks. Decoder-only models use causal sequence prediction and commonly generate continuations. Encoder-decoder models encode input and then generate output with a decoder that can attend to the encoder's representations. Translation is a classic application.
In a decoder-only model, final hidden states are projected to vocabulary scores called logits. Softmax turns logits into probabilities. Generation chooses a token, appends it, and repeats until a stop condition. Choosing a token can use greedy selection or sampling.
Training versus generation
Given “the cat sat,” causal training can supervise multiple positions in a parallel forward pass: predict cat after “the,” and sat after “the cat.” The mask prevents future information from leaking. This use of known previous training tokens is often called teacher forcing.
At generation time, the model must continue from the tokens already produced. An early error can alter later predictions. A fluent multi-sentence answer is built through many conditional token decisions; its training objective does not automatically establish factual correctness.
Reasoning and model size
Some systems allocate extra computation to intermediate reasoning or multiple attempts. This can improve outcomes on certain tasks but increases latency or cost and still needs evaluation. A visible chain of text is not guaranteed to faithfully explain the internal computation.
Parameter count is one architectural attribute. Training data, objective, compute, architecture, post-training, and task fit also influence capability. A smaller specialized model may outperform a larger general model for a narrow workload.
Checkpoint with answers
Does a decoder generate a whole paragraph in one ordinary decoding step? No. Standard autoregressive decoding advances token by token, although acceleration methods can propose and verify multiple tokens.
Is every transformer decoder-only? No. Encoder-only and encoder-decoder families are also important.
What prevents causal training from reading the next token? The attention mask.