Language model head

Also known as: LM head

On this page 7

A language model head, often shortened to LM head, is the final output layer of a neural language model that projects each hidden state onto the vocabulary, producing one raw score, or logit, for every token the model can emit. In artificial intelligence, and in language models in particular, it is the component that turns abstract internal representations into a probability distribution over the next token.

Although it is usually a single matrix multiplication, the LM head is one of the largest weight blocks in small models, a frequent target of weight tying, and the place where decoding strategies, logit bias and constrained decoding take effect.

How the language model head produces logits

The LM head is a linear projection from model width to vocabulary size. After the final transformer block and a closing normalization layer, each position holds a hidden vector of dimension d, typically between 768 and 16,384. The head multiplies that vector by a weight matrix of shape d by V, where V is the tokenizer vocabulary size, and returns V logits.

The logits are unnormalized scores, not probabilities. A softmax function converts them into a distribution that sums to one, and the decoding strategy then selects a token from it. During training, the same logits feed a cross-entropy loss against the true next token, so the head receives gradients at every position of every sequence.

The following table traces one forward step from hidden state to selected token, with typical shapes for a decoder-only model.

StageOperationOutput shape
Final hidden stateOutput of last block plus normalizationBatch x sequence x d
Linear projectionMultiply by d x V weight matrixBatch x sequence x V
Optional bias or scalingAdd bias, apply logit soft-cappingBatch x sequence x V
Softmax with temperatureDivide by temperature, normalizeProbabilities over V
Sampling or argmaxApply top-k, top-p or greedy ruleOne token ID per position
Data flow through the language model head

At inference time, an autoregressive model only needs logits for the last position, so efficient implementations slice the final hidden state before the projection and avoid computing V scores for every earlier token.

Size, cost and weight tying

The parameter count of the LM head equals d multiplied by V. With a vocabulary of 128,000 tokens and a width of 4,096, the head alone holds about 525 million parameters. In a model with one billion parameters, that is a large share of the total; in a model with hundreds of billions, it is a minor fraction.

Weight tying reuses the input embedding matrix as the output projection, transposed. It removes a full d by V matrix, often improves sample efficiency in smaller models, and enforces a shared geometry between how tokens are read and how they are predicted. Many larger models keep the two matrices untied because separate output weights add capacity at negligible relative cost.

The table below compares how the head scales across typical model configurations.

Model widthVocabulary sizeHead parametersTypical tying choice
76850,000About 38 millionTied
2,048128,000About 262 millionOften tied
4,096128,000About 525 millionTied or untied
8,192256,000About 2.1 billionUsually untied
Approximate LM head size by configuration

Compute cost follows the same product. For long prompts during training, the head and its softmax can consume a noticeable share of memory, because the logit tensor grows with sequence length times vocabulary size. Chunked or fused cross-entropy kernels compute the loss without materializing the full tensor.

Variants of the output head

Not every LM head is a plain linear layer, and architecture choices around it affect quality and speed. Some designs add a bias vector, some apply logit soft-capping with a scaled tanh to keep scores within a fixed range, and some attach several heads to predict more than one future token.

VariantWhat changesMain purpose
Plain linear headSingle d x V projection, no biasStandard next-token prediction
Tied headShares weights with embedding layerFewer parameters, better small-model efficiency
Soft-capped headScaled tanh limits logit magnitudeTraining stability
Multi-token prediction headsExtra heads for tokens t+2, t+3Richer training signal, speculative decoding
Masked LM headTransform layer plus projection at masked positionsEncoder-only pretraining
Adaptive softmaxClusters rare tokens into smaller projectionsLower cost for huge vocabularies
Common LM head variants

In encoder-only models such as masked language models, the head is applied only to masked positions and is often discarded after pretraining, when a task-specific classification head replaces it. In decoder-only models, the LM head remains the permanent interface between the network and the text it generates.

Where decoding controls act on the head

Nearly every user-facing generation control operates on the logits the head returns, before or during sampling. This is why the head output, exposed through logprobs, is the main window into model confidence and the main lever for steering output.

  • Temperature divides logits before softmax, sharpening or flattening the distribution.
  • Logit bias adds fixed offsets to chosen token IDs to favor or suppress them.
  • Repetition, frequency and presence penalties lower logits of tokens already generated.
  • Constrained decoding masks invalid tokens to negative infinity, enforcing formats such as JSON.
  • Top-k, top-p and min-p sampling truncate the distribution after softmax.

Researchers also read intermediate layers through the head, a technique called the logit lens: projecting an earlier hidden state with the final head reveals how the prediction forms gradually across layers.

Limitations and common misconceptions

The head is simple, but its design constraints have real consequences. A single linear map followed by softmax limits the rank of the output distribution, a problem known as the softmax bottleneck, which can prevent the model from expressing some context-dependent distributions exactly.

The table below lists frequent misunderstandings and what actually holds.

MisconceptionWhat is actually true
The head stores the model knowledgeKnowledge resides mostly in the transformer blocks
Logits are probabilitiesLogits need softmax to become probabilities
Bigger vocabulary is always betterIt enlarges the head and spreads training signal thinner
Fine-tuning must update the headMany adapters leave the head frozen
Tied weights reduce qualityEffect depends on scale; small models often gain
Misconceptions about the language model head

Rarely seen tokens receive weak gradients through the head, so their output vectors can stay poorly trained. This contributes to glitch tokens and odd behavior around unusual strings. Expanding a vocabulary after pretraining also requires careful initialization of the new head rows, typically from the mean of existing embeddings.

In plain words

A language model thinks in numbers, not words. At the end of each step, it holds a long list of numbers that describe what should come next. The LM head turns those numbers into word choices.

Picture a large scoreboard with one line for every word piece the model knows. The head fills in a score on each line. Higher scores mean more likely next pieces. The system then picks one piece, adds it to the text and repeats. Settings such as temperature only change how the scoreboard is read, not what the model has learned.

A real-world example

An engineering team adapts a one-billion-parameter model for customer support in Czech and Slovak. The original tokenizer splits words in those languages into many fragments, so the team adds 20,000 new tokens. That change means extending the LM head with 20,000 new output rows, each of width 2,048, which adds about 41 million parameters.

Because the model uses weight tying, the team extends the embedding matrix once and the head follows automatically. They initialize the new rows from the average of existing embeddings and fine-tune on local support transcripts. After training, the same answers need about 30 percent fewer tokens, and response latency drops accordingly. The team also applies constrained decoding on the head output so that ticket summaries always come back as valid JSON.