Learning to Predict Code-Switching Points

Thamar Solorio, Yang Liu

Abstract This study investigates the feasibility of predicting code-switching points—locations where a bilingual speaker transitions between languages—using machine learning. By framing the problem as a binary classification task at word boundaries, we evaluate Naive Bayes and Value Feature Interval models on an English-Spanish corpus. While standard performance metrics are constrained by the optional nature of code-switching, human evaluations demonstrate that Naive Bayes models can generate transitions that are nearly as natural as those produced by humans.

Introduction

Code-switching (CS) is a sophisticated linguistic phenomenon where bilingual speakers alternate between languages within a single conversation. For Natural Language Processing (NLP) systems, CS poses a significant challenge, as most tools are optimized for monolingual data. Predicting these switch points is critical for reducing model perplexity and improving the robustness of multilingual speech and text processing.

Methodology

The task is defined as binary classification at every word boundary: "Switch" or "No Switch." We compared Naive Bayes (NB) and Value Feature Interval (VFI) algorithms. Due to the high class imbalance (96% non-switches), discriminative models like SVMs were found to overfit. Features included lexical data (word forms, lemmas), language identification, Part-of-Speech (POS) tags, and BIO chunks. We also utilized monolingual TreeTaggers for both English and Spanish to provide syntactic context.

Naive Bayes performance across various feature combinations, highlighting the impact of different linguistic features on precision and recall.

Results and Evaluation

Quantitative evaluation on a corpus of spontaneous "Spanglish" conversation yielded a peak F1-measure of 0.28 for the Naive Bayes model. This modest score reflects the "intrinsically motivated" nature of CS; because switching is often optional, a model may predict a grammatically sound switch that does not appear in the gold standard.

To better assess model performance, we conducted a human naturalness study. Participants rated sentences on a 5-point scale. The Naive Bayes model achieved a score of 3.33, which is statistically comparable to human-generated sentences (3.64) and significantly higher than random baselines.

Comparison of average naturalness scores across different sentence generation methods, showing Naive Bayes' proximity to human performance.

Key Insights

Our findings suggest that models can learn the grammatical "scaffold" of code-switching. For example, the NB model correctly identified that switches are more frequent following Spanish words, aligning with the Matrix Language Frame model. Additionally, specific "trigger words" such as "anyway" or "yeah" were identified as high-probability transition points.

Conclusion and Future Work

Predicting code-switching points is a viable task for machine learning, provided that evaluation accounts for the subjective nature of language. Future work will explore larger datasets and more complex multi-word expressions to further bridge the gap between machine and human performance.

Summary updated

BibTeX
@inproceedings{solorio2008learning,
  author = {Thamar Solorio and Yang Liu},
  title = {{Learning to Predict Code-Switching Points}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2008},
}
Figure