LangMAP: A Language-Adaptive Approach to Tokenization

TL;DR

LangMAP extends UnigramLM with language-specific MAP estimation, enabling multi-language tokenization from a shared vocabulary, improving morphological boundary alignment.

cs.CL 🔴 Advanced 2026-06-23 94 views
Clara Meister Suchir Salhan Andrzej Szablewski Pietro Lesci Paula Buttery Tiago Pimentel
multilingual processing tokenization algorithm model adaptation language-specific deep learning

Key Findings

Methodology

This paper introduces LangMAP, which integrates the UnigramLM probabilistic framework to handle multiple languages by learning separate language-specific unigram distributions ϕℓ over a shared vocabulary. During training, the EM algorithm estimates these parameters independently for each language, optimizing their fit to language-specific corpora. In inference, the system employs UniLID for automatic language identification, then computes the MAP segmentation likelihood under each language's distribution, selecting the segmentation with the highest probability. This approach allows for language-specific segmentation without altering the shared vocabulary or retraining the entire model. The core components include: • EM-based parameter estimation for each language; • language identification via UniLID; • MAP segmentation computation using Viterbi search over the shared lattice; • selection of the most probable segmentation across languages. The method is computationally efficient, scalable, and compatible with existing pretrained models.

Key Results

  • Across 14 open-source tokenizers, 9 natural languages, and 9 programming languages, LangMAP significantly improved morphological boundary alignment, with an average increase of 0.032 in MorphScore micro-F1, and recall improved by 0.086. In code, AST leaf boundary alignment improved consistently, with an average increase of 4.2%. Fine-tuning experiments showed that LangMAP enhanced grammatical acceptability (MultiBLiMP) by up to 3.5% in low-resource languages like Turkish and Finnish. The improvements were particularly notable in morphologically rich languages, demonstrating the method's effectiveness in capturing language-specific morphological structures.
  • The results indicate that LangMAP effectively adapts tokenization to individual languages without retraining models or modifying vocabularies. It enhances morphological boundary detection, reduces tokenization errors, and improves downstream grammatical tasks. While benefits on knowledge reasoning tasks like Global-PIQA and Belebele were mixed, the overall performance gains in linguistic and structural alignment suggest broad applicability. The approach's efficiency, requiring only a single shared lattice and independent language-specific distributions, makes it suitable for large-scale multilingual systems, reducing computational costs and facilitating rapid deployment.
  • These findings demonstrate that LangMAP offers a practical and scalable solution to the longstanding challenge of multilingual tokenization. By decoupling language-specific segmentation from the shared vocabulary, it enables models to better understand and process diverse languages, especially those with complex morphology or limited resources. The method's compatibility with existing models and datasets underscores its potential for widespread adoption in multilingual NLP pipelines, machine translation, code understanding, and beyond.

Significance

This research addresses a critical bottleneck in multilingual NLP: the trade-off between shared vocabularies and language-specific segmentation quality. Existing approaches either require retraining models or complex vocabulary adaptations, which are costly and inefficient. LangMAP offers a novel solution by leveraging probabilistic modeling and language identification to achieve language-specific segmentation without altering the underlying vocabulary or retraining. This significantly reduces computational overhead, facilitates rapid adaptation to new languages, and improves morphological and syntactic understanding across diverse linguistic contexts. The approach has broad implications for deploying scalable, high-performance multilingual systems, especially in low-resource settings where data scarcity hampers model performance. Its ability to enhance downstream tasks such as grammatical acceptability and code structure alignment underscores its practical value for both academia and industry.

Technical Contribution

The core technical contribution of this paper lies in extending the UnigramLM framework to a multi-language setting through independent estimation of language-specific unigram distributions over a shared vocabulary. The authors develop an EM-based training procedure that learns these distributions from language-labeled corpora, enabling each language to have tailored segmentation probabilities. At inference, the system employs a combined approach of language identification via UniLID and MAP segmentation computation, efficiently selecting the best segmentation without modifying the vocabulary. This approach preserves the benefits of a shared vocabulary—such as reduced model size and easier deployment—while allowing for fine-grained language adaptation. Additionally, the paper introduces an efficient lattice-based inference method that scales linearly with the number of languages, making it suitable for large multilingual systems. The theoretical guarantees of MAP estimation and the empirical validation across diverse languages and codebases mark significant advancements over prior methods that rely on vocabulary expansion or post-hoc adaptation.

Novelty

This work is the first to propose a language-adaptive tokenization scheme that operates solely by learning language-specific probability distributions over a fixed shared vocabulary, avoiding the need for vocabulary expansion or retraining. Unlike previous methods that modify vocabularies or rely on character-level models, LangMAP maintains a single vocabulary and introduces a probabilistic framework that enables language-specific segmentation through MAP inference. Its integration of automatic language identification with probabilistic segmentation is novel, providing an elegant and efficient solution to the challenge of multilingual tokenization. The approach effectively balances the trade-offs between model complexity, computational cost, and segmentation quality, setting a new standard for scalable multilingual NLP.

Limitations

  • While LangMAP significantly improves morphological boundary alignment, its performance diminishes for languages with poor vocabulary coverage or highly divergent scripts, such as certain low-resource or non-Latin languages. The reliance on quality language identification also introduces potential errors that can propagate into segmentation inaccuracies.
  • The method assumes availability of sufficient language-labeled corpora for parameter estimation, which may not be feasible for extremely low-resource languages. Moreover, the current implementation focuses on static corpora, limiting adaptability to dynamic or code-mixed inputs.
  • Although inference complexity scales linearly with the number of languages, in scenarios involving hundreds of languages or dialects, computational costs could become non-trivial. Future work should explore more scalable inference algorithms and unsupervised parameter estimation techniques.

Future Work

Future directions include developing unsupervised or semi-supervised learning methods to estimate language-specific distributions with minimal labeled data, extending the framework to handle code-mixed or dialectal inputs, and integrating contextual information for more robust language identification. Additionally, exploring joint training with downstream tasks such as translation or question answering could further enhance the utility of LangMAP. Investigating real-time inference optimizations and applying the approach to speech and multimodal data are promising avenues for broadening its impact. Ultimately, these efforts aim to create more flexible, efficient, and universally applicable multilingual NLP systems.

AI Executive Summary

Multilingual natural language processing (NLP) faces a persistent challenge: how to effectively tokenize diverse languages with a unified model. Traditional tokenization methods, such as Byte Pair Encoding (BPE) or UnigramLM, are optimized for resource-rich languages like English, often resulting in suboptimal segmentation for morphologically rich or low-resource languages. These issues manifest as over-segmentation, poor morphological boundary detection, and increased downstream task errors, hampering the deployment of truly universal NLP systems.

Existing solutions attempt to address this by training language-specific tokenizers or expanding vocabularies post hoc. However, these approaches are computationally expensive, requiring retraining or complex vocabulary adaptation, which limits scalability and flexibility. Moreover, they often compromise the shared vocabulary's universality, leading to increased model size and maintenance complexity.

In response to these limitations, the authors propose LangMAP, a novel tokenization scheme that extends the UnigramLM probabilistic framework to a multi-language setting. The key innovation lies in learning separate language-specific unigram distributions over a shared vocabulary during training, using an EM algorithm. During inference, the system employs an automatic language identification method—UniLID—to determine the input language, then computes the MAP segmentation likelihood under each language-specific distribution. The segmentation with the highest likelihood is selected, enabling language-adaptive tokenization without modifying the vocabulary or retraining the model.

Extensive experiments demonstrate that LangMAP significantly improves morphological boundary alignment across 14 open-source tokenizers, covering 9 natural languages and 9 programming languages. The results show consistent gains in boundary detection metrics, especially for morphologically complex languages like Finnish, Turkish, and Bengali. In code, AST leaf boundary alignment also improves, indicating better structural tokenization. Fine-tuning models with LangMAP further enhances downstream grammatical acceptability, with improvements up to 3.5% on MultiBLiMP benchmarks for low-resource languages.

This approach offers a practical, scalable solution for multilingual NLP, reducing the need for costly retraining and vocabulary expansion. Its ability to adapt to new languages with minimal overhead makes it highly suitable for deploying multilingual systems in real-world applications, including translation, multilingual chatbots, and code understanding. While some limitations remain—such as performance in extremely low-resource or script-divergent languages—the overall contribution marks a significant step forward in multilingual tokenization, promising broader accessibility and efficiency in NLP technology.

Deep Analysis

Background

The evolution of NLP has been driven by large-scale pretraining on massive corpora, leading to models like BERT, GPT, and T5 that rely heavily on effective tokenization. Traditional tokenizers such as BPE and UnigramLM excel in resource-rich languages but struggle with morphologically complex or low-resource languages, where over-segmentation and boundary misalignments are common. Multilingual models like mBERT and XLM-R attempt to unify multiple languages under a shared vocabulary, but often face trade-offs between universality and language-specific accuracy. Recent research explores vocabulary expansion, post-hoc adaptation, and character-level models, yet these solutions are computationally costly and often compromise model efficiency. The need for a scalable, language-adaptive tokenization method that maintains a shared vocabulary while providing language-specific segmentation remains unmet. This gap motivates the development of approaches like LangMAP, which leverages probabilistic modeling to reconcile these conflicting requirements.

Core Problem

The core problem addressed by this work is the suboptimal tokenization of diverse languages within a single shared vocabulary, leading to poor morphological boundary detection and downstream task performance. Existing models either require separate vocabularies for each language, incurring high storage and maintenance costs, or rely on post-hoc vocabulary modifications that are computationally expensive and inflexible. This results in a significant performance gap, especially for morphologically rich or low-resource languages, and hampers the scalability of multilingual NLP systems. Additionally, current methods lack an efficient mechanism to automatically identify the language of input text at inference, which is crucial for selecting the appropriate segmentation strategy. Overcoming these challenges requires a unified framework that can learn language-specific segmentation parameters without altering the shared vocabulary or retraining the entire model.

Innovation

The primary innovation of this paper is the integration of language-specific unigram distributions within a shared vocabulary framework, enabling adaptive tokenization without vocabulary modification. This is achieved by:

  • �� Learning separate unigram parameters ϕℓ for each language via EM, capturing language-specific morphological patterns;
  • �� Employing a shared vocabulary to maintain model simplicity and facilitate transfer learning;
  • �� Incorporating UniLID for automatic language detection during inference, allowing dynamic selection of the most probable segmentation model;
  • �� Utilizing MAP estimation to efficiently compute the most likely segmentation under each language model, leveraging a Viterbi search over a fixed lattice.

This combination results in a scalable, flexible, and effective multilingual tokenization scheme that outperforms traditional methods in boundary alignment and downstream task accuracy.

Methodology

  • �� Training phase:
  • �� Collect language-specific corpora, Cℓ, for each language ℓ.
  • �� Initialize unigram distribution ϕℓ using empirical token frequencies.
  • �� Run EM algorithm for 10 iterations:
  • �� E-step: compute expected token counts over corpus Cℓ using current ϕℓ.
  • �� M-step: normalize counts to update ϕℓ.
  • �� Repeat until convergence, obtaining language-specific parameters.
  • �� Inference phase:
  • �� Use UniLID to identify input language.
  • �� Construct a shared lattice of all possible tokenizations based on the fixed vocabulary.
  • �� For each language ℓ, compute MAP segmentation likelihood using ϕℓ.
  • �� Select the segmentation with the highest likelihood across all languages.
  • �� Output the chosen segmentation as the final tokenization.
  • �� Efficiency considerations:
  • �� The lattice is built once, shared across languages.
  • �� The per-language likelihood computations are linear in the number of languages, O(|Ω|).
  • �� This design ensures scalable and fast inference suitable for large multilingual systems.

Experiments

The experimental setup involved 14 open-source tokenizers, covering models from Gemma, LLama, Mistral, Qwen, and others, trained on datasets like FineWeb2 and The Stack. The evaluation spanned 9 natural languages, including German, Finnish, Turkish, Hindi, Bengali, Tamil, Arabic, and Thai, as well as 9 programming languages such as C, Java, and Python. For natural languages, corpora were drawn from Universal Dependencies treebanks, enabling morphological boundary evaluation via MorphScore. For code, parse trees generated by tree-sitter facilitated AST boundary analysis. Parameters for LangMAP were estimated with 10 EM iterations on 25 million tokens per language. The baseline was the original tokenizers, with comparisons based on intrinsic metrics (boundary alignment, entropy, compression) and extrinsic downstream tasks (grammar acceptability, reasoning, reading comprehension). Fine-tuning involved adapting pretrained models with LangMAP tokenization on 100 million tokens per language, assessing improvements in downstream performance.

Results

LangMAP consistently improved morphological boundary alignment, with an average increase of +0.032 in MorphScore micro-F1 and +0.086 in recall across nine languages. In code, AST leaf boundary alignment improved by approximately 4.2%, indicating better structural tokenization. Fine-tuned models showed a 2-3.5% increase in grammatical acceptability scores on MultiBLiMP, especially for agglutinative languages like Turkish and Finnish. The improvements were less pronounced on reasoning and comprehension tasks, suggesting that morphological gains do not always translate directly to higher-level cognitive tasks. The results validate that language-specific parameter estimation enhances tokenization quality without retraining models, offering a practical solution for multilingual NLP pipelines.

Applications

This approach is immediately applicable to improving tokenization in multilingual language models, translation systems, and code understanding tools. It allows for rapid adaptation to new languages with minimal computational overhead, making it suitable for deployment in resource-constrained environments. Industry applications include multilingual chatbots, search engines, and automated content moderation, where accurate tokenization directly impacts performance. In the long term, LangMAP can facilitate the development of truly universal NLP systems capable of handling diverse linguistic and coding inputs seamlessly. Its scalability and efficiency also open avenues for real-time multilingual processing in voice assistants, real-time translation, and cross-modal AI systems, potentially transforming how machines understand and generate human language.

Limitations & Outlook

Despite its advantages, LangMAP faces limitations in languages with extremely limited corpora or poor script coverage, where the learned distributions may be unreliable. The automatic language identification step, while robust, can misclassify inputs with code-mixing or ambiguous scripts, leading to suboptimal segmentation. Computational costs, though linear, may become significant when scaling to hundreds of languages or dialects, especially in real-time applications. Additionally, the current framework assumes static corpora for parameter estimation, which may not adapt well to evolving language use or domain shifts. Future work should focus on unsupervised learning, dynamic adaptation, and integrating contextual cues to further enhance robustness and scalability.

Plain Language Accessible to non-experts

Imagine a giant kitchen where chefs from different countries prepare dishes using their own unique cutting styles. Some prefer fine slicing, others big chunks, and some use special spices. Previously, each chef needed their own set of knives and cutting techniques, which was time-consuming and expensive. Now, picture a smart, adjustable knife that learns each chef’s style during training. When a chef starts working, the knife automatically recognizes their preferred style and adjusts itself accordingly, even if the chef hasn't told it explicitly. This way, the same knife can serve many chefs, each getting perfectly sliced ingredients suited to their cuisine. Similarly, LangMAP trains a shared vocabulary on many languages but learns specific 'cutting styles'—probabilities—for each language. When processing new text, it identifies the language and slices the text into meaningful parts, just like the adjustable knife. This makes multilingual processing faster, more accurate, and easier to manage, much like a versatile kitchen tool that adapts to every chef’s needs.

ELI14 Explained like you're 14

Imagine you’re in a huge international school cafeteria, where students from all over the world bring their own special recipes. Some students like to cut their fruits into tiny pieces, while others prefer big chunks. Instead of having a different knife for each recipe, there's a super-smart knife that learns each student's cutting style during a training phase. When a student brings their fruit, the knife automatically figures out which style to use—whether to slice thin or thick—and adjusts itself accordingly. So, every student gets their fruit cut just the way they like it, without needing a new knife or special instructions. Now, think of language as the recipe and words as the fruits. LangMAP is like that smart knife: it learns how each language 'prefers' to be broken into parts. When it sees a new sentence, it guesses which language it is, then slices it into meaningful pieces in the best way for that language. This way, computers can understand different languages more accurately and quickly, just like everyone gets their fruit cut just right at the cafeteria!

Glossary

Maximum a Posteriori (MAP)

A statistical inference method that finds the most probable hidden variable value given the observed data and model parameters. In this paper, used to determine the best segmentation of text.

Applied during inference to select the segmentation with the highest likelihood under each language's distribution.

UnigramLM

A probabilistic language model assuming each token is generated independently according to a unigram distribution. Used as the core framework for tokenization in this work.

Serves as the basis for the probabilistic segmentation approach extended to multiple languages.

EM Algorithm

An iterative optimization technique that estimates model parameters by alternating between expectation (E) and maximization (M) steps, especially useful with latent variables.

Used to learn language-specific unigram distributions from corpora.

UniLID

A neural-based language identification method that predicts the language of a given text segment, combining probabilistic cues from language models.

Automatically identifies input language during inference for optimal segmentation.

Viterbi Algorithm

A dynamic programming algorithm that finds the most likely sequence of hidden states (or tokens) in a probabilistic model.

Used to efficiently compute the MAP segmentation over the shared lattice.

Vocabulary

The set of all tokens (subwords or units) used by a tokenizer to encode text, typically fixed before training.

LangMAP maintains a shared vocabulary across languages, learning language-specific distributions over it.

Morphological Boundary

The boundary between morphemes within a word, indicating morphological segmentation points.

Improved boundary detection is a key metric in evaluating tokenization quality.

Abstract Syntax Tree (AST)

A tree representation of the syntactic structure of source code, with leaf nodes representing tokens or identifiers.

Used to assess tokenization quality in programming languages by measuring leaf boundary alignment.

Multilingual Pretrained Model

A deep learning model trained on multiple languages simultaneously, capable of understanding and generating multilingual text.

The target for applying LangMAP to improve tokenization without retraining.

Multi-task Learning

Training a model on multiple related tasks to improve generalization and robustness.

Potential future extension to jointly optimize tokenization and downstream tasks.

Open Questions Unanswered questions from this research

  • 1 While LangMAP effectively improves morphological boundary detection, its performance in languages with extremely limited data or scripts not well covered by the shared vocabulary remains uncertain. Exploring unsupervised or semi-supervised methods for parameter estimation could address this gap. Additionally, integrating contextual cues for more robust language identification and segmentation, especially in code-mixed or informal text, is an open challenge. Extending the approach to dynamic corpora and real-time applications also warrants further research.

Applications

Immediate Applications

Multilingual Search Engines

Enhance search accuracy across multiple languages by improving tokenization, especially for morphologically complex or low-resource languages, leading to better retrieval and ranking.

Machine Translation

Use LangMAP to produce more accurate subword units aligned with morphological boundaries, improving translation quality for diverse language pairs.

Multilingual Chatbots

Enable chatbots to understand and generate text in multiple languages more effectively by leveraging adaptive tokenization, reducing misinterpretations.

Long-term Vision

Universal Multilingual NLP Systems

Develop systems capable of processing any language with minimal adaptation, supporting global communication and information access.

Cross-lingual and Multimodal AI

Integrate LangMAP with speech and vision models to build comprehensive AI capable of understanding multilingual multimodal inputs, transforming human-computer interaction.

Abstract

Language-specific tokenizers improve tokenization quality and the downstream performance of models on those languages. However, using such a tokenizer comes at a cost: either a new model must be trained from scratch, or the vocabulary of an existing pretrained model must be adapted. We propose Language-adaptive Maximum a Posteriori (LangMAP) Tokenization, a tokenization scheme that extends the UnigramLM algorithm to the multilingual setting, producing language-specific tokenization from a single shared vocabulary. Notably, LangMAP can be used when training a multilingual language model from scratch or to adapt a pretrained model's tokenizer to individual languages without changing its vocabulary. While language labels are required at training time, a key feature of the algorithm is that it then performs language-specific tokenization at inference without knowledge of the input's language. Across 14 open-source tokenizers, 9 natural languages, and 9 programming languages, LangMAP improves morphological boundary alignment and, for all coding languages tested, alignment with abstract syntax tree (AST) leaf boundaries. In fine-tuning experiments, results are mixed: LangMAP improves target-language grammatical acceptability (MultiBLiMP) on the languages tested; its benefits are less consistent on knowledge-related tasks (Global-PIQA, Belebele).

cs.CL

References (20)

MultiBLiMP 1.0: A Massively Multilingual Benchmark of Linguistic Minimal Pairs

Jaap Jumelet, Leonie Weissweiler, A. Bisazza

2025 56 citations ⭐ Influential View Analysis →

Global PIQA: Evaluating Physical Commonsense Reasoning Across 100+ Languages and Cultures

Tyler Chang, Catherine Arnett, A. Eldesokey et al.

2025 10 citations ⭐ Influential

What Language is This? Ask Your Tokenizer

Clara Meister, Ahmetcan Yavuz, Pietro Lesci et al.

2026 1 citations View Analysis →

Length-aware Byte Pair Encoding for Mitigating Over-segmentation in Korean Machine Translation

Jungseob Lee, Hyeonseok Moon, Seungjun Lee et al.

2024 13 citations

Language Model Tokenizers Introduce Unfairness Between Languages

Aleksandar Petrov, Emanuele La Malfa, Philip H. S. Torr et al.

2023 235 citations View Analysis →

FineWeb2: One Pipeline to Scale Them All - Adapting Pre-Training Data Processing to Every Language

Guilherme Penedo, Hynek Kydlícek, Vinko Sabolcec et al.

2025 116 citations View Analysis →

You should evaluate your language model on marginal likelihood over tokenisations

Kris Cao, Laura Rimell

2021 33 citations View Analysis →

MAGNET: Improving the Multilingual Fairness of Language Models with Adaptive Gradient-Based Tokenization

Orevaoghene Ahia, Sachin Kumar, Hila Gonen et al.

2024 30 citations View Analysis →

Universal Dependencies

Joakim Nivre, Daniel Zeman, Filip Ginter et al.

2021 316 citations

The Mathematics of Statistical Machine Translation: Parameter Estimation

P. Brown, S. D. Pietra, V. D. Pietra et al.

1993 4931 citations

Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer

Colin Raffel, Noam Shazeer, Adam Roberts et al.

2019 26268 citations View Analysis →

Tokenization Is More Than Compression

Craig W. Schmidt, Varshini Reddy, Haoran Zhang et al.

2024 96 citations View Analysis →

Maximum likelihood from incomplete data via the EM - algorithm plus discussions on the paper

A. Dempster, N. Laird, D. Rubin

1977 54222 citations

Why do language models perform worse for morphologically complex languages?

Catherine Arnett, Benjamin K. Bergen

2024 59 citations View Analysis →

Evaluating Morphological Alignment of Tokenizers in 70 Languages

Catherine Arnett, Marisa Hudspeth, Brendan O'Connor

2025 11 citations View Analysis →

XLNet: Generalized Autoregressive Pretraining for Language Understanding

Zhilin Yang, Zihang Dai, Yiming Yang et al.

2019 9419 citations View Analysis →

No Language Left Behind: Scaling Human-Centered Machine Translation

Nllb team, M. Costa-jussà, James Cross et al.

2022 1847 citations View Analysis →

Subword Regularization: Improving Neural Network Translation Models with Multiple Subword Candidates

Taku Kudo

2018 1361 citations View Analysis →

Superbizarre Is Not Superb: Derivational Morphology Improves BERT’s Interpretation of Complex Words

Valentin Hofmann, J. Pierrehumbert, Hinrich Schütze

2021 95 citations View Analysis →

The Belebele Benchmark: a Parallel Reading Comprehension Dataset in 122 Language Variants

Lucas Bandarkar, Davis Liang, Benjamin Muller et al.

2023 326 citations View Analysis →