AI Glossary / Retrieval and knowledge systems / Intermediate
Unembedding
Definition
Unembedding is the mapping from a language model's hidden representation to scores for tokens in its output vocabulary. It is commonly implemented as a learned linear projection, sometimes with a bias term. The resulting scores are logits; a subsequent softmax converts them into a token probability distribution. Unembedding is therefore a stage in producing language-model outputs, rather than a general method for reversing arbitrary embeddings.
What it means
Inside a language model, information is represented by vectors whose coordinates are not token choices. To predict a next token, the model needs one score for each possible output token. The unembedding layer performs that conversion.
The name suggests the opposite direction from input embedding, but it does not imply a mathematical inverse. The hidden state has been transformed by the model and reflects context. Mapping it to vocabulary scores does not reconstruct the original input or recover a unique sentence from a vector.
How it works
Let a hidden state h have dimension d and the vocabulary contain V tokens. Using a column-vector convention, an output matrix W has shape V by d. The logits are z=W*h+b, where b is an optional vocabulary-sized bias. Some descriptions use row vectors and transpose these shapes; the underlying operation is the same.
Each row of W defines how the hidden state's components contribute to one token's score. Softmax exponentiates and normalizes the logits to produce nonnegative values summing to 1. Decoding then selects or samples a token according to a specified procedure, potentially with additional restrictions or transformations.
In a weight-tied architecture, the output projection shares parameters with the input embedding table, with the transpose convention determined by how matrices are written. Weight tying is a design choice, not part of the definition of unembedding. Untied models learn a separate output matrix.
The hidden representation used for prediction may undergo a final normalization or other processing before projection. The tokenizer's vocabulary and token order must match the output rows. During training, prediction errors update the relevant model parameters; during generation, the projection is evaluated repeatedly as the context grows. A token probability reflects the model's continuation distribution, not a direct probability that a factual statement is correct.
Three practical examples
- A language model converts its final hidden state into next-token logits before decoding.
- A model engineer compares tied and untied output projections when evaluating parameter use and language-model quality.
- An interpretability experiment projects selected internal states into vocabulary space, while recognizing that an intermediate projection may not match the model's final prediction.
Think of it this way
Think of a control panel that translates an internal set of signals into a score for each available button. The panel does not undo all the computations that produced the signals. It provides scores from which a separate selection procedure chooses the next button.
Worked example
Consider an original toy model with three output tokens A, B, and C, and a two-dimensional hidden state h=(1,2). Let the unembedding rows be A:(1,0), B:(0,1), and C:(-1,0), with no bias.
The logits are z_A=1, z_B=2, and z_C=-1. Softmax probabilities are proportional to exp(1), exp(2), and exp(-1). For numerical convenience, subtract the largest logit, 2, from all three; this leaves softmax unchanged.
The exponentiated shifted values are exp(-1), 1, and exp(-3), approximately 0.367879, 1, and 0.049787. Their sum is approximately 1.417666. The probabilities are therefore approximately 0.259496 for A, 0.705385 for B, and 0.035119 for C.
Greedy decoding chooses B because it has the largest logit and probability. Sampling could choose another token, so the unembedding calculation alone does not determine a unique generated continuation under every decoding method.
If the target token during training is B, its negative log-likelihood is -ln(0.705385), approximately 0.349012 using natural logarithms. This loss concerns the observed target under the toy distribution; it does not measure the truthfulness of a sentence.
For a separate parameter-count example, an output matrix with 10,000 vocabulary tokens and hidden dimension 128 contains 1,280,000 weights. An untied input table of the same dimensions adds another 1,280,000. Sharing them removes that duplication, but does not halve all parameters in a model that also contains other layers.
Illustrative case study
Fictional case: Maple Language builds an educational demonstration of token prediction. Its interface initially labels the unembedding output as probabilities even though the values are raw logits.
The team separates hidden-state projection, softmax normalization, and token selection in the explanation. It verifies the tokenizer row mapping and uses a small hand-checkable example before displaying larger model outputs. It also explains that a highly probable continuation can still contain an error.
The demonstration is hypothetical. It illustrates conceptual clarity rather than a real model deployment, and its toy values are not claimed to describe any commercial language model.
Common misconceptions and mistakes
Unembedding is not generally inverse embedding. A transpose is not automatically an inverse, and hidden-state processing cannot be undone merely by projecting to vocabulary space.
Logits are not probabilities. They can be negative or greater than 1, and their absolute common offset does not affect softmax.
Weight tying is not universal, and a token need not be a whole word. Also avoid treating an intermediate-layer vocabulary projection as the final model's belief without checking normalization, architecture, and later computations.
Business use
Understanding unembedding helps teams interpret model outputs, estimate some parameter costs, and distinguish generation mechanics from factual reliability. It is useful when building language-model educational tools, inspecting logits, or modifying a model's vocabulary or output head.
Verify dimensions, token ordering, and compatibility with the model's final processing. Evaluate any architecture change with meaningful held-out data rather than assuming a smaller parameter count preserves quality. When probabilities are shown to users, describe what event they concern and avoid labeling them as confidence in factual correctness.
People also ask
Does unembedding produce text directly?
It normally produces token scores; decoding and token-to-text conversion complete the process.
Must it share input-embedding weights?
No.
Why can every logit be shifted by the same amount?
Softmax divides by the same exponential scale factor, so the probabilities are unchanged.
Check your understanding
Which token has the largest score in the example?
Answer: B, with logit 2.
Why is its probability not 2?
Answer: Softmax normalizes all three logits into a distribution.
Why does weight tying not necessarily halve the model?
Answer: Other layers retain their own parameters.
Related terms
- Embedding matrix
- Logit
- Softmax
- Weight tying
- Tokenization
- Decoding
- Cross-entropy loss
- language-model head
- hidden state
Learn next
Learn matrix shapes and softmax, then trace one hidden state through projection and decoding. Next study weight tying and distinguish next-token likelihood from measures of task accuracy, calibration, or factual support.
More in Retrieval and knowledge systems
- Type-1 OWA operators - Type-1 OWA operators extend ordered weighted averaging to aggregate information represented by type-1 fuzzy sets, with weights that can also be type-1 fuzzy...
- Unary code - Unary code represents an integer using a repeated bit followed by a terminating bit.
- Uncertain inference - Uncertain inference is reasoning in which the support for a conclusion is not treated as simply certain or absent.
- Universal code - A universal code, in this information-retrieval context, is an integer coding scheme with an efficiency guarantee across a specified class of source...
- URL normalization - URL normalization converts a web address into a consistent representation using rules that preserve its intended meaning.
- Variable byte encoding - Variable byte encoding represents an integer using one or more bytes, reserving a bit in each byte to mark whether the number continues.
Sources
Primary textbook: Jurafsky and Martin, Speech and Language Processing, language-model-head discussion: https://web.stanford.edu/~jurafsky/slp3/ Primary research: Press and Wolf, Using the Output Embedding to Improve Language Models: https://arxiv.org/pdf/1608.05859
Previous: Undirected graph Next: Unevenly spaced time series