Abstract
Code switching (CS) is a common phenomenon in communication but is handled poorly by many NLP applications. This paper explores CS language identification (LID) for corpus building, making the task more realistic by scaling it to hundreds of languages and considering models with simpler architectures for faster inference. We reformulate the task as a sentence-level multi-label tagging problem and investigate three architectures: OpenLID, MultiLID, and Franc. Our empirical evidence demonstrates that current approaches are inadequate for identifying multiple languages in a single sentence at scale.
Introduction
Language Identification (LID) is often considered a "solved" first step in NLP pipelines. However, this assumption breaks down when speakers mix languages, a practice known as code-switching. Most LID systems operate under a "one-document, one-language" assumption. While word-level LID exists for specific language pairs (e.g., Spanish-English), these systems do not scale to the "wild" internet, where millions of sentences across hundreds of languages must be processed quickly.
This research tackles the challenge of scalable, sentence-level multi-label LID. The goal is to build a system that can analyze a short string—like a tweet—and return a set of all languages present (e.g., [eng_Latn, tur_Latn]). This is a critical prerequisite for building large-scale code-switched corpora.
Methodology and Monolingual Baseline
The researchers compared three distinct approaches:
- OpenLID (Adapted Baseline): A fastText-based model trained for single-label identification across 200+ languages, modified with a probability threshold ($k=0.3$) to allow multi-label output.
- MultiLID (Native Multi-label Model): A novel architecture using sigmoid activation and Binary Cross Entropy (BCE) loss, treating each language's presence as an independent binary choice.
- Franc (Trigram Comparison): A popular off-the-shelf LID package using trigram distributions across 414 languages.
To establish a baseline, the models were first tested on the monolingual FLORES-200 dataset. As shown in Figure 2, OpenLID performs exceptionally well in this controlled environment.
Key Results: The Code-Switching Reality Check
The transition from monolingual to code-switched data reveals a massive performance gap. While models are successful on FLORES-200, their performance on code-switched (CS) datasets—covering pairs like Turkish–English, Basque–Spanish, and Mandarin–English—is a reality check for the field.
On the Turkish–English CS set, the Exact Match ratio for the best-performing model (MultiLID) plummeted to a staggering 0.0665, compared to the 0.926 achieved by OpenLID on monolingual data. This disparity is detailed in Figure 4, which highlights how rarely these models correctly identify the entire set of languages present in a code-switched sentence.
Analysis of Failure Modes
Several factors contribute to these poor results:
- The "Softmax" Constraint: Standard models are designed to pick one winner. Even with thresholding, they struggle to distribute probability mass effectively across two languages in short sentences.
- The Null Prediction Trap: OpenLID achieved a low False Positive Rate by simply returning no labels at all for 10-12% of code-switched sentences, choosing silence over error.
- Recall Disparity: Models often catch the "primary" language but miss the second. In Turkish-English text, MultiLID identified Turkish 73% of the time but caught the English component only 20% of the time.
- N-gram Fragility: Character n-gram models are easily confused by social media orthography. Creative spelling (e.g., "bursaaaaa") can cause models to hallucinate rare languages because the n-gram frequencies no longer match training data.
Limitations and Future Work
The authors identify three major hurdles for future LID research:
- Input Representation: N-grams are too fragile for informal, creative code-switched text; more robust embeddings are needed.
- Training Data Skew: Models are biased toward ubiquitous languages like English, which often "overpower" other languages in predictions.
- Defining the Task: The inherent ambiguity between "borrowed" words and true code-switching makes labeling difficult. Future models may need to embrace linguistic uncertainty rather than forcing binary labels.
In conclusion, while LID may be solved for monolingual text, identifying code-switching at scale remains an open and significantly more difficult challenge.
Summary updated