From token ids to logits
PremiumUnderstand how a Decoder-only Transformer turns token ids into next-token logits
Starting from token ids
In the tokenization section, we already turned text into token ids. By this point, what the model sees is no longer a string, but a sequence of integers.
The next question is: once these integers enter the Transformer, why do they ultimately become, for each position, a score over the entire vocabulary?
Let us first denote the complete model as , where stands for all the trainable parameters of the model. For a batch, the input is:
and the output is:
Here is the batch size, is the sequence length, and is the vocabulary size. In other words, the model does not directly output the next token id; instead, for every position it outputs a vector of logits of length .
What are logits, and how big are they?
Logits are the raw scores before softmax; they can be positive or negative, and their magnitude is not fixed. They are not probabilities in themselves — only after softmax do they become a probability distribution.
A sense of typical scale: Qwen3.5-0.8B has and ; Qwen3.5-9B has and . is usually one to two orders of magnitude larger than , so the matrix of the LM Head can take up a substantial fraction of the model:
- Qwen3.5-0.8B: embedding and LM Head share weights (weight tying), and this single matrix accounts for about 32% (~254M).
- Qwen3.5-9B: the two are not shared; the LM Head alone is about 11% (~1.02B), and together with the embedding totals about 22%.
The smaller the model and the larger the vocabulary, the more extreme this ratio becomes (the next chapter, Embedding and LM Head, expands on the trade-offs of weight tying).
Log in to continue reading
This is premium content. Please log in to access the full article.
CookLLM Docs