TL;DR
LangMAP (Language-adaptive Maximum a Posteriori) tokenization optimizes subword segmentation for different languages without changing a model's underlying vocabulary or embeddings. By learning language-specific token probabilities over a single shared vocabulary, it significantly improves morphological and structural alignment for both natural text and source code, requiring zero language labels at inference time.
What Problem Does This Paper Address?
Most modern language models rely on tokenizers (like Byte-Pair Encoding) that are heavily optimized for English. When applied to non-English languages—especially morphologically rich languages (e.g., Finnish, Turkish) or non-Latin scripts—these tokenizers tend to over-segment words into tiny, semantically opaque fragments. This over-segmentation degrades downstream performance and inflates API costs due to longer sequence lengths.
Existing solutions usually involve training a new tokenizer from scratch or adapting a pretrained model's vocabulary. However, both approaches are computationally expensive because they require retraining or retrofitting token embeddings.
The authors of LangMAP point out a crucial, overlooked detail: the poor segmentations aren't always caused by a missing vocabulary. Often, the correct subwords already exist within the multilingual tokenizer, but the global, English-centric parameters force the tokenizer to choose suboptimal splits. LangMAP addresses this by changing how the tokenizer selects subwords from its existing vocabulary based on the language of the input text.
Methods
LangMAP builds upon the UnigramLM tokenization algorithm, which treats tokenization as finding the most likely (Maximum a Posteriori, or MAP) sequence of tokens under a unigram probability distribution.
Instead of maintaining a single global token distribution, LangMAP learns a collection of language-specific distributions ($\phi^\ell$) over the same fixed vocabulary.
- Training: For each language, the parameters are estimated independently using the Expectation-Maximization (EM) algorithm on a language-specific corpus.
- Inference: At inference time, the tokenizer doesn't need to be told which language the text is written in. It constructs a single shared segmentation lattice for the input string, computes the MAP segmentation under every language-specific distribution, and selects the segmentation that yields the highest overall likelihood. This process implicitly performs language identification during tokenization.
Because the vocabulary is fixed, the segmentation lattice is identical across languages and only needs to be built once per input, keeping inference highly efficient.
Datasets
The authors evaluated LangMAP across 14 base model tokenizers (from families like Gemma, Llama, Mistral, and Qwen), covering 9 natural languages and 9 programming languages.
- Parameter Estimation: 25M tokens per language from FineWeb2 (for natural languages) and The Stack (for programming languages).
- Intrinsic Evaluation: FLORES-200 parallel dataset for natural languages and StarCoder data for code. Universal Dependencies (UD) treebanks were used to evaluate morphological alignment.
- Extrinsic Evaluation (Fine-tuning): Qwen2.5 (0.5B and 1.5B) models adapted on 100M tokens and evaluated on MultiBLiMP (grammatical acceptability), Global-PIQA (commonsense reasoning), and Belebele (reading comprehension).
Key Insights and Ideas
- Vocabulary is a Bound, Not a Destiny: Reweighting existing token probabilities can dramatically alter and improve segmentation quality without touching model weights or embeddings.
- Implicit Routing: Tokenization can double as a highly accurate language identifier. By picking the language distribution that maximizes string likelihood, LangMAP correctly routes inputs to their native segmentation rules automatically.
- Low Sample Complexity: LangMAP's language-specific distributions stabilize incredibly quickly—requiring only 1,000 to 2,000 training examples per language to converge.
Key Results
Natural Language Morphological Alignment
LangMAP consistently improved morphological boundary alignment (measured via MorphScore) for languages whose scripts were already well-represented in the base vocabulary. The largest gains were seen in Latin-script languages like German, Turkish, Hungarian, and Finnish.
However, for languages like Hindi and Thai, the improvements were near zero or slightly negative. This occurred because the base tokenizers contained virtually no native subwords for these scripts, leaving LangMAP with no alternative segmentations to choose from.
Code Tokenization
For programming languages, LangMAP consistently improved Abstract Syntax Tree (AST) leaf-boundary alignment and reduced identifier fragmentation across all 9 tested languages (such as Go, PHP, and Python).
Downstream Performance
In fine-tuning experiments with Qwen2.5, models adapted using LangMAP achieved significantly higher accuracy on target-language grammatical acceptability (MultiBLiMP), with the largest jumps observed in agglutinative languages like Finnish (+16.2% for the 0.5B model). Benefits were neutral or inconsistent on knowledge-heavy tasks like Global-PIQA and Belebele, which depend more heavily on pretrained knowledge than syntactic understanding.
Limitations and Future Work
The primary limitation of LangMAP is that it is strictly bounded by the representational capacity of the base vocabulary. If a language's essential morphemes are entirely missing from the pretrained vocabulary, reweighting probabilities cannot fix the underlying blind spot.
Additionally, the method requires labeled data during the training phase to estimate the language-specific distributions. The authors suggest that future work could explore pairing LangMAP with lightweight vocabulary extension techniques or developing unsupervised methods to learn these distributions without explicit language labels.
Summary updated