﻿# Token embeddings and contextual hidden states do different jobs

How a vocabulary embedding differs from a contextual hidden state, following a repeated word through lookup, attention and the language-model output.

Author: Retrivium editorial team
Updated: 2026-11-03
Canonical URL: https://retrivium.ai/journal/static-token-embedding-contextual-state/
Language: en

The same token can appear in different sentences without changing its vocabulary identifier. A model nevertheless needs representations that reflect those different contexts. The distinction between an embedding lookup and a contextual hidden state explains how these facts can coexist.

## The lookup supplies a learned starting point

A vocabulary table associates token identifiers with learned vectors. Repeated occurrences of an identifier normally select the same table row before position information and contextual processing are applied. This shared starting point does not assign one final meaning to every occurrence. The token can be part of a word, punctuation or another learned unit. Its role is to provide coordinates that subsequent layers can transform, not to deliver a complete interpretation of the sentence before those layers have run.

## Context changes the representation at each occurrence

Attention combines information from eligible positions, while feed-forward and normalization operations transform the resulting features. After these layers, occurrences that began with the same lookup can have different hidden states. A causal model only uses the context its attention pattern permits; a bidirectional encoder has a different visibility contract. The phrase contextual representation therefore needs a layer identity and an access pattern. A vector from an early layer and one from the final layer need not support the same downstream interpretation.

## Follow an ambiguous example through the distinction

Consider the word bank in a financial sentence and in a sentence about a river. The actual tokenizer may split either text into units, so first identify the relevant token sequence. A repeated token’s initial table value can remain shared, while surrounding words lead contextual computation toward different representations. This is an illustrative explanation, not a claim about an identified neuron or a measured model result. The example clarifies why comparing raw table rows cannot establish how the full model disambiguates complete sentences.

## Select the representation for its intended consumer

A retrieval system, a classifier and an output vocabulary projection may consume different representations or pool them differently. Reusing the phrase embedding does not make their vectors interchangeable. Record the tokenizer, selected layer, pooling rule and normalization alongside an extracted vector. Then test whether it preserves the distinctions the downstream task needs. This connects a conceptual explanation to an artifact that can be reproduced: the vocabulary row supplies a starting identity, while the full extraction procedure specifies the contextual object actually used by an application.

## Primary research and implementation references

- [Attention Is All You Need](https://arxiv.org/abs/1706.03762).

- [PyTorch: Embedding Lookup](https://docs.pytorch.org/docs/2.15/generated/torch.nn.Embedding.html).

- [Hugging Face Transformers PreTrainedModel](https://huggingface.co/docs/transformers/main_classes/model).

## Related engineering context

[Reproducible inference stacks: preserving a GPU pilot’s result](/journal/software-stack-reproducibility/); [A GPU inference benchmark you can trust](/journal/inference-benchmark-method/).
