Adapting Language Models via Token Translation

Zhili Feng, Tanya Marwah, Nicolo Fusi, David Alvarez-Melis, Lester Mackey

TL;DR

When adapting pretrained Large Language Models (LLMs) to specialized domains like protein sequences, existing tokenizers cause poor sequence compression, inflated inference costs, and semantic mismatch. Sparse Sinkhorn Token Translation (S2T2) solves this by training a domain-tailored tokenizer and learning a sparse optimal transport mapping between old and new tokens without requiring parallel translation data. S2T2 enables superior compression and perplexity during continual finetuning, and mappings learned on smaller models transfer directly to larger models at low cost.

What Problem Does This Paper Address?

Modern LLMs rely on tokenizers optimized for their primary pretraining data (typically natural language and code). When applied to vastly different data types—such as biological sequences written in Latin characters—these source tokenizers perform poorly. Substrings in proteins carry fundamentally different semantics and frequencies than English words, causing severe semantic misalignment and forcing models to process text byte-by-byte or character-by-character. This dramatically inflates sequence lengths, context window usage, and inference costs.

Standard workarounds fall short:

  1. Retaining the source tokenizer maintains poor compression and inflated sequence lengths.
  2. Training a fresh target tokenizer typically forces practitioners to discard or randomly truncate embedding and language model head weights, erasing pretrained knowledge.
  3. Cross-lingual vocabulary transfer methods (like fast_align) depend on parallel bilingual corpora, which do not exist between natural language and molecular domains like proteins.

Methods

The authors introduce Sparse Sinkhorn Token Translation (S2T2) to translate between the source token vocabulary (size $v$) and a new target domain vocabulary (size $u$):

  • Target Tokenizer: A new Byte-Pair Encoding (BPE) tokenizer is trained specifically on the target domain.
  • Sparse Optimal Transport Mapping: S2T2 seeks a joint coupling matrix $P \in \mathbb{R}^{v \times u}$ that maps source and target token distributions while obeying marginal constraints $\mu$ and $\nu$.
  • Sparse Sinkhorn Formulation: Unlike standard entropy-regularized optimal transport (which produces dense couplings via Softmax), S2T2 solves an $\ell_2$-regularized optimal transport problem using Dykstra’s algorithm. In each iteration, it performs iterative row and column projections via SparseMax with appropriate scale factors.
  • End-to-End Learning Without Parallel Data: S2T2 parameterizes $P$ via an underlying dense weight matrix $C$. New input token embeddings $E'$ and language model output heads $L'$ are constructed as sparse convex combinations of the original embedding matrix $E$ and head $L$. The matrix $C$ is updated via standard backpropagation through the Sinkhorn iterations using the target domain next-token prediction loss. An optional entropy regularization term controls the sparsity level of $P$.

Datasets

  • UniRef50: A standard benchmark dataset containing clustered protein sequences.
  • Target Vocabulary: A BPE tokenizer trained on UniRef50 with a vocabulary size of 512, which compresses protein sequences by an average factor of $1.82\times$ relative to byte-level representations.
  • Models: Evaluated using the open-source OLMo-1B and OLMo-7B English models.

Key Insights and Ideas

  • No Parallel Data Required: S2T2 bridges disparate vocabularies purely through gradient updates on the target sequence modeling objective and the pretrained LLM’s internal representations.
  • Exact Sparsity Outperforms Dense Couplings: Replacing Softmax with SparseMax creates sparse token-to-token alignments. This prevents the blending of irrelevant tokens, outperforming unconstrained matrices and dense Sinkhorn baselines.
  • Weak-to-Strong Transferability: The token translator $P$ learned on a smaller model (OLMo-1B) can be directly plugged into a larger model (OLMo-7B). This allows practitioners to solve the token translation optimization on cheap hardware before scaling up.

Key Results

Evaluating on the UniRef50 validation set using perplexity and bits-per-byte (BpB):

Method Perplexity Bits-per-Byte (BpB)
Finetuning with original tokenizer 151.05 7.24
Finetuning with new tokenizer (truncated weights) 130.56 3.86
Unconstrained Translator + Continual Finetuning (CFT) 130.44 3.86
Dense Sinkhorn + CFT 136.12 3.89
S2T2 (Initialization only, no model CFT) 144.03 3.94
S2T2 + CFT 118.78 3.78
  • Zero-Finetuning Quality: Remarkably, initializing the model with S2T2 without any backbone finetuning (perplexity 144.03, BpB 3.94) outperforms full backbone finetuning using the original tokenizer (perplexity 151.05, BpB 7.24).
  • Continual Finetuning Boost: S2T2 + CFT delivers the best overall performance, reducing perplexity down to 118.78 and BpB to 3.78.
  • Model Transfer to OLMo-7B: Directly transferring the $P$ matrix learned on OLMo-1B to OLMo-7B yields an immediate cross-entropy loss of 5.94, comfortably beating random guessing (6.24), the original tokenizer (6.46), and a truncated new tokenizer (6.44).

Limitations and Future Work

  • Single Domain Evaluation: The paper evaluates S2T2 primarily on protein sequences using the OLMo architecture. Validation on other modalities (e.g., code, audio, or images) remains future work.
  • Domain Replacement vs. Expansion: S2T2 currently replaces the vocabulary for target domain adaptation rather than creating a unified multidomain model that retains proficiency in both source and target vocabularies simultaneously.

Summary updated

BibTeX
@inproceedings{feng2024adapting,
  author = {Zhili Feng and Tanya Marwah and Nicolo Fusi and David Alvarez-Melis and Lester Mackey},
  title = {{Adapting Language Models via Token Translation}},
  booktitle = {FITML @ NeurIPS},
  year = {2024},
  url = {https://openreview.net/forum?id=wAhgiuIr4j},
}
Figure