Abstract: Language Identification (LID) is an important component of many multilingual natural language processing pipelines, where it facilitates corpus curation, training data analysis, and cross-lingual evaluation of large language models. Despite near-perfect performance on high-resource languages, existing systems remain brittle in low-resource and closely related language settings. We introduce UniLID, a simple and efficient LID method based on the UnigramLM tokenization algorithm, leveraging its probabilistic framing, parameter estimation technique and inference strategy. In short, we learn language-conditional unigram distributions over a shared tokenizer vocabulary but treat segmentation as a language-specific phenomenon. Our formulation is data- and compute-efficient, supports incremental addition of new languages without retraining existing models, and can naturally be integrated into existing language model tokenization pipelines. Empirical evaluations against widely used baselines, including fastText, GlotLID, and CLD3, show that UniLID achieves competitive performance on standard benchmarks, substantially improves sample efficiency in low-resource settings - surpassing 70% accuracy with as few as five labeled samples per language - and delivers large gains on fine-grained dialect identification.
TL;DR
UniLID is a novel language identification (LID) method that repurposes the UnigramLM tokenization algorithm to treat text segmentation as a language-specific feature. It is exceptionally data-efficient, achieving over 70% accuracy with just five samples per language, and significantly outperforms standard baselines like fastText on fine-grained dialect identification.
Introduction: The Challenge of the Long Tail
Language Identification (LID) is often considered a "solved" problem in NLP, but that’s only true for high-resource languages like English or French. Current systems remain brittle when faced with the "long tail" of the world's languages—specifically low-resource settings and closely related dialects (e.g., distinguishing between variants of Bosnian, Croatian, and Serbian).
Existing tools like Google’s CLD3 or Meta’s fastText typically rely on character n-gram statistics. While fast, these models often require massive amounts of curated data to generalize well and struggle with the subtle morphological differences that define dialects. Furthermore, adding a new language to these models usually requires retraining the entire system.
Methods: Segmentation as a Linguistic Signal
The authors introduce UniLID, which shifts the perspective from "what characters are in this string?" to "how would this language's tokenizer break this string apart?"
The method is built on the UnigramLM algorithm. In a standard setup, a tokenizer uses a fixed vocabulary and a single strategy to segment text. UniLID, however, learns a separate language-conditional unigram distribution for every language over a shared vocabulary.
The core logic follows a generative framework:
- Training: For each language, the model uses the Expectation-Maximization (EM) algorithm to estimate the probability of each subword token in the shared vocabulary.
- Inference: When a new string arrives, UniLID calculates the most probable segmentation (using a Viterbi-style algorithm) for every candidate language.
- Decision: It applies Bayes’ rule to find which language’s specific distribution makes the input string most likely.
By treating segmentation as a language-dependent latent variable, the model captures meaningful morphological structures that simple character-level models miss.
Datasets
The researchers evaluated UniLID across a massive range of benchmarks to test different "regimes" of LID:
- GlotLID-C: A massive dataset covering 1,940 language-script combinations, focused on the long tail.
- DSL-ML 2024: Specifically designed for fine-grained dialect identification (e.g., variants of Spanish, Portuguese, and French).
- UDHR & FLORES-200: Parallel corpora used to evaluate cross-lingual performance on identical semantic content.
- Tatoeba: Short, noisy, user-contributed sentences to test robustness.
- WiLI-2018: A balanced Wikipedia-based benchmark used for detailed ablation studies on sample efficiency.
Key Insights: Extreme Sample Efficiency
- Segmentation is a Linguistic Fingerprint: The way a word is broken into subwords (tokens) is a powerful indicator of language. A segmentation that makes sense in Spanish might be statistically impossible in Portuguese, even if the characters are identical.
- Extreme Sample Efficiency: One of the most striking findings is that UniLID can learn a language's profile from almost nothing. While fastText fails to generalize with very small datasets, UniLID hits 70% accuracy with 5 samples and exceeds 90% with 50 samples.
- Incremental Growth: Because each language has its own independent distribution, you can add a 1,001st language to the model without touching the parameters of the first 1,000. This makes it highly modular for production environments.
- Tokenizer Integration: UniLID can use the existing vocabulary of a large language model (like Llama 3 or Mistral). This means LID can be integrated directly into the tokenization step of an LLM pipeline with minimal overhead.
Key Results: Dialect Mastery and Robustness
- Dialect Mastery: On the DSL-ML 2024 benchmark, UniLID improved the macro F1 score from 0.53 (fastText) to 0.72, showing a massive leap in distinguishing closely related varieties.
- Lower False Positives: On the full GlotLID-C test set (nearly 2,000 labels), UniLID reduced the False Positive Rate (FPR) by roughly 25% compared to fastText. This is critical for web-scale crawling where misclassifying common languages as rare ones creates "data pollution."
- Robustness to Length: UniLID consistently outperformed baselines on shorter text sequences (100–150 characters), a notoriously difficult area for LID.
- Efficiency: Despite being a research implementation, UniLID showed shorter training times than fastText and comparable inference throughput.
Limitations and Future Work
The authors acknowledge a few key limitations:
- The Unigram Assumption: The model assumes tokens are independent (a "bag-of-tokens" approach). It ignores the order of tokens, which means it might miss syntactic cues.
- Memory Scaling: While computationally efficient, the model's memory footprint grows linearly with the number of languages. Supporting thousands of languages might become challenging in strictly memory-constrained environments.
- Future Directions: The team suggests moving from "most probable segmentation" to "marginalizing over all possible segmentations" to better handle uncertainty, and exploring $n$-gram dependencies between tokens to capture more complex linguistic patterns.
Summary updated