Each tokenizer builds its own vocabulary independently, so id 1234 is a row index into one specific table. Different tokenizer, different table, different meaning. Raw text is the only portable representation.
Imagine each tokenizer has a numbered locker room. Token id 47 means 'locker 47 in this specific room'. Inside locker 47 is the embedding vector representing one piece of text. Now imagine a different building with its own locker room. Locker 47 there holds something completely different. There is no relationship between locker 47 in building A and locker 47 in building B. Token ids work the same way. The id is a coordinate inside one tokenizer's vocabulary, not a global name. The only way two models can share information is through the raw text: detokenize on one side, re-tokenize on the other. Passing token ids directly between models is like mailing someone your gym locker number and expecting it to mean something at their gym.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
A token id is one of the smallest objects in an LLM stack, but understanding it precisely clears up an entire category of cross-model bugs. The id is an integer index into a specific tokenizer's vocabulary. It has no meaning outside that tokenizer. The model uses it to index the embedding matrix at input and to label logit positions at output.
This deep dive walks through the mechanics: how ids interact with the model, why they are coupled to the tokenizer, the role of special tokens, and the implications for any pipeline that spans more than one model.
What a token id does inside the model
The token id has two specific jobs, one at each end of the transformer pipeline.
At input time, the id indexes the embedding matrix. The embedding matrix is a vocab_size by d_model array of trained parameters. Token id 1234 means 'use row 1234 as the input vector for this position'. That row is a d_model-dimensional vector that becomes the input to the first transformer block, typically after modification by a positional scheme like RoPE.
From that point the model does not use the id directly. Every transformer layer operates on continuous d_model-dimensional vectors. The discrete identity of the token is encoded in the embedding vector and the model's learned associations.
At output time, the final layer produces logits via a matrix multiply against the lm_head (shaped d_model by vocab_size). The result is a logit for every vocabulary position. Sampling picks one position, and that position is the token id of the predicted next token. The decoder maps that id back to the corresponding vocabulary entry and appends it to the output.
This is the entire path. Input ids become embedding vectors, transformer layers process them, lm_head produces logits, sampling picks an id, decoder maps it back to text. The id is the boundary between discrete text-space and continuous vector-space at both ends.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
Real products, models, and research that use this idea.
- In tiktoken cl100k_base the token ' the' (with leading space) has a specific id; that same surface form in o200k_base has a different id because the vocabularies differ.
- Llama 3's tokenizer assigns specific ids to chat template control tokens; mismatching these breaks apply_chat_template and generation behavior.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhat happens inside the model the moment a token id is read from the input?
The id indexes the embedding matrix to produce a d_model-dimensional vector. That vector is modified by the positional encoding (or RoPE) and becomes the input to the first transformer block. From that point the model operates on continuous vectors; the discrete id is not used again until the final logit projection.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Treating token ids as portable between models. They are integer indices into a specific tokenizer's vocabulary; the same id in two tokenizers points to two unrelated entries.
60 second bullets to scan on the way to the call.
Define a token id as an integer index into a specific tokenizer's vocabulary.
Name the two model components token ids interact with (embedding matrix at input, lm_head at output).
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.