Why can the same token have different contextualized representations?
From a shared embedding lookup to context-dependent hidden states
Lesson objective. Predict what can change an occurrence’s state by separating token ID, position, accessible prefix, and network transformations.
Lesson skeleton
- Initial token embedding + Positional encoding → Contextualized representation · Explain why two occurrences of one token can have different states
By the end of this lesson, you should be able to: - explain why two occurrences of the same token ID share an initial embedding and can produce distinct contextualized hidden states; - identify exactly when positional information and sequential interactions transform internal activations; - refute the misconception that attributes semantic comprehension or contextual disambiguation to the initial embedding lookup.
Verified concept Architecture: Transformer Blocks
The question “What have the Romans ever done for us?” and a reply such as “The Romans built roads” contain the same visible word in different surrounding sequences. Under the assumption that the tokenizer assigns it the same ID, both occurrences retrieve the same initial vector. The lookup does not change; the Transformer’s processing of each sequence builds hidden states that depend on context.
Questions and exercises: Open the dedicated practice page.
To isolate the effect of context, we now keep the parameters, the studied token ID, and its position fixed. Only the accessible prefix varies. The previous lesson varied position; this one holds position fixed to examine what the blocks can do with context.
Start with what stays the same
In the question “What have the Romans ever done for us?” and in a reply such as “The Romans built roads”, the visible word Romans may be represented by the same token ID. Under that explicit assumption, both occurrences retrieve the same initial embedding:
\(e_{\text{Romans}} = E[\text{ID}_{\text{Romans}}]\)
The embedding lookup is a table access. It does not inspect the surrounding words or produce a sentence-specific vector. The contextualized states can nevertheless differ because each occurrence is processed with a different surrounding sequence.
One qualification: a visible word is not guaranteed to correspond to one token. A tokenizer may split it into several tokens. This example isolates the contextualization principle by assuming one shared token ID.
What changes with position and context
The initial lookup is not the whole network input: the architecture must also handle position, and Transformer blocks then build states that depend on accessible context. Positional mechanisms vary across models; a position vector is therefore not always added directly to the embedding.
In the running example, “What have the Romans ever done for us?” is already in the context. As “They built roads between distant towns.” is generated, each new token is processed against the context available at that step, which grows throughout the loop.
This original illustration is motivated by Ethayarajh (2019), How Contextual are Contextualized Word Representations?. It illustrates the principle, not measured vectors. Depending on the tokenizer, a visible word may consist of multiple tokens.
Common Fallacy: “For two senses of a word like ‘bank’ to be captured, the tokenizer must assign them different token IDs”
Counterexample: A tokenizer segments text using its vocabulary and segmentation rules; it does not perform sentence-level semantic disambiguation. In this example, we explicitly assume that both occurrences of “bank” receive the same ID. The model’s layers can then build different hidden states from their accessible contexts. Requiring separate IDs for each sense confuses token segmentation with contextual disambiguation.
Dependencies between positions are not limited to lexical ambiguity: they can also involve pronoun reference. This requires more linguistic analysis, so it is reserved for the advanced page on contextualized representations.
A controlled experiment: change the past or the future
Fix a position \(i\), the model parameters, and the token at that position. Compare three inputs:
| Experiment | Modification | Can the state at position \(i\) change? |
|---|---|---|
| A — reference | No change | No: this is the baseline |
| B — past changed | A token strictly before \(i\) changes | Potentially: an accessible input has changed |
| C — future changed | A token strictly after \(i\) changes | No, in a correctly masked causal GPT |
This comparison identifies which context can affect a state at a given position. It assumes the same position, fixed parameters, and the same causal mechanism. It also separates the initial lookup, which depends on the ID and embedding matrix, from the hidden state, which depends on subsequent transformations and accessible information.
The dedicated practice page lets you test this boundary with concrete cases.
Keep the stages and representations separate
| Object | What determines it? | Is it context-dependent? |
|---|---|---|
| Token ID | Tokenizer vocabulary and rules | A fixed token keeps its ID in that vocabulary. Segmentation can produce a different token, for example with or without a leading space. |
| Initial token embedding | The selected row of the embedding matrix | No, for a fixed matrix and token ID |
| Hidden state at layer \(\ell\) | Previous layer’s state, positional information, and tokens accessible under the mask | Yes, in general |
Two common confusions follow from collapsing these stages:
- “The embedding lookup understands the sentence.” No. The lookup selects a learned row; context is incorporated by subsequent network operations.
- “The same token must have the same hidden state everywhere.” No. The initial lookup can be shared while position and context change later representations.
This also does not guarantee that the model will represent human-interpreted senses as cleanly separated clusters. Contextualization is a computational mechanism, not a guarantee of a particular semantic geometry.
- Same ID, same lookup: with a fixed matrix, both occurrences select the same row.
- Position: the architecture introduces order through its positional mechanism (absolute embeddings, RoPE, etc.).
- Context: each block transforms a position’s state using the tokens it can access.
- Result: hidden states can differ, without guaranteeing a clean geometric representation of human “senses.”
In a causal GPT, the prefix accessible at a position ends at the current token. With position and weights fixed, a change to the accessible prefix can change the current state; a change after that position must not change it.
Where this fits in the model
Comparing these objects prepares you to read the Transformer. In the computation itself, the blocks produce contextualized states from their inputs.
- The tokenizer maps text to token IDs.
- The embedding table maps each ID to an initial vector.
- The architecture handles position where its mechanism requires it: in the input representation or inside attention.
- Transformer blocks use that mechanism to produce context-dependent hidden states.
- Later layers and the output head use those states to predict the next token.
This is an original, simplified illustration, not a reproduction of Rushang Chauhan’s figure. For another pedagogical overview of the path from tokens to context, see Rushang Chauhan’s article, Embeddings: The Bridge Between Tokens and Context.
The embedding-space lookup maps IDs to initial vectors. To see how the network then transforms these vectors into contextualized states, continue with The Transformer in a GPT: that page locates the stack of blocks and distinguishes attention from the MLP. The Q/K/V and scaled dot-product attention pages then unpack the attention mechanism.
For the dependencies between positions, causal masks, and the distinct roles of self-attention and the MLP, see the deep dive on contextualized representations. The detailed formalization is deliberately separated from this first explanation.