Abstract
Accurate alignment between languages is fundamental for improving cross-lingual pre-trained language models (XLMs). Motivated by the natural phenomenon of code-switching (CS) in multilingual speakers, CS has been used as an effective data augmentation method that offers language alignment at word- or phrase-level, in contrast to sentence-level via parallel instances. Existing approaches either use dictionaries or parallel sentences with word-alignment to generate CS data by randomly switching words in a sentence. However, such methods can be suboptimal as dictionaries disregard semantics, and syntax might become invalid after random word switching. In this work, we propose EntityCS, a method that focuses on Entity-level Code-Switching to capture fine-grained cross-lingual semantics without corrupting syntax. We use Wikidata and the English Wikipedia to construct an entity-centric CS corpus by switching entities to their counterparts in other languages. We further propose entity-oriented masking strategies during intermediate model training on the EntityCS corpus for improving entity prediction. Evaluation of the trained models on four entity-centric downstream tasks shows consistent improvements over the baseline with a notable increase of 10% in Fact Retrieval. We release the corpus and models to assist research on code-switching and enriching XLMs with external knowledge.
Introduction
Cross-lingual language models (XLMs), such as XLM-R, serve as the foundation for modern multilingual Natural Language Processing. The efficacy of these models depends heavily on cross-lingual alignment—the ability to map concepts across diverse languages. Traditionally, alignment is achieved through parallel corpora, which are expensive and often scarce for low-resource languages.
Code-switching (CS), the practice of mixing multiple languages within a single utterance, offers a promising alternative for data augmentation. However, conventional CS methods typically rely on random word swapping or simple dictionary lookups. These approaches suffer from two primary limitations: semantic ambiguity, where context-free dictionaries lead to incorrect translations, and syntactic corruption, where swapping arbitrary parts of speech breaks grammatical structures.
To address these issues, we introduce EntityCS, a novel data augmentation framework that performs entity-centric code-switching. By focusing exclusively on entities (e.g., people, places, and technical concepts), EntityCS preserves the syntactic integrity of the source sentence while grounding the model in precise cross-lingual semantics.
Methodology
1. EntityCS Corpus Construction
The construction of the EntityCS corpus leverages the structured knowledge within English Wikipedia and Wikidata. Entities identified via "wikilinks" in Wikipedia articles are mapped to their corresponding Wikidata entries. Since Wikidata provides multilingual labels for these entries, an English entity can be precisely replaced with its equivalent in any of 92 other target languages.
To maintain consistency and avoid "language soup," all entities within a single sentence are switched to the same target language. This process resulted in a massive synthetic corpus of over 231 million code-switched sentences.
2. Entity-Oriented Masking Strategies
Beyond standard Masked Language Modeling (MLM), we propose two specialized training objectives to enhance the model's ability to predict and align entities across languages:
- Whole Entity Prediction (WEP): The model is tasked with predicting an entire multi-word entity based on its surrounding context.
- Partial Entity Prediction (PEP): Only specific tokens within an entity are masked. This forces the model to utilize the remaining (often code-switched) tokens of the entity to infer the missing parts, strengthening intra-entity cross-lingual associations.
Experimental Setup and Evaluation
We evaluated EntityCS-trained models on four diverse entity-centric downstream tasks in a zero-shot cross-lingual transfer setting (training on English, testing on target languages):
- WikiAnn: Named Entity Recognition (NER).
- X-FACTR: Multilingual Fact Retrieval.
- MultiATIS++ & MTOP: Slot Filling for task-oriented dialogue.
- XL-WiC: Word Sense Disambiguation.
Results and Discussion
EntityCS consistently outperformed the XLM-R baseline across all benchmarks. Notable results include:
- Fact Retrieval: A significant +10% absolute improvement in accuracy on X-FACTR, demonstrating that entity-centric training significantly improves the model's ability to store and retrieve factual knowledge across language barriers.
- Named Entity Recognition: A +2.8% gain on WikiAnn, outperforming state-of-the-art models that utilize more extensive parallel data.
- Non-Latin Language Performance: The method proved exceptionally beneficial for languages using non-Latin scripts (e.g., Arabic, Hindi, Chinese), where high-quality parallel data is often limited.
Key Insights
- Syntax Preservation: By restricting swaps to entities, the model learns cross-lingual mappings within a stable, grammatically correct English frame, preventing the learning of "broken" syntax.
- Efficient Fine-tuning: Updating only the embedding layer and the final two layers of the model was sufficient to achieve these gains, mitigating the risk of catastrophic forgetting.
Conclusion and Future Work
EntityCS demonstrates that entity-level code-switching is a powerful and efficient method for improving cross-lingual transfer. While highly effective, the current approach does not account for complex morphology (e.g., case endings in German). Future research will explore incorporating morphological inflections and extending the framework to non-English source languages. We release our corpus and models to facilitate further research in code-switching and knowledge-enriched XLMs.
Summary updated