TL;DR
When extending a large language model's vocabulary with new domain-specific or foreign words, initializing their embeddings properly is crucial but traditionally expensive. Token Distillation solves this by optimizing a new token's input embedding to mimic the internal hidden states produced when the model processes that same word split into its original subtokens. This fast, lightweight method runs in minutes on a single GPU and consistently outperforms both simple heuristics and complex, pretrained hyper-networks.
What Problem Does This Paper Address?
Large Language Models (LLMs) rely on fixed, static vocabularies determined during their initial pretraining. When these models encounter specialized domains (like medicine) or new languages, their tokenizers frequently chop unfamiliar words into tiny, fragmented pieces called subtokens. For example, the word palatable might be broken down into <_pal>, <at>, and <able>.
This "over-tokenization" causes two major issues:
- Performance Degradation: Fragmented tokens make it harder for the model to capture the cohesive semantics of a word.
- Increased Computational Cost: Longer token sequences consume more memory and compute, particularly due to the quadratic scaling of the attention mechanism.
While you can add new tokens to a model's vocabulary to fix this, initializing their embedding vectors is notoriously difficult. Simple methods like taking the average of the subtokens' embeddings perform poorly because they ignore how the Transformer's attention layers dynamically build meaning. Conversely, advanced methods like hyper-networks require expensive pretraining.
Methods
The authors introduce Token Distillation, a method that leverages the functional knowledge stored inside the Transformer's layers to initialize new input embeddings.
Instead of looking only at the static embedding matrix, Token Distillation treats the original model as a "teacher." The process works as follows:
- Teacher Forward Pass: A text snippet containing the target word is passed through the model using the original tokenizer (where the word is split into subtokens). The model's hidden states at a specific layer (usually the last layer) are recorded.
- Student Forward Pass: The same snippet is passed through, but this time using a new tokenizer where the word is represented as a single, new token.
- Distillation Optimization: The weights of the LLM are frozen, and only the new token's input embedding is optimized using gradient descent. The objective is to minimize the Mean Squared Error (MSE) between the student's hidden states and the teacher's hidden states at the positions following the target token.
To find text snippets containing the new tokens, the authors propose two efficient strategies: retrieving short windows of text from a reference corpus using the Aho-Corasick string-matching algorithm, or prompting the LLM to generate sentences containing the new token.
Datasets
The method was evaluated across several diverse benchmarks:
- Biomedical Domain: Evaluated using the Open Medical-LLM leaderboard, which aggregates datasets like MedMCQA, MedQA, PubMedQA, and various medical subsets of MMLU. Contexts were retrieved from the
ncbi/pubmedcorpus. - French Language Adaptation: Tested on multiple-choice tasks from FrenchBench, using the
HuggingFaceFW/fineweb-2corpus for context retrieval. - Arabic Language Adaptation: Evaluated on Arabic multiple-choice benchmarks using tokens selected via AdaptiVocab to maximize sequence compression.
Key Insights and Ideas
- Meaning is Layered, Not Static: The core philosophy is that a word's true meaning isn't fully captured in its raw input embedding. Instead, the Transformer's attention and feed-forward layers gradually construct the word's contextual meaning. Token Distillation successfully "bakes" this multi-layer interaction into a single input vector.
- Behavior Matching Beats Likelihood Maximization: Traditional embedding tuning uses Next-Token Prediction (NTP) to maximize text likelihood. However, NTP often learns generic representations (e.g., learning that a token is just "a football player"). Token Distillation forces the embedding to capture highly specific semantics by directly matching the model's internal behavior.
- Context Generation as an Alternative: If a large reference corpus isn't available, simply prompting the model to generate sentences containing the new token provides a clean, un-biased training signal that performs nearly as well as real-world data.
Key Results
The authors tested Token Distillation across a wide range of open-weight models, including Mistral-7B, Llama-3/3.1/3.2, and OLMo2.
- Superior Performance: On the Open Medical-LLM leaderboard, Token Distillation consistently outperformed subtoken averaging and NTP baselines, achieving results closest to the original tokenization performance without any full-model fine-tuning.
- Beating Hyper-networks: It outperformed ZeTT, a state-of-the-art hyper-network baseline, despite ZeTT requiring billions of tokens of pretraining compared to Token Distillation's few million tokens.
- Significant Compute Savings: For Arabic adaptation on Mistral-7B, adding 1,000 compression-oriented tokens reduced the total token count by 36%. Thanks to quadratic attention scaling, this translated to a 40.8% to 50.5% reduction in wall-clock compute time during processing.
- High Efficiency: The method is incredibly fast, capable of initializing 2,500 new tokens on a single Nvidia H100 GPU in under 10 minutes.
Limitations and Future Work
- Input Embeddings Only: Token Distillation only optimizes input embeddings. Output embeddings (the matrix used to predict the next token) cannot be learned this way because the new token does not exist in the original teacher model's output vocabulary. It must be paired with other methods or trained via standard next-token prediction.
- Completely Unseen Languages: The method relies on the original model being able to fragment and somewhat understand the target word. If a model is adapted to an entirely new script/language that it cannot process at all, Token Distillation is inapplicable.
- Short Subword Tokens: It struggles with short, highly ambiguous subwords (like
<ed>or<fer>) that lack stable semantic meaning across different contexts.
The authors suggest that future work should explore targeting specific, localized attention heads responsible for subtoken contextualization to make the distillation objective even more precise.
Summary updated