Elamur Research

Code-Switched Language Identification is Harder Than You Think

Paper · 2024 · Laurie Burchell, Alexandra Birch, Robert Thompson et al.

Summary

A sentence can begin in one language and finish in another. It can also switch for a phrase or a single word. A tool that files each sentence under one language may overlook these examples, even when it correctly identifies much of what the writer said. Burchell and colleagues study how to find such sentences automatically so they can be collected as training data. Their intended source is web text, where the languages present in a sentence are typically unknown in advance and the volume makes it important to process each sentence quickly.

The paper frames code-switched language identification as a question about the whole sentence. Given a short stretch of text, the system returns the set of language labels it finds, including the script where the label distinguishes it. The authors compare three ways to do this. OpenLID, an existing single-language classifier, returns every label whose probability clears a cutoff. MultiLID, their new classifier, scores each language independently and can return the two strongest labels if the runner-up meets a cutoff calculated for that sentence. Franc compares patterns of adjacent characters with language profiles and can return a second language when the two best matches are close. OpenLID and MultiLID learn from the same source of single-language examples. None of the three approaches is given the language pair at test time.

The authors evaluate the systems on six datasets that contain code-switching and on FLORES-200*, a separate benchmark whose sentences have one reference language each. On FLORES-200*, thresholded OpenLID returns the complete reference set with an exact match ratio of 0.926. For Turkish–English sentences annotated as containing both languages, the best exact match ratio is MultiLID’s 0.0618. MultiLID leads on exact match in the mixed-only subset of every dataset, but the scores show how frequently at least one label is missing or incorrect. The paper also finds that a low rate of false positives can accompany poor recovery. A system can avoid wrong labels by leaving difficult sentences unanswered, or by repeatedly choosing a familiar language and omitting the other.

The authors conclude that the tested approaches fall short for building a code-switched corpus. The errors reflect both the systems’ use of short recurring text patterns and a difficulty in deciding what the labels should mean. A clear switch between recognizable stretches can go undetected, while a lone expression may be hard even for a person to classify as a switch or a borrowing. The paper argues for evaluating complete label sets alongside false positives and partial matches, defining the labels with the intended use in mind, and investigating representations that can preserve evidence from short switches.

Deep dive: Code-Switched Language Identification is Harder Than You Think

Burchell and colleagues test whether fast language identifiers can detect the languages in mixed sentences accurately enough to build web corpora. · about 37 minutes to read

The problem and its context

Finding data for language technology

Code-switching is the use of different languages within the same utterance. In text, the languages might occupy recognizable stretches of a sentence, or the evidence for one language might be concentrated in a brief expression. The paper treats switching as a familiar part of communication that many applications in natural language processing handle poorly. It draws on the Survey of Code-switching for the linguistic and social context. The difficulty for language technology starts before an application has to understand what a mixed utterance means. It starts when a pipeline decides which text to keep.

The authors are interested in using web text to build a corpus, a collection of language examples assembled for later use. A collection of code-switched utterances could supply training examples for applications that need to handle multilingual communication. Such a collection is hard to assemble if the initial language filter assumes every input belongs to one category. An otherwise plausible label can send a mixed sentence into a monolingual collection. A system can also reject the sentence if its evidence is divided among several languages. Both outcomes make the switch invisible to downstream work.

The intended collection task gives language identification two responsibilities. One is to recognize text that contains a switch. The other is to name the languages involved, so the text can be assigned to a suitable collection. Recognizing a dominant language addresses only part of that job. A prediction of Turkish for a Turkish–English sentence may correctly identify much of the text while providing no signal that the sentence belongs in a Turkish–English corpus. Adding an unrelated language creates another problem. It can give an ordinary monolingual sentence the appearance of a switch or put a genuinely mixed sentence in the wrong collection.

These errors matter in different ways when the text to be found is scarce. A filter may see many sentences that do not contain the switch of interest for every sentence that does. Even a small tendency to attach an irrelevant label provides many opportunities for contaminants to enter the corpus. At the same time, an overly restrictive filter can discard examples that are already difficult to obtain. The authors connect this practical problem to the experience described in Language ID in the Wild. Finding usable examples requires paying attention to missed positives and false alarms in the population the filter will actually process.

Why the earlier tasks answered different questions

The paper situates its work in a field with a long history of assigning language names to text, as documented in Automatic Language Identification in Texts. Much of the broad-coverage work the authors discuss expanded the number of languages a tool could recognize. Some systems claimed coverage of over a thousand. Most general-purpose tools still expected monolingual input, or assumed that languages in a longer input occurred in separate blocks. An extensive inventory helps a system answer which language an input belongs to. Detecting several languages in the same short input requires a different kind of decision.

Earlier multilingual document identification addressed one version of that decision. A document may include several passages, each in a different language. Detecting those passages supports the segmentation of web text, an application represented by Automatic Detection and Language Identification of Multilingual Documents. In a sentence that switches briefly, the second language may contribute very little text. A method that relies on evidence accumulating across a passage faces a different problem when that evidence occupies a small part of a sentence.

The code-switching shared tasks discussed in the paper focused more closely on short inputs. The first shared task on code-switched language identification and the second shared task on code-switched language identification asked participants to label individual words for a known language pair. They also included categories for material such as names, foreign words and nonlinguistic content. Word labels can show exactly where a switch happens and what surrounds it. For the authors’ collection task, the useful output is a list of the languages in the sentence. Knowing where each switch starts would add detail to the record, but the collection decision can be made from the list alone.

The known pair also changes the classification problem. If the task specifies the two possible languages ahead of time, spelling or vocabulary need only distinguish those languages and the extra categories. A web filter in the authors’ setting has to decide which languages are present from a much larger inventory. A short sequence that is easy to place when the alternatives are known may be compatible with several languages in that inventory. It can also be difficult to tell whether a sequence is informative at all. The sentence-level task reduces the amount of detail the system must return while keeping this wider choice of candidate languages.

The authors also question the computational assumptions of some earlier approaches. They regard high-capacity classifiers based on the Transformer and attention as costly for screening large web crawls, where the identification step would run on a great deal of text. They choose lightweight approaches to explore performance under that practical constraint. The paper also points out that even broad-coverage single-language identification can look better on benchmarks than on web data, particularly for low-resource languages. Its discussion relates this gap to the evidence in Quality at a Glance. Adding code-switching means confronting that existing gap while also looking for evidence that may be brief or ambiguous.

What counts as a language in the output

The paper’s target is a set attached to a sentence-length input. A set records the presence of a language without counting how many times the writer switches to it. It also leaves out the order of the languages and how much of the sentence each accounts for. A sentence containing a long stretch of one language and a short stretch of another can receive the same output as a sentence in which the proportions are reversed. That design serves the corpus-building task. It keeps the decision focused on membership in a collection.

The labels distinguish a language variety and a writing system. The paper uses modified ISO 639-3 codes and gives eng_Latn for English in Latin script. The script component matters because a classifier’s ability to recognize a language in one writing system says little by itself about whether its inventory represents the same language in another. This becomes a practical constraint in the evaluation. Some existing code-switching datasets include transliterated languages for which the training inventory lacks the relevant written forms.

Sentence-level linguistic annotation removes the need to defend a label for every punctuation mark, name or emoji. It leaves a substantive decision about language membership. A single word may be an established loan, a deliberate switch or a spelling that permits several readings. With a set as the target, such a decision can change the status of the whole sentence. The paper therefore treats language identification as partly a problem of defining the category that the corpus is meant to capture.

The method, step by step

From a sentence to a set of labels

Each approach takes a short input, represents its text patterns and gives candidate languages scores. Those scores have different meanings across systems. For OpenLID they are normalized probabilities for competing classes. For MultiLID they are separate predictions about each language. For Franc they are relative measures of closeness to stored language profiles. The last stage turns those numbers into a discrete set. It is possible to change the set returned for a sentence by changing that stage alone, even when the ranking of languages stays fixed.

The authors select the three approaches to examine different ways of making this decision without requiring word-by-word tagging. Two use a lightweight trained classifier and share a source of training data. The third uses a pre-existing package with broader language coverage and a different scoring procedure. The complete process includes putting the resulting labels into a form that can be compared with the reference annotations.

From short text to a language set

The steps in order.

From short text to a language setStep 1: Take a sentence-length input1. Take a sentence-length inputStep 2: Represent its recurring word or character patterns2. Represent its recurring word or character patternsStep 3: Score candidate languages3. Score candidate languagesStep 4: Apply the system’s label selection rule4. Apply the system’s label selection ruleStep 5: Align language codes with the evaluation inventory5. Align language codes with the evaluation inventoryStep 6: Compare the returned set with reference labels6. Compare the returned set with reference labels

OpenLID uses a shared probability distribution

OpenLID comes from An Open Dataset and Model for Language Identification. The paper adapts its existing fastText classifier. To represent a sentence, fastText averages learned vectors for words and n-grams, which are short sequences of neighboring units. A vector is a collection of numbers the classifier can use as features. Averaging places evidence from the different parts of the sentence into a representation of fixed size. A linear classifier then uses that representation to give each language a raw score, called a logit.

OpenLID converts those logits with softmax. This operation gives every class a share of a fixed total probability. Raising the share allotted to one language leaves less probability available to the others. During training, cross-entropy measures how well this distribution supports the single reference language. The learning procedure adjusts the parameters to assign more probability to the correct class. This is a direct fit for a training example that belongs to one language.

The original decision rule can use the language with the largest probability. The adaptation in this paper instead returns every language with a probability strictly above a chosen cutoff. The change is made at prediction time. The underlying training task still rewarded identifying one language per input. If the evidence for a mixed sentence gives high probabilities to several languages, the new rule can return them together. If a likely language takes up much of the probability or the scores are spread among many classes, some or all labels can fall below the cutoff.

The paper gives two expressions for the cutoff setting and its consequence. The setting used in the experiments is:

k = 0.3

Here k is the minimum cutoff a probability must exceed to be returned, and 0.3 is its chosen value. The equals sign assigns the setting to k. Because the rule uses a strict comparison, a score exactly at the cutoff does not qualify.

Maximum label count ≤ ⌊k⁻¹⌋

The left side is the maximum number of labels the system can return. The symbol ≤ means that this number cannot exceed the expression on the right. The superscript ⁻¹ takes the reciprocal of k, and ⌊ ⌋ rounds that reciprocal down to an integer. The bound follows from sharing a fixed total of probability across the candidates. With the paper’s chosen cutoff, at most three labels can qualify. When every probability falls short of the required score, the returned set is empty.

This makes OpenLID a relatively conservative baseline. Labels have to clear a common minimum despite competing for probability. A sentence can receive the best-scoring language alone, a set with several languages, or no language at all. The evaluation distinguishes these cases because they have different implications for finding code-switching. A single correct label is partial evidence, while the empty set leaves the collection pipeline without even that.

MultiLID scores language presence separately

MultiLID retains the broad shape of the fastText approach. It condenses the input into a sentence vector, applies a linear transformation and obtains a score for each label. The authors implement it in Python and PyTorch. Its preprocessing removes emojis and hash symbols. The vocabulary includes words observed more than 1,000 times in the training data, together with the 2-to 5-grams of those words. The sentence vector comes from a bag of vocabulary embeddings. The representation pools these features across the sentence, with local order represented in the n-grams.

The substantial change is what happens after the linear transformation. MultiLID applies a sigmoid to each logit independently. A sigmoid maps a raw score to a value between zero and one. There is no shared total that the output scores must fit. Evidence for one class can therefore support a high score while another class also has a high score. The objective treats every language as its own present-or-absent decision. That is the sense in which MultiLID is a multi-label classifier even though its training data give each example just one positive language.

The paper introduces the score vector as follows:

L = [l₁, …, lₖ, …, lₙ]ᵀ

Here L is the vector of language scores, and lₖ is the score at language index k. The ellipses stand for intervening entries between the first component, l₁, and the last component, written lₙ here for the paper’s total of N languages. The superscript ᵀ turns the displayed row of entries into a column. The index k identifies a language in this expression. The same letter in the OpenLID rule names a cutoff.

For each component, the paper gives the following binary cross-entropy expression:

BCELoss(lₖ) = lₖ* · log(lₖ) + (1 − lₖ*) · log(1 − lₖ)

BCELoss(lₖ) is the paper’s name for the contribution associated with language k. The score lₖ is the sigmoid output, and lₖ* is the reference indicator, either 0 for absence or 1 for presence. The asterisk marks the reference value. The paper uses xₖ for the input representation associated with the prediction in its definition. The dot denotes multiplication, log is the logarithm, and the subtraction from 1 gives the complement of an indicator or score. The plus sign joins the presence and absence terms. The expression as displayed in the paper has the sign of a log-likelihood. Binary cross-entropy as a loss to minimize uses the negative of that expression.

For a language that is present, the indicator makes the presence term active. For an absent language, it makes the absence term active. The authors sum the contributions across the output vector. Its positive entries are sparse because there are many candidate languages and very few are present in any input. The training setup retains that sparsity. Every training sentence comes with a single language label even though the scoring rule can express several positive decisions.

Training on single-language sentences was a practical choice. The authors lacked code-switched training examples for most languages, and a broad-coverage approach would be difficult to use if it required examples for every pair. Training on the shared OpenLID data also gives the comparison with OpenLID a common data source. The experiment consequently asks whether separate scores learned from monolingual text can also recover the languages in a mixed sentence. It leaves open what supervised examples of mixing would add.

MultiLID chooses the runner-up relative to the sentence

Once the sigmoid scores are available, MultiLID still needs a rule for returning labels. The authors report that a fixed cutoff was ineffective on these unnormalized outputs. They instead compare a candidate’s score with the overall pattern of scores for the current sentence. A sparse target encourages most scores to be small. The scores that are unusually high relative to the rest of the vector can then guide selection.

The rule uses the mean of the scores and their standard deviation. The mean describes the overall level of support across candidates. The standard deviation describes how spread out their scores are around that level. The cutoff is the mean plus two standard deviations, a setting chosen empirically using the LinCE training sets. The resulting cutoff can differ across sentences. Even if a runner-up has the same raw score in two inputs, it can be kept in one and dropped in the other because the rest of the vector differs.

MultiLID always returns the highest-scoring language. It returns the second-highest language only when that score exceeds the dynamic cutoff. A strong top score guarantees a first choice, and a weak top score also produces one. The rule therefore makes the runner-up decision conditional on the score distribution but gives the first label no corresponding rejection option. It also limits the returned set to two labels in spite of the scoring layer’s ability to assign high scores to more candidates.

The two decisions have different effects. Always returning the strongest label can preserve useful information when only one language is clear. It can also attach a label when the input provides little reliable evidence. Letting the runner-up qualify relative to the rest of the sentence makes the rule responsive to different score patterns. It does not establish that the second language is genuinely present. That depends on whether MultiLID learned to give the relevant text a distinct score and whether the runner-up is the correct candidate.

Franc compares an input with language profiles

Franc provides a baseline with a separate training history and a broader inventory of 414 languages. The authors use the pretrained Python package. Franc examines character trigrams, short sequences of three adjacent characters. It compares the trigram distribution in the input with distributions associated with candidate languages. The package uses script information in deciding which languages to compare. It then orders the candidates by their distance from the input’s pattern.

Franc scales the comparison so the closest language receives a score of 1. This describes its position relative to the other candidates. The best available match can receive that score even when the input is difficult to identify. The authors lower the minimum valid input length to 1 so that short strings can be considered. This relaxes the length restriction. The paper later observes that mixed-script text can still yield no usable label.

The output rule keeps the closest language and adds the next closest if the latter’s score exceeds 0.99. The authors choose this threshold empirically with the LinCE training sets, as they do for MultiLID’s runner-up rule. The interpretation of the number differs. For Franc, the criterion asks whether the runner-up is almost as close as the leading candidate on the package’s scale. For MultiLID, the criterion is whether the runner-up stands out against a distribution of separately predicted scores.

Franc also needs a mapping from its returned language codes to the evaluation inventory. If a code is outside FLORES-200*, the authors use the Python package langcodes to look for an equivalent. A tag distance below 10 is required for the mapping. If there is a match, its code replaces Franc’s original code. Otherwise the prediction retains its original tag. When computing the metrics, the authors handle languages outside FLORES-200* as empty tags. This convention affects the relationship between the raw guesses Franc generates and the labels that ultimately enter evaluation.

Turning existing annotations into sentence labels

The test collections come with different kinds of annotation. Some identify the language of each token. Others provide an utterance-level label. For a token-annotated example, the evaluation takes the languages observed among the labels and combines them into a sentence-level set. A sentence with both relevant languages becomes a code-switched example. One with a single language becomes a monolingual example, regardless of how the other material in the sentence is tagged.

If no language is assigned, the authors discard the example. A line consisting entirely of names or emojis can fall into that category. For corpora that already distinguish mixed and monolingual utterances, the authors use the supplied utterance-level information to form the reference. This brings datasets with different original annotation schemes into a common scoring procedure. It also means that the sentence-level reference inherits the decisions made by the original annotators about what counted as language evidence.

OpenLID supplies the common training data for the two trained classifiers. The LinCE training data inform the selection rules for MultiLID and Franc, while the LinCE validation data have a separate role as evaluation inputs. The authors release code for obtaining and transforming the datasets, training the classifiers and computing the metrics. Their data-sourcing instructions also distinguish collections they downloaded from social-media datasets obtained through a request or through contact with the dataset authors.

Experiments and results

Test collections and their balance

The experiments combine wide single-language coverage with a narrower collection of mixed-language examples. The authors use six code-switching datasets covering eight languages. These sets vary in source, annotation practice and the share of examples that actually contain a switch. Keeping the monolingual examples inside them provides a test of whether a system can serve both kinds of input. Testing the mixed subsets separately provides a closer view of the examples the authors want to collect.

The Turkish–English dataset contains text from Twitter and the Ekşi Sözlük forum. Its original language tags are attached to tokens, which the authors recombine into sentences. The resulting evaluation set has 376 lines, with 98.9% labeled as code-switched in the dataset description and composition table. The Indonesian–English dataset also begins with language labels on tokens in Twitter posts. Its processed set has 825 lines, of which 93.5% are mixed. The original work on Indonesian–English code-mixed Twitter data supplies the annotations for that set.

BaSCo supplies the Basque–Spanish evaluation set. It begins with Spanish and Basque examples from text used to train bilingual chatbots. Volunteers produced equivalents in Euskañol, a Basque–Spanish mixture, and annotators checked the resulting utterances. The authors take the available monolingual and mixed utterances and use the existing utterance-level language labels. The processed set contains 2304 lines, with 59.8% marked as code-switched. Its inclusion provides a source of mixed utterances created differently from the naturally occurring social-media material.

The LinCE benchmark supplies the Spanish–English and Modern Standard Arabic–Egyptian Arabic datasets. Both are based on Twitter and come with word-level annotations. The authors evaluate on the validation sets because the test sets are private. After filtering and conversion to sentence labels, Spanish–English has 3247 lines, with 35.2% marked as mixed. The Modern Standard Arabic–Egyptian Arabic set has 1107 lines, with 14.5% marked as mixed. For the Arabic set, the task involves distinguishing varieties that a language identifier might collapse into a shared category.

ASCEND supplies the Mandarin Chinese–English examples. The original corpus contains conversational speech, while the authors evaluate the written renderings of utterances. They take them from ASCEND’s training split, which serves as evaluation material for language identification here. The processed set has 9869 lines, 27.8% of them labeled as code-switched. It provides an important case for Franc because mixed utterances in the set can contain different scripts within the same input.

FLORES-200* provides the broad single-language comparison. The wider FLORES-200 benchmark contains professional translations based on 842 web articles and includes 3001 sentences for each of 204 language varieties. The authors follow earlier OpenLID work by evaluating on 201 varieties from the dev-test split. The processed subset contains 203,412 lines and has a reported code-switched share of 0. The earlier FLORES evaluation datasets and the FLORES-101 benchmark give the benchmark context. Here the translations supply a test of language identification across many varieties.

What the metrics count

Exact match ratio, false positive rate, and Hamming loss are the metrics used in the primary evaluation. They ask different questions about the same predictions. Exact match asks whether the system recovered the complete language set for the sentence. Hamming loss checks every individual language decision and counts disagreements. False positive rate measures erroneous assignments among examples for which a language is absent. The combination lets the reader see whether a classifier makes many incorrect additions, misses present languages or produces the right set as a whole.

For exact match, the authors count each sentence once. The predicted set has to equal the reference set, regardless of order. A sentence with Turkish and English in the reference counts as an error if the system returns Turkish alone. It also counts as an error if the classifier returns both correct labels plus an unrelated language. The strictness fits an evaluation where a reference set and a predicted set imply membership in a particular corpus.

Exact match ratio = (1/N) ∑ᵢ₌₀ᴺ⁻¹ I(ŷᵢ = yᵢ)

Here N is the number of evaluated sentences, and i indexes them. The summation sign ∑ adds the terms from index 0 through N−1. The prediction for sentence i is ŷᵢ, with the hat marking a predicted value, and yᵢ is its reference set. Inside I, the equals sign tests whether those sets match. The indicator I is 1 when the condition holds and 0 otherwise. Multiplication by 1/N averages those indicators over the sentences. A larger value is better.

Hamming loss gives partial credit by treating every possible language label as a separate binary decision. A missing label produces a disagreement. So does a label added where it is absent from the reference. A system that gets one part of a mixed sentence right can therefore fare better under Hamming loss than a system that gets neither part right, even though both fail exact match. Most classes are absent on any given input, which is important when reading the small values reported for a large inventory.

Hamming loss = (1/(L · N)) ∑ᵢ₌₀ᴺ⁻¹ ∑ₗ₌₀ᴸ⁻¹ (Yᵢ,ₗ ⊕ Ŷᵢ,ₗ)

Here N is the number of sentences and L is the number of language classes. The index i runs over sentences and l runs over language classes. Yᵢ,ₗ indicates whether class l occurs in the reference for sentence i. Ŷᵢ,ₗ is the corresponding prediction, again marked by a hat. The exclusive-or operator ⊕ yields 1 when the indicators differ and 0 when they agree. The two summations add all such disagreements, and the factor 1/(L · N) divides by the total number of sentence–language decisions. The dot is multiplication. A smaller value is better.

For false positive rate, the paper starts with a separate calculation for every language class. It considers the examples where that language is absent and measures how often the system attaches the label anyway. The reported aggregate is a macro-average, so the language classes contribute equally to the average. This is useful for recognizing how often the filter gives a sentence an unwarranted label, including labels outside the pair that a particular dataset was built to study.

False positive rate = FP / (TN + FP)

FP counts false positives for a language, the sentences incorrectly assigned that label. TN counts true negatives, the sentences that lack the language and are correctly left without its label. The plus sign combines these counts into the total reference negatives for that language. The slash divides erroneous assignments by that total. A smaller value is better. A missed reference label has no direct effect on this fraction, which is why the paper reads it alongside measures that account for omissions.

The paper also reports precision and recall as diagnostics. Precision asks how often the system is right when it predicts a label. Recall asks how frequently the system recovers a label when the reference contains it. With a broad inventory and evaluation sets focused on a pair of labels, some per-class ratios can be undefined. The formulas identify the cases. Precision needs at least one prediction of the class and recall needs at least one reference occurrence. Neither ratio includes true negatives in its denominator.

Precision = TP / (TP + FP)

TP counts true positives, predictions of a language when it appears in the reference. FP counts predictions of the language when it is absent. The sum TP + FP counts all predicted instances of the class. The slash divides the true ones by that total.

Recall = TP / (TP + FN)

TP again counts true positives. FN counts false negatives, the instances where the reference includes the language but the prediction omits it. The sum TP + FN is the total number of reference instances of the class. The slash divides the recovered instances by that total. Recall can be high for one member of a pair while the other is seldom retrieved, a distinction that is central to the mixed-sentence results.

Performance on the single-language comparison

On FLORES-200*, thresholded OpenLID has the strongest exact match ratio. This is the setting in which its original training objective is most directly aligned with the reference. MultiLID’s independent scores permit additional languages, even though each sentence in this benchmark has one reference label. Franc has the broadest inventory and the weakest exact match in this comparison. Its candidates include languages beyond the set that supplies the reference answers.

Exact match ratio on the FLORES-200* dev-test subset

Thresholded OpenLID most often returns the complete reference set on the monolingual benchmark.

Exact match ratio on the FLORES-200* dev-test subsetOpenLID (this paper): 0.926OpenLID (this paper)0.926MultiLID: 0.861MultiLID0.861Franc: 0.672Franc0.672
The numbers
System or settingexact match ratio
OpenLID (this paper)0.926
MultiLID0.861
Franc0.672

OpenLID also has the lowest Hamming loss on this subset at 0.000694, against MultiLID’s 0.00121 and Franc’s 0.00279. For macro false positive rate, the scores are 0.000395 for OpenLID, 0.000885 for MultiLID and 0.00123 for Franc. The same ordering across the main metrics is consistent with OpenLID returning fewer superfluous labels. Its mean number of predictions is 1.02, compared with 1.11 for MultiLID and 1.08 for Franc. An average near one can include both empty and multi-label predictions, so this figure describes the total prediction tendency rather than the behavior on every sentence.

The supplementary columns show a narrower difference in recall between the two classifiers trained on OpenLID data. OpenLID has precision of 0.942 and recall of 0.939 on FLORES-200*. MultiLID has precision of 0.879 and recall of 0.933. Franc records precision of 0.666 and recall of 0.706. The paper uses the benchmark to establish a broad point of comparison for the behavior of the same output rules on the mixed datasets. The FLORES reference sets themselves give no occasion to reward the recovery of a second language.

Performance over all sentences in the code-switching datasets

The full code-switching evaluations contain both monolingual and mixed references. MultiLID is strongest on exact match where mixed sentences dominate. On the entire Turkish–English set, exact match is 0.0665 for MultiLID, 0.0213 for OpenLID and 0.00532 for Franc. On the entire Indonesian–English set, the respective values are 0.184, 0.0448 and 0.0182. Neither result affords much room for the easier case where a prediction can be complete with a single label, because the reference contains both languages on most lines.

On BaSCo, OpenLID has the highest full-set exact match at 0.360. MultiLID reaches 0.317 and Franc 0.201. On LinCE Spanish–English, OpenLID reaches 0.417 over the full validation-derived set, while MultiLID reaches 0.379 and Franc 0.146. The ordering of the learned classifiers reverses when only the mixed sentences are scored. This makes the full-set result informative about performance on the complete input stream, while the composition of that stream remains part of the explanation.

The full Mandarin Chinese–English results are close for the two classifiers trained on the same data. MultiLID scores 0.508 and OpenLID 0.507 in exact match, while Franc scores 0.301. Franc’s full-set false positive rate is 0.000332, lower than MultiLID’s 0.00130 and OpenLID’s 0.00197. The authors observed that its script-dependent procedure often returned no label when the input combined scripts. An empty prediction cannot add a false language, even when it misses everything that was present.

In Modern Standard Arabic–Egyptian Arabic, Franc has the highest full-set exact match at 0.691, followed by OpenLID at 0.625 and MultiLID at 0.345. Franc also has the lowest Hamming loss there at 0.00242, compared with 0.00631 for OpenLID and 0.00281 for MultiLID. Franc lacks Egyptian Arabic coverage and tends to output Modern Standard Arabic. The full set contains enough monolingual examples for this limited behavior to score well on both metrics. Its result illustrates how a system can take advantage of the composition of an evaluation without being able to return the pair that defines the code-switching task.

Hamming loss also adds a useful distinction in the sets where MultiLID leads in exact match. On the full Turkish–English set, MultiLID has Hamming loss of 0.00531, against 0.00732 for OpenLID and 0.00903 for Franc. On the full Indonesian–English set, MultiLID still has the best exact match, but OpenLID has Hamming loss of 0.00617, compared with 0.00680 for MultiLID and 0.00995 for Franc. Recovering the complete answer more often can coexist with making more individual label errors across the whole evaluation.

Performance on sentences annotated as mixed

The paper repeats the main evaluation using only the examples whose reference sets contain both languages. MultiLID leads in exact match on every such subset. This comparison gives a clearer picture of the test the authors designed around. A classifier must recover both languages on every input to be credited with a complete answer, and a system specializing in the majority monolingual class no longer benefits from that shortcut.

Exact match ratio on code-switched Turkish–English and Indonesian–English sentences

MultiLID returns both reference languages most often on the mixed portion of each dataset.

Exact match ratio on code-switched Turkish–English and Indonesian–English sentencesTurkish–English, MultiLID (this paper): 0.0618Turkish–English, MultiLID (this paper)0.0618Turkish–English, OpenLID: 0.0134Turkish–English, OpenLID0.0134Turkish–English, Franc: 0Turkish–English, Franc0Indonesian–English, MultiLID: 0.153Indonesian–English, MultiLID0.153Indonesian–English, OpenLID: 0.00649Indonesian–English, OpenLID0.00649Indonesian–English, Franc: 0.0013Indonesian–English, Franc0.0013
The numbers
System or settingexact match ratio
Turkish–English, MultiLID (this paper)0.0618
Turkish–English, OpenLID0.0134
Turkish–English, Franc0
Indonesian–English, MultiLID0.153
Indonesian–English, OpenLID0.00649
Indonesian–English, Franc0.0013

On the mixed Basque–Spanish sentences, exact match is 0.0247 for MultiLID and 0.0189 for OpenLID. On the mixed LinCE Spanish–English sentences, the results are 0.0184 and 0.00613 respectively. For mixed Mandarin Chinese–English, MultiLID gets 0.0365 and OpenLID 0.0164. For mixed Modern Standard Arabic–Egyptian Arabic, MultiLID gets 0.0994 and OpenLID 0.0373. Franc reaches 0 on exact match in each of these subsets. Its result on the Arabic pair is consistent with the absence of Egyptian Arabic from its inventory.

The difference between these scores and the full-set scores is especially informative in sets with many monolingual sentences. The full-set result answers how the classifier behaves on that particular mix of examples. The mixed-only result asks whether a sentence known to contain a switch can be given the complete target set. That restricted evaluation does not measure how many monolingual inputs would incorrectly be called mixed. The experiments need both views to describe the intended filtering task.

False positive rate also needs to be read with the scoring subset and the individual system in view. On mixed Spanish–English, the reported rates are 0.000985 for OpenLID, 0.00259 for MultiLID and 0.00190 for Franc. The tables have exceptions to the prose’s broad description of OpenLID as the most conservative by this metric. On mixed Mandarin Chinese–English, Franc’s reported rate is 0.000620 and OpenLID’s is 0.000703. On mixed Modern Standard Arabic–Egyptian Arabic, Franc’s is 0.000127 and OpenLID’s is 0.000587. In both subsets Franc has an exact match ratio of 0. A low rate of adding wrong languages can accompany an inability to return the complete pair.

What the ablations show

The paper reports no formal component ablation. It compares classifiers with a shared training source, changes which examples enter the evaluation, examines empty predictions and label frequencies, and inspects selected Turkish–English errors. These analyses offer evidence about where failures occur. They vary in how well they can distinguish one explanation from another.

Shared training data and different output rules

OpenLID and MultiLID provide the closest comparison because they use the same training data and similar lightweight designs. OpenLID learns to allocate probability among mutually exclusive choices and applies a fixed threshold at prediction time. MultiLID learns to score each class independently and uses a sentence-dependent rule for the second choice. Their contrasting behavior is consistent with these design choices. OpenLID is strong on FLORES-200*, while MultiLID recovers complete language sets more frequently on the known mixed sentences.

The comparison changes more than the output activation. It includes differences in preprocessing, feature construction, the training loss and the rules translating scores into labels. The scores therefore describe the complete systems. They cannot establish how much of MultiLID’s advantage comes from the sigmoid, how much comes from returning a second label more readily, or what would happen if OpenLID used a different decision rule with the same underlying scores. The shared data remove one confounding factor and leave several others.

Franc serves a different purpose. It tests a profile-based approach with more candidate languages, different training material and script-dependent selection. Its results reveal failure modes worth considering in a broad-coverage filter. They cannot isolate the effect of changing the number of languages or choosing character trigrams, because several properties change together. Its high full-set score on the Arabic comparison is particularly useful as a warning about aggregate results, since the coverage gap is known independently of its ranking on that test.

Empty predictions and conservative output

OpenLID can return an empty set if every language probability is below the threshold. The authors count these cases because a system that makes fewer guesses has fewer opportunities to add wrong labels. The FLORES-200* empty rate is 0.092% on the full evaluation. On full Spanish–English it is 10.6%, rising to 12.0% among the mixed sentences. In Mandarin Chinese–English the reported rate is 1.91% over the full set and 4.42% on its mixed portion. These cases show that refusing to make a prediction can fall disproportionately on the kind of sentence the corpus builder seeks.

The pattern depends on the dataset. In Indonesian–English, OpenLID returns an empty set on 9.46% of the full set and 9.21% of the mixed subset. The difference there goes in the other direction, and the whole set already consists predominantly of mixed examples. In the Arabic comparison the empty rate is 0.632% over all sentences and 1.24% for mixed sentences. The comparisons describe when the chosen rule abstains. They supply evidence for the authors’ interpretation of some low false positive rates without treating abstention as the only source of missed labels.

Returning a single correct label can also produce a low false positive rate while still missing the switch. For a genuinely mixed sentence, a one-label prediction can be entirely free of erroneous additions. Under exact match, it still fails. A comparison of empty rates can separate abstention from some other errors, but it cannot by itself tell what proportion of the nonempty predictions contain the right languages. That is where the per-language diagnostics and predicted sets become informative.

Uneven recall within the known pairs

The authors compute per-language precision and recall over the full code-switching datasets. Precision for the included reference languages is generally high. Egyptian Arabic is an exception, with reported precision of 0.645 for OpenLID, 0.485 for MultiLID and 0 for Franc. The learned classifiers can confuse the Arabic varieties, and Franc cannot supply the Egyptian Arabic label. The paper’s zero for Franc is reported in the context of that missing coverage. Its Egyptian Arabic recall is 0.000, while its Modern Standard Arabic recall is 0.995.

The Turkish–English recall results show how much the two learned classifiers can favor different parts of the same sentence. OpenLID’s recall is 0.952 for Turkish and 0.032 for English. MultiLID’s is 0.731 for Turkish and 0.206 for English. On a test set dominated by mixed sentences, high recall for Turkish can be achieved through predictions that routinely omit English. MultiLID finds English more often, though it also retrieves Turkish less often. The exact match scores show what happens when both labels must be recovered together.

The Indonesian–English results give a similar comparison with near-matching recall for Indonesian. OpenLID reports recall of 0.727 for Indonesian and 0.066 for English. MultiLID reports 0.723 for Indonesian and 0.372 for English. A reader who examined only Indonesian recall would see comparable performance. The English results show that the shared training source and similar broad design can yield different sensitivity to a second language. They also make the exact match advantage on mixed Indonesian–English easier to understand.

Recall alone cannot show whether the two languages were found in the same sentence. It gives each language credit across its own reference instances. A system can recover each member of a pair on different inputs and still seldom identify both in a single prediction. Similarly, precision calculated for the expected pair gives no direct indication of how many different outside labels are also being proposed. The analysis helps explain why the authors retain metrics that operate on complete sets and metrics that explicitly count spurious assignments.

The variety of languages returned

Each code-switching test set has a specified pair in its references, but the outputs contain many distinct language labels. On Turkish–English, the paper reports 54 unique predicted languages for MultiLID, 11 for OpenLID and 97 for Franc. On Spanish–English it reports 126 for MultiLID, 86 for OpenLID and 234 for Franc. On Mandarin Chinese–English the respective counts are 134, 85 and 225. These are counts across an entire dataset. They show how far outside the reference pair the systems can range, including labels returned infrequently.

The paper proposes several reasons for this spread. The normalization in OpenLID can make it harder for weak candidates to clear the cutoff. MultiLID’s independent scores can allow a rarer label to remain competitive, especially as a runner-up. Franc has a larger pool of candidates from which to draw. For the classifiers trained on OpenLID data, a change in domain may also contribute. Their training text is mainly formal, while much of the evaluation material comes from social media. The counts are consistent with these mechanisms. They do not measure how much each mechanism contributed.

The Arabic dataset produces a narrower spread. MultiLID predicts 18 unique languages, OpenLID 10 and Franc 8 across the full set. Franc’s relative restraint there is compatible with its strong inclination towards Modern Standard Arabic and its lack of Egyptian Arabic coverage. The counts thus describe the diversity of the guesses, while exact match and recall indicate whether that diversity helps to recover the relevant variety. A small inventory of predictions may be desirable only if it still includes the reference labels.

What the Turkish–English examples reveal

The qualitative analysis focuses on Turkish–English because the set is overwhelmingly code-switched and exact match is low. Turkish alone is the most frequent prediction for both OpenLID and MultiLID. The authors find no mixed sentence on which both produce the correct complete set. Their shared correct predictions are on sentences labeled Turkish alone. This suggests that the stronger performance of MultiLID over the mixed subset reflects, in part, successes on examples where OpenLID makes a different decision.

The paper describes two examples with substantial runs of both languages. One starts with Turkish about a song and a coffee shop and then switches into English. MultiLID returns both languages and OpenLID returns Turkish alone. Another starts with a long English stretch and finishes in Turkish. OpenLID returns the pair, while MultiLID returns English alone. The authors see no clear surface difference that would explain why the two approaches succeed on different examples. Both cases provide recognizable stretches of each language, so a short or linguistically ambiguous switch is insufficient as a general explanation for the failures.

A third example includes repeated letters in words around the two-language material. OpenLID assigns Standard Latvian. MultiLID assigns Latgalian and Wolof. The authors suggest that the unusual spellings may distort the recurring character patterns on which language identification relies, and relate the example to the behavior discussed in Language ID in the Wild. This interpretation is plausible from the input and predictions. The paper reports no experiment that regularizes the spelling of that sentence and then measures the change.

The authors also discuss examples that separate difficulties in prediction from difficulties in defining the reference. A post with an English request followed by a Spanish reply supplies a recognizable switch between stretches. A mostly Spanish post with a single expression that resembles English can be harder to interpret, particularly when the spelling leaves the writer’s intention uncertain. The qualitative evidence therefore points to distinct problems. Some reference switches seem straightforward and still defeat the classifiers. Other potential switches raise a genuine question about which label a corpus should assign.

Limitations

Limits the authors identify

The authors emphasize that their mixed-language test coverage is small relative to the range of language combinations used in communication. The available sets are concentrated in relatively high-resource languages, particularly English. The broad monolingual coverage of FLORES-200* cannot supply evidence about code-switching in all those varieties. The exclusion of some existing test sets is itself informative. The OpenLID training inventory does not include Indian languages written in Roman characters, and the authors identify LinCE datasets with transliterated Hindi and Nepali that they consequently cannot use.

The annotation problem also persists at sentence level. Switching for a single word may be difficult to distinguish from borrowing, and closely related languages or varieties can be difficult to tell apart in a short fragment. Annotators can disagree even when the text is legible and the labels are clearly specified. The paper recommends that the definition fit the downstream use. In corpus building, a convention about where to draw the line affects which text will be available to an application trained on the collection.

Training imbalance is another limitation named by the authors. The number of OpenLID training examples varies substantially across classes. This may encourage the trained classifiers to predict some languages more readily because of their representation in the training data. Yet the systems do not explicitly encode which languages are likely to co-occur in an utterance. English, for example, is common in the switching considered by the authors. The paper distinguishes the effect of uneven monolingual training exposure from the possibility of useful information about language pairs, and leaves the role of both for further study.

The authors also acknowledge limits in their evaluation materials and inspection. The qualitative analysis of Turkish–English relies on surface judgments because none of the authors speaks Turkish. They report that the social-media datasets are anonymized and direct researchers to the data sources so that distribution can be controlled. They also note concerns raised by updates to FLORES about the reliability of the test material and the choice of variety names. They retain the earlier labels to support comparison with OpenLID and point to the updated FLORES+ resource for future evaluation.

Limits that follow from the setup

The task is motivated by web-scale processing, and the systems were chosen with efficiency in mind. The reported experiments give label-quality metrics without a measured throughput comparison or a resulting web crawl corpus. The conclusion about suitability for corpus building is an inference from errors on the evaluation data. The paper does not observe how the predicted sets would affect a downstream application trained on the resulting corpus. It also does not measure how corpus quality would vary with the prevalence of code-switching in a particular crawl.

The test sets supply complementary kinds of text, though their differences limit cross-dataset causal comparisons. The Basque–Spanish examples were elicited and checked. The LinCE evaluations use validation data from Twitter. ASCEND supplies written representations of speech from a split intended for training in its original setting. Differences in exact match can reflect language coverage, script, genre, the proportion of mixed examples and the process used to annotate them. A comparison between two datasets does not isolate which of those factors made one more difficult.

There is a further distinction between broad language coverage and broad coverage of switching. The sentence-label formulation can express a set with several languages. The mixed evaluations are organized around pairs. MultiLID and Franc also use rules that return at most two candidates, while OpenLID’s selected threshold permits three. The experiments therefore say little about how the approaches would handle utterances with more than two reference languages. They also do not require the system to identify the location or extent of a switch.

The development choices leave other questions open. The paper uses LinCE training data to choose the runner-up rules for MultiLID and Franc, then uses LinCE validation data in part of the evaluation. This keeps the examples used for choosing the rule distinct from those used for scoring it. The fixed choices still reflect the development settings. The paper does not trace the recovery and false-positive tradeoff across a range of thresholds. A different operating point could change the balance between abstention, missed languages and incorrect extra labels.

Finally, the authors’ concern about n-gram representations is supported by the errors of several systems that rely on them. The experiments do not include a matched comparison with a representation that keeps a different kind of evidence from short stretches of text. They also do not add code-switched training data in a controlled comparison. The results show that the particular combinations of representation, training and selection studied here are inadequate for the intended use. They leave open which change would yield the greatest improvement.

What came after

The later citing works cover several settings in which the paper’s distinctions matter. Their titles identify the problems they address, while the citation links establish a connection to Burchell and colleagues’ study. Those facts do not establish which classifiers, selection rules or metrics the later studies adopted, or what results they obtained with them.

The Survey of Code-switched Arabic NLP takes up progress and challenges in Arabic code-switching more broadly. The connection is particularly direct in the case of language varieties. Burchell and colleagues’ Modern Standard Arabic–Egyptian Arabic comparison shows how a classifier can score well on a full set by favoring one variety while being unable to identify the other. That case is relevant to a survey concerned with how Arabic NLP handles switching and with the distinctions its labels preserve.

CommonLID takes up the re-evaluation of language identification on web data. This returns to the deployment setting that motivated Burchell and colleagues. Their study uses annotated benchmarks to probe behavior relevant to a web filter and argues that conventional scores can miss errors that matter for corpus collection. A re-evaluation centered on web data brings the source of the input into focus. The citing connection alone does not say whether CommonLID evaluates code-switching with the same sentence-level task.

Robust Language Identification for Romansh Varieties focuses on robust identification at the variety level. In Burchell and colleagues’ task, a language code can encode distinctions within a broader language category, with consequences for what counts as a correct set. The Arabic case makes those consequences visible. The Romansh study addresses variety-level identification in a different setting, where preserving the intended label distinction is central to the stated problem.

Improving Language Identification for Code-Switched Speech shifts the identification question to speech and foregrounds accented English. Burchell and colleagues include utterances sourced from speech in the Mandarin Chinese–English evaluation, but their classifiers receive written text. A study centered on accented speech addresses a different source of evidence for language identity. The connection is the mixed-utterance problem, with the later work’s title locating its investigation in spoken input and accent.

CS-YODAS addresses a mined dataset of code-switched speech in the wild. Its stated contribution returns to the collection goal that motivated Burchell and colleagues and places it in a speech setting. The distinction between finding authentic mixed examples and assigning each example the right language set carries over as a question about corpus construction. The citation links the two collection problems, while the later work’s title leaves its mining procedure and evaluation criteria unspecified.

Cite

Cite as Laurie Burchell, Alexandra Birch, Robert Thompson and Kenneth Heafield. 2024. Code-Switched Language Identification is Harder Than You Think. Proceedings of the 18th Conference of the European Chapter of the Association for Computational Linguistics (Volume 1: Long Papers).

The paper itself, not this page. BibTeX from the library's record of the work. DOI 10.18653/v1/2024.eacl-long.38

@inproceedings{burchell2024code,
  title = {{Code-Switched Language Identification is Harder Than You Think}},
  author = {Laurie Burchell, Alexandra Birch, Robert Thompson and Kenneth Heafield},
  booktitle = {Proceedings of the 18th Conference of the European Chapter of the Association for Computational Linguistics (Volume 1: Long Papers)},
  year = {2024},
  doi = {10.18653/v1/2024.eacl-long.38},
  url = {https://doi.org/10.18653/v1/2024.eacl-long.38}
}

↑ back to top

This page in Markdown https://md.research.elamur.ai/free/en/papers/burchell-2024-code-switched-language-identification-is/