The whole path
A language model predicts the next piece of text. Training adjusts its learned parameters to improve predictions; generation reuses them unchanged to continue the text.
-
1 · Embed
Token + position
Look up the two learned vectors and add them.
384 values per token position -
2 · Process
Six transformer blocks
Attention shares context; the MLP transforms each position.
384 values in and out of each block -
3 · Predict
Normalise, then score
Final LayerNorm, then the separate output head.
8,192 scores; softmax gives probabilities, sampling picks the next token
Tokens, positions and embeddings
A token is a piece of text mapped to an integer ID. Its position is its index in the sequence: 0, 1, 2, and so on. A vector is a list of numbers; an embedding is a learned vector looked up for a token or a position.
The token table contains 8,192 × 384 = 3,145,728 parameters (18.45% of this model). The position table contains 256 × 384 = 98,304 parameters (0.58%). Look up one vector from each table and add them: 384 numbers then flow forward per position. Adding the position vector gives the model a sense of order.
The stored table entries are learned parameters. The flowing vectors are activations, computed from this input using those parameters. Producing another vector does not create or learn another set of weights.
Revisit embeddings in Concepts · See the tokenizer built in Part 1
Inside a transformer block
The transformer blocks hold most of the parameters. All six have the same architecture and parameter count, but each block has its own learned weights. Within a block, those weights are shared across token positions: there is no separate set for every token.
Start with the model's width: 384 numbers per token position. A token is a piece of text mapped to an ID (the token primer); its position is where that piece sits in the sequence. The embedding table's stored numbers are learned parameters. Once looked up, added to position embeddings and processed by the blocks, the flowing vectors are activations: input-dependent values computed using those parameters. Producing another vector does not create or learn another set of weights.
Every block receives and returns a vector of width 384, so the blocks fit together and their residual connections can add vectors of the same size. A whole transformer block includes attention and an MLP, plus normalisation and residual connections; the MLP is just one part. Within each block, the two stages run in this order:
Use information from the current and earlier positions, never future tokens.
The same feedforward weights work on each position independently.
384 → 1,536 → 384; GELU between the layersThe width and the MLP's expansion determine the sizes of the two main sets of matrices:
- Attention mixes information across token positions, drawing on the current and earlier positions. Its query, key and value projections each map 384 numbers to 384 numbers, and the output projection does the same. That makes 4 × 384 × 384 = 589,824 weights. The code packs the first three into one larger matrix, but the count is the same.
- The feedforward MLP transforms each position independently, using the same weights at every position. Its first layer expands 384 numbers to 1,536, GELU adds a nonlinear bend, and its second layer brings 1,536 back to 384. The wider middle gives the block more room to transform features before returning to the shared width. We chose a 4× expansion, so these two matrices contain 384 × 1,536 + 1,536 × 384 = 1,179,648 weights.
Add 3,456 biases across those projections and feedforward layers, plus 1,536 learned scales and offsets in the block's two layer normalisations, and one block totals 1,774,464 parameters. Six separately learned blocks therefore contribute 6 × 1,774,464 = 10,646,784.
Width, the feedforward expansion multiplier and the number of blocks are related design choices. Keeping the multiplier fixed, block parameters grow roughly with the square of width: doubling width makes the matrices about four times as large. Doubling the number of blocks instead doubles the stack's parameter count. A larger expansion multiplier increases the feedforward part. These choices trade capacity against memory and compute, so their value needs evaluation rather than an assumption that bigger is always better.
Vocabulary size determines the input embedding table and output head, but does not change these block matrices at a fixed width. A longer context makes attention do more work without enlarging those matrices, although this model's learned position table grows with its maximum context length. The six attention heads divide the 384 numbers into 64 per head; at a fixed width, changing the number of heads does not multiply the projection parameter count.
The complete inventory for one block
MLP means multilayer perceptron: here, two linear layers with GELU between them. GELU supplies a nonlinear bend; GELU and residual additions have no learned parameters.
| Component | Weights, scales & offsets | Parameters |
|---|---|---|
| Attention | 589,824 weights + 1,536 biases | 591,360 |
| Feedforward MLP | 1,179,648 weights + 1,920 biases | 1,181,568 |
| Two layer norms | 2 × (384 scales + 384 shifts) | 1,536 |
| One block | All three components | 1,774,464 |
Six blocks contribute 10,646,784 parameters, or 62.46% of the model. The diagrams show structure, not proportional parameter areas. Continue to initialization and stability in Part 1 →
From the final vector to the next token
The final LayerNorm normalises the feature values within each position's vector before the output head reads it. Its 384 learned scales and 384 shifts account for 768 parameters; it does not mix positions.
The output head maps each final 384-number vector to 8,192 vocabulary scores, one for each possible next token. 384 → 8,192 describes the input and output shapes; the parameter count is 384 × 8,192 = 3,145,728 weights, plus 8,192 biases, totalling 3,153,920. This is a separate, untied matrix: it does not reuse the input embedding table.
These scores are called logits. At generation time, softmax converts the last position's temperature-adjusted scores into probabilities that sum to 1; it has no learned parameters. Sampling uses those probabilities to choose the next token, which is appended to the input for the next step (the generation loop in §9).
The separate output head holds 18.50% of this model's parameters. Temperature adjustment, softmax and sampling add no learned parameters.
All 17,045,504 parameters
Add the two embedding tables, six blocks, final LayerNorm and separate output head. The 384-to-8,192 output shape is not itself a parameter count: the matrix and biases are what we count.
| Component | Calculation | Parameters |
|---|---|---|
| Token embeddings | 8,192 × 384 | 3,145,728 |
| Learned position embeddings | 256 × 384 | 98,304 |
| Six transformer blocks | 6 × 1,774,464 | 10,646,784 |
| Final layer normalisation | 2 × 384 | 768 |
| Separate output head | 384 × 8,192 + 8,192 biases | 3,153,920 |
| Total | All five components | 17,045,504 ≈ 17.05 million |
These were practical design choices, not established optima. Part 1 explains how they were chosen and what a production development process would test.