A whole LLM, layer by layer
A large language model (LLM) combines tokens, attention and feed-forward networks. How do those parts become a model that writes?
The complete network
We can now put everything we have built into one picture. Follow “the old rabbit sleeps” from the token IDs at the top to the vocabulary probabilities at the bottom.
Use the model-size picker to put real dimensions on the axes. Keep an eye on the residual stream: it connects every layer, including those left out of the drawing.
One prediction becomes the next input
Temperature adjusts the scores before softmax. Try the slider beside the final array: lower values concentrate probability on the highest-scoring tokens; higher values spread it more evenly. This changes the distribution used for sampling, not the model’s weights.
Suppose we choose “at” from that final array. The next input is now “the old rabbit sleeps at”:
That completes the basic architecture. The later articles explore how to make this journey cheaper as the model and context grow.
Sources and assumptions
- Attention Is All You Need (2017): attention, positional information, causal masking and position-wise feed-forward networks.
- GPT-2 report (2019): decoder-only language modelling, pre-normalisation and final normalisation.
- GLU Variants Improve Transformer (2020): gated feed-forward networks.
- Using the Output Embedding to Improve Language Models (2017): sharing input and output embedding weights.
The diagram shows a generic pre-normalised decoder with gated feed-forward networks, not a named checkpoint. Axis labels use the selected model’s dimensions; the three drawn blocks stand for the full stack. Coloured cells and IDs are illustrative, not trained activations or a real tokenisation. Position handling is included in attention.
Vectors are columns. The context has shape width × context length; embeddings have shape width × vocabulary; output weights have shape vocabulary × width. Some models reuse the embedding weights in the transposed orientation for the output; others learn separate weights.
The final probability grid is schematic, with softmax calculated from illustrative scores. It is not a prediction from a trained model. The generation loop describes full-prefix evaluation; caching is a later topic.