What Language is This? Ask Your Tokenizer.

Clara Meister, Ahmetcan Yavuz, Pietro Lesci, Tiago Pimentel

Executive Summary

Language Identification (LID) is a foundational component of modern multilingual natural language processing (NLP). It facilitates corpus curation, training data analysis, and the cross-lingual evaluation of Large Language Models (LLMs). While LID is often considered a "solved" problem for high-resource languages, existing systems remain notoriously brittle when faced with low-resource languages or closely related dialects.

To address this, researchers have introduced UniLID, a novel, generative approach to LID that repurposes the UnigramLM tokenization algorithm to classify text. By treating subword segmentation as a language-specific feature rather than a fixed preprocessing step, UniLID achieves state-of-the-art performance in low-resource settings—reaching approximately 70% accuracy with just five labeled samples per language—and significantly outperforms standard baselines on fine-grained dialect identification.

The Challenge of Language Identification

If an NLP pipeline cannot correctly identify a language, it cannot curate high-quality training data. Existing discriminative models, such as Facebook’s widely used fastText, rely on massive amounts of training data to learn boundaries between language classes. Furthermore, these models typically treat tokenization as a static, language-agnostic preprocessing step.

This paper argues that ignoring how a language is tokenized is a missed opportunity. The way a specific language naturally segments into subwords carries powerful morphological signals. For instance, a compound word might be segmented entirely differently in German compared to English. By forcing a single, global tokenization strategy, traditional models discard valuable linguistic evidence.

Introducing UniLID: A Generative Approach

UniLID flips the traditional LID paradigm by building directly on the UnigramLM tokenization framework. Instead of learning a discriminative boundary between languages, UniLID is a generative model. To predict a string’s language, it simply asks: Under which language’s specific statistical profile is this string most likely to have been produced?

The methodology relies on four core pillars:

  1. Language-Specific Distributions: Instead of utilizing one global tokenizer, UniLID learns a separate unigram distribution for every language over a shared, universal vocabulary.
  2. Segmentation as a Latent Variable: UniLID allows the "best" segmentation of a string to vary depending on the language being evaluated. It uses the Viterbi algorithm to find the most probable sequence of subwords for a given string under each language's specific distribution.
  3. Bayes’ Decision Rule: To classify a string, the model calculates the likelihood of the text under each language-specific model and applies Bayes' rule to determine the most probable language label.
  4. Modular Expansion: Because the architecture is modular, adding a new language does not require retraining the entire system. Practitioners can simply estimate a new unigram distribution for the new language and add it to the existing pool.

Datasets and Evaluation

The research team evaluated UniLID across a broad spectrum of LID regimes to test its robustness, efficiency, and accuracy:

  • GlotLID-C: A massive corpus covering nearly 2,000 language-script pairs.
  • DSL-ML 2024: A benchmark specifically designed for fine-grained dialect identification (e.g., distinguishing regional varieties of French, Spanish, and Portuguese).
  • WiLI-2018: Utilized for controlled ablations and sample efficiency tests.
  • UDHR & FLORES-200: Parallel text datasets used to evaluate cross-lingual performance.
  • Tatoeba: A dataset of short, noisy, community-contributed text to test out-of-domain robustness.

Key Insights and Results

UniLID demonstrates that generative classifiers can be highly effective, particularly in data-constrained environments. Because per-language distributions are naturally sparse (most tokens in a 100k vocabulary won't appear in a specific low-resource language), the model remains computationally lean.

  • Unprecedented Sample Efficiency: On the WiLI dataset, UniLID reached ~70% accuracy with only 5 samples per language, and ~90% with fewer than 50 samples. In stark contrast, fastText required hundreds of samples to achieve comparable generalization.
  • Mastery of Dialects: On the DSL-ML 2024 task, UniLID improved the macro-F1 score from 0.53 to 0.72 compared to fastText. It showed particular dominance in distinguishing French dialects, scoring a 0.534 F1 against the previous top system's 0.385.
  • Fewer False Positives: On the massive GlotLID-C test set, UniLID reduced the False Positive Rate (FPR) by roughly 25% compared to fastText. This is a critical improvement for web-scale crawling, where misclassifying a common language as a rare one can severely degrade dataset quality.
  • Training Speed: UniLID trained 9x faster than a 100-epoch fastText configuration on the full GlotLID-C corpus (17.8k seconds vs. ~163k seconds).
  • Plug-and-Play Integration: Because most modern LLMs already utilize UnigramLM-style tokenizers (like SentencePiece), UniLID can be integrated directly into existing pipelines without introducing new vocabulary overhead.

Limitations and Future Directions

While UniLID offers substantial improvements, the authors note a few limitations:

  • The Unigram Assumption: The model assumes tokens are independent (a "bag of subwords" approach). By ignoring the context between neighboring tokens, it may miss complex syntactic cues.
  • Script Bias: If the base vocabulary is heavily dominated by Latin-script data, performance on non-Latin scripts (like Greek or Hebrew) can lag. A more script-balanced base vocabulary is required to mitigate this.
  • Linear Scaling: Memory and storage requirements scale linearly with the number of languages. While this is highly manageable for a few hundred languages, supporting thousands of languages under strict latency constraints may eventually require hierarchical decoding or sparse representations.

Looking forward, the authors suggest that this generative, tokenizer-based framework could be extended beyond language identification to other text classification tasks, such as identifying the domain, register, or source of a document.

Summary updated

BibTeX
@inproceedings{meister2026what,
  author = {Clara Meister and Ahmetcan Yavuz and Pietro Lesci and Tiago Pimentel},
  title = {{What Language is This? Ask Your Tokenizer.}},
  booktitle = {International Conference on Machine Learning},
  year = {2026},
  url = {https://openreview.net/forum?id=HhWaVjXmLN},
}
Figure