Code-switching (CS)—the practice of alternating between two or more languages in a single conversation—is a linguistic reality for nearly half the world's population. However, most Natural Language Processing (NLP) models struggle with CS text due to a severe lack of diverse, high-quality training data. While synthetic generation methods exist, they often lack the fine-grained control necessary to capture the rich stylistic and structural diversity of real-world bilingual speech.
COCOA (Controllable Code-switched Generation) addresses this gap by introducing a novel encoder-decoder framework designed to transform monolingual text into code-switched text with precise, user-defined control over language mixing, burstiness, and formality.
Methodology
COCOA is built upon the mT5 (multilingual T5) architecture and utilizes two distinct control mechanisms to manage different linguistic attributes:
- Encoder-side Control (Syntactic Attributes): To control the Code-Mixing Index (CMI) and Switch-Point Index (SPI), the model employs "attribute vectors." At inference time, these vectors are scaled by the desired attribute value and added to the encoder's hidden representations. This allows for continuous, fine-grained control rather than being limited to discrete categories.
- Decoder-side Control (Lexical Attributes): For controlling Formality, the framework uses FUDGE. A binary classifier, trained on formal and informal prefixes, re-weights the decoder's output probabilities during generation to favor choices aligning with the target formality level.
To prevent the model from simply "copying" the source text, the authors utilized a multi-task training regimen. This included standard translation tasks and a primary task where 20% of source tokens were masked, forcing the model to learn underlying semantics and generate the embedded language naturally.
Key Insights: Continuous vs. Discrete Control
A major finding of the study is the superiority of the "scaled vector" approach over traditional "tagging" methods (e.g., using a <high_cmi> tag). The scaled vector approach allows the model to interpolate and generate text for attribute values it may not have encountered during training, providing much smoother control.
Furthermore, COCOA successfully decouples CMI (the ratio of language mixing) and SPI (the frequency of switching). This is critical because a high CMI can occur with either a low SPI (long blocks of each language) or a high SPI (frequent interleaving), and COCOA is the first model to control these independently.
Results and Impact
COCOA demonstrates high faithfulness, achieving a Pearson correlation of up to 0.92 between requested attribute scores and the actual scores of generated text. In human evaluations, COCOA significantly outperformed previous baselines in both naturalness and semantic consistency.
The utility of COCOA-generated data was further proven in downstream tasks:
- Language Modeling: Training on COCOA-generated data led to a 10% reduction in perplexity on real-world code-switched text.
- Sentiment Analysis: Using COCOA for data augmentation improved the Mean F1 score on the GLUECoS benchmark compared to other synthetic techniques.
Conclusion
COCOA provides a robust solution for generating diverse, high-quality synthetic code-switched data. While currently focused on Hindi-English pairs, the architecture's ability to provide "inference-time levers" for linguistic style and structure marks a significant step forward in making NLP models more inclusive of global linguistic practices. Future work will look toward extending these controls to the decoder side to potentially eliminate the need for parallel code-switched training data entirely.
Summary updated