Zero-Shot Tokenizer Transfer

Benjamin Minixhofer, Edoardo Ponti, Ivan Vulić

Abstract

Large language models (LMs) are traditionally constrained by the fixed tokenizers used during their initial training. This coupling often leads to inefficiencies in non-English languages or specialized domains like code. We present Zero-Shot Tokenizer Transfer (ZeTT), a novel approach that utilizes a hypernetwork to predict embeddings for any new vocabulary on-the-fly. ZeTT enables swapping tokenizers without retraining the entire model, achieving up to 16% inference speedups with minimal performance loss. Our results demonstrate that LMs can be effectively decoupled from their tokenizers, allowing for better domain adaptation and efficiency.

Introduction

Language models are traditionally "bound" to the tokenizer they were trained with. Most popular LMs use English-centric tokenizers, which are highly inefficient for other languages or specialized domains like programming. For example, a single word in Hindi or a block of Python code might be broken into many more tokens than an equivalent English sentence.

This leads to two major issues: high inference costs due to increased computation per semantic unit, and performance gaps where inefficient tokenization hinders the model's ability to learn patterns in non-English data. Previously, changing a tokenizer required "n-shot" transfer—retraining the model's embedding layer on billions of tokens. ZeTT aims to do this "zero-shot," requiring no new training data to swap vocabularies.

Methods

The core innovation is the use of a hypernetwork ($H_\theta$) to bridge the gap between different tokenization schemes. The hypernetwork is a small Transformer model designed to find the embedding for a new token (e.g., from a target tokenizer $V_b$) by first decomposing that token using the LM's original tokenizer ($T_a$). These original sub-token embeddings are then "composed" by the hypernetwork into a single new embedding that fits the LM's existing latent space.

The hypernetwork $H_\theta$ decomposes tokens from a new vocabulary into original sub-tokens to predict new embeddings.

The hypernetwork is trained on a diverse distribution of synthetic tokenizers using the English subset of the MADLAD-400 corpus and code from StarCoder. This amortization allows it to learn the general mapping between text and the model's internal representations, rather than just memorizing a specific vocabulary. To handle various tokenizer types (like BPE or WordPiece), the authors introduce a procedure to approximate them as UnigramLM tokenizers, creating a unified interface for the hypernetwork.

Key Results

ZeTT demonstrates that LMs are not as strictly tied to their tokenizers as previously thought; they just require a consistent mapping into their learned embedding space. Evaluation across natural language benchmarks (PiQA, MMLU, ARC), code (HumanEvalPack), and multilingual tasks (XNLI, XCOPA) shows strong generalization.

On the XLM-R encoder, swapping to language-specific tokenizers reduced sequence lengths by an average of 14% (and up to 23% for Greek) while keeping accuracy within 1% of the original. These shorter sequences result in an estimated >16% speedup in inference time.

Zero-shot tokenizer transfer results for XLM-R on XNLI, showing sequence length reduction vs. accuracy.

For Mistral-7B, transferring to the StarCoder tokenizer—which is 10% more efficient for code—preserved functional correctness within ~3% in a zero-shot setting. Furthermore, a hypernetwork trained for a base model (like Mistral-7B) works effectively for its fine-tuned variants (like Mistral-7B-Instruct) without extra training, indicating that embedding spaces remain stable during instruction tuning.

Conclusion and Future Work

ZeTT provides a path toward more efficient and adaptable language models by decoupling the core model from its tokenizer. While the method is robust, current limitations include model-specific overhead (a hypernetwork must be trained for each base LM architecture) and assumptions regarding fixed pretokenization. Future work may extend ZeTT to multimodal models, allowing for zero-shot transfer in perceiving images or speech.

Summary updated

BibTeX
@inproceedings{minixhofer2024zero,
  author = {Benjamin Minixhofer and Edoardo Ponti and Ivan Vulić},
  title = {{Zero-Shot Tokenizer Transfer}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=RwBObRsIzC},
}
Figure