Skip to main content
CookLLM logoCookLLM Docs

Embedding and LM Head

Premium

Understand how token ids enter a continuous vector space, and how hidden states are projected back to vocabulary logits

Get code access

Why are the input/output layers worth looking at separately?

The heaviest computation in a Decoder-only Transformer happens in the blocks in the middle, but the input/output relationship of a language model is actually determined by the two ends:

token ids→embeddinghidden states→LM Headnext-token logits\text{token ids} \xrightarrow{\text{embedding}} \text{hidden states} \xrightarrow{\text{LM Head}} \text{next-token logits}

If these two ends are not understood clearly, many later questions get tangled together: why the input is integers, why the output is not a token id, why the loss needs shifted targets, why the vocabulary size significantly affects the parameter count, and even why some models share the weights of the input embedding and the output LM Head.

The main thread of this chapter only covers the two ends, input and output: Embedding and LM Head.

Log in to continue reading

This is premium content. Please log in to access the full article.