The unembedding matrix is the final linear layer in a transformer-based language model, responsible for projecting the processed hidden state from the model's internal representation space back into the vocabulary space. After the final transformer block writes its output to the residual stream, the unembedding matrix multiplies this state vector to produce a raw score, or logit, for every token in the model's dictionary. This operation is the inverse conceptual counterpart to the embedding matrix, which maps discrete tokens into dense vectors at the input layer.
Glossary
Unembedding Matrix

What is Unembedding Matrix?
The unembedding matrix is the final linear transformation in a language model that maps the high-dimensional residual stream state to a vector of logits, one for each token in the vocabulary, to produce a probability distribution for the next-token prediction.
Crucially, the unembedding matrix is not merely a mechanical decoder but a key object of study in mechanistic interpretability. Because it directly connects internal representations to output tokens, its weights can be used as a lens to decode intermediate states. Techniques like the logit lens apply the unembedding matrix to the residual stream at earlier layers to reveal the model's iterative predictions, effectively reading its 'thought process' as it refines the next token before the final output.
Key Properties of the Unembedding Matrix
The unembedding matrix is the final linear transformation in a language model, mapping the high-dimensional residual stream state to a probability distribution over the entire vocabulary. Its properties directly govern the model's output behavior and are a primary target for interpretability research.
Dual of the Embedding Matrix
The unembedding matrix W_U is often tied to the transpose of the embedding matrix W_E through weight tying. This parameter sharing forces the input and output representations to live in the same space.
- Weight Tying: Reduces parameter count and enforces a shared semantic geometry between input tokens and output logits.
- Folding Norm: The unembedding vector for a token is its 'ideal' representation that the residual stream must align with to predict that token.
- Interpretation: The logit for a token is the dot product between the final residual stream state and that token's unembedding vector.
Logit Lens Application
The Logit Lens technique applies the unembedding matrix to intermediate residual stream states, not just the final layer. This reveals the model's iterative prediction process.
- Early Layer Predictions: Applying W_U at early layers often shows the model predicting nonsensical or highly generic tokens.
- Convergence: As layers progress, the top predicted token converges toward the final output, showing how the model refines its belief.
- Interpretability Tool: Researchers use this to diagnose where specific factual recall or syntactic decisions occur in the forward pass.
Softmax Bottleneck
The unembedding matrix is followed by a softmax function to produce a probability distribution. This creates a well-known representational bottleneck.
- Rank Limitation: The logit for a token is a linear function of the hidden state. The model cannot express arbitrary probability distributions; it is constrained by the dimensionality of the residual stream.
- Mixture of Softmaxes: Advanced architectures break this bottleneck by using multiple unembedding matrices and mixing their probabilities, allowing for more expressive output distributions.
- Impact: This limitation is a key reason why language models struggle with tasks requiring precise, multi-modal output distributions.
Unembedding as a Semantic Space
The rows of the unembedding matrix form a semantic basis for the vocabulary. The geometry of this space encodes linguistic relationships.
- Cosine Similarity: The cosine similarity between unembedding vectors for two tokens correlates with their semantic relatedness.
- Linear Analogies: Famous analogies like 'king - man + woman = queen' can be performed in the unembedding space, demonstrating that it captures structured relational knowledge.
- Concept Directions: Directions in the unembedding space can correspond to interpretable concepts, such as sentiment or tense, which can be used for steering.
Logit Attribution and Saliency
The unembedding matrix is the final step for logit attribution methods that trace a prediction back to input tokens or model components.
- Direct Attribution: The contribution of a specific attention head or MLP neuron to the final logit is computed by multiplying its output by the unembedding matrix.
- Gradient-Based Saliency: The gradient of a target logit with respect to the input embeddings is computed through the unembedding matrix, revealing which input tokens were most influential.
- Causal Tracing: In causal tracing for factual recall, the unembedding matrix is used to project intermediate states to logits to measure the restoration of a corrupted fact.
Logit Suppression and Steering
By manipulating the logits before the softmax, the unembedding matrix enables direct control over the model's output distribution.
- Logit Bias: Adding a constant bias vector to the logits can suppress or promote specific tokens, a common technique in API-based inference.
- Contrastive Decoding: Methods like DoLa subtract the logits from an early layer's unembedding projection from the final layer's logits to amplify factual knowledge and reduce hallucinations.
- Steering Vectors: A direction computed in the residual stream can be mapped through the unembedding matrix to understand which tokens it promotes, validating the vector's semantic effect.
Frequently Asked Questions
Explore the critical final layer that translates a language model's internal state into a probability distribution over its vocabulary, enabling token prediction.
The unembedding matrix is the final linear layer in a transformer-based language model that maps the high-dimensional residual stream state to a probability distribution over the entire vocabulary of tokens. It functions as the inverse operation of the embedding matrix. While the embedding layer converts discrete input tokens into dense vectors, the unembedding matrix (often denoted as W_U) projects the final hidden state vector back into logit space. Mathematically, if the residual stream has a dimension d_model, and the vocabulary size is V, the unembedding matrix has dimensions [d_model, V]. The dot product between the final hidden state and each column of this matrix produces a raw score, or logit, for the corresponding token. These logits are then normalized by a softmax function to produce a valid probability distribution, from which the next token is sampled.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
The unembedding matrix is the final linear transformation in a language model's architecture. Explore the core concepts that govern how internal representations become token predictions.
Vocabulary Space
The high-dimensional vector space where each dimension corresponds to a specific token in the model's tokenizer. The unembedding matrix performs the critical linear map from the model's internal residual stream dimension to this vocabulary dimension. The resulting vector of raw scores, or logits, defines the model's raw preferences before the softmax function converts them to probabilities.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us