Code-switching—the practice of alternating between two or more languages in a single conversation—is a global phenomenon, especially prevalent on social media. However, building AI that understands code-switched text is notoriously difficult due to the "data hunger" problem. While monolingual datasets are vast, labeled code-switched datasets are comparatively tiny. This paper introduces VACS (Variational Autoencoder for Code-Switching), a generative framework designed to synthesize realistic code-switched text to bridge this data gap.
The Challenge of Code-Switching
State-of-the-art neural language models require massive amounts of data to perform effectively. Existing generative models, such as standard GANs or VAEs, often struggle with code-switching because it involves a complex, informal interplay between different grammars and "switching signals" that are absent in monolingual text. Standard models often fail to capture the specific linguistic "rhythm" of how and when a speaker transitions between languages.
The VACS Architecture
The authors propose VACS, a novel hierarchical VAE architecture that explicitly separates the semantic "content" of a sentence from the "act of switching" languages. This decoupling allows the model to learn the nuances of each independently.
The Two-Level Hierarchy
VACS encodes text into a two-part latent representation:
- Lower Level ($z_c$): Captures the syntactic and contextual "content" of the sentence.
- Upper Level ($z_l$): Models the language-switching behavior (the "switching pattern").
The Generation Process
Unlike standard models that attempt to predict the next word directly, the VACS decoder follows a controlled two-step approach. First, it uses the switching embedding ($z_l$) to generate a sequence of language ID labels (e.g., English, English, Hindi). Second, conditioned on these labels and the context embedding ($z_c$), it selects specific words from the appropriate language's vocabulary.
Experimental Setup and Insights
The researchers focused on Hindi-English (Hinglish), using a combination of real tweets, monolingual data, and parallel corpora created via translation APIs. VACS was benchmarked against several baselines, including standard VAEs (pVAE/rVAE) and GANs (pGAN/rGAN).
Key insights from the experiments include:
- Decoupling is Crucial: By separating switching patterns from semantic content, VACS avoids the confusion standard VAEs face when mapping two different grammars into a single latent space.
- GANs Struggle with Diversity: Generative Adversarial Networks often suffered from "mode collapse" or failed to generate appreciable code-switching rates when trained on small datasets.
- Curriculum Learning: The most effective training strategy involved starting with monolingual data, followed by synthetic code-switched data, and finally fine-tuning on real data (the "Mono | gCS" approach).
Key Results
The primary metric for success was the impact on a "payload" language model's performance. Using VACS-generated synthetic text for training resulted in a 33.06% drop in perplexity on natural Hindi-English text compared to models trained only on natural data.
Beyond perplexity, VACS demonstrated superior structural realism. It produced sentences with length distributions and switching frequencies (measured by M-Index and Span Entropy) that closely mirrored real human-generated tweets. Qualitative analysis further showed that VACS could generate multiple diverse code-switched versions of the same underlying context, proving a robust understanding of linguistically plausible switch points.
Limitations and Future Work
While VACS produces syntactically sound sentences, the authors note that the semantics and pragmatics are not always perfect—sentences may be grammatically correct but logically inconsistent. Future work may involve extending this hierarchy to handle multi-party code-switching (three or more languages) or incorporating Part-of-Speech (POS) tags to improve the logical coherence of generated text.
Summary updated