Introduction
Code search is an indispensable part of modern software development, enabling engineers to locate relevant code snippets through natural language queries. However, a significant bottleneck exists: most high-quality datasets for training these models, such as CodeSearchNet (CSN), are predominantly English-centric. This creates a barrier for developers who are more comfortable searching in their native languages. While programming languages like Python or Java are universal, the natural language descriptions used to index and search them are not. This research addresses this "English-only" limitation by leveraging Neural Machine Translation (NMT) to transform the massive CodeSearchNet dataset into a multilingual resource covering French, Japanese, and Chinese.
Methodology
The researchers developed a systematic three-step approach to construct and validate a multilingual code search system.
1. Dataset Augmentation via NMT
The core of the approach involves using the M2M-100 model—a many-to-many multilingual translation model—to translate English "docstrings" (function documentation) from the original CodeSearchNet corpus. These docstrings were translated into French (FR), Japanese (JA), and Chinese (ZH). This process effectively creates a parallel corpus where code snippets are paired with descriptions in multiple natural languages.
2. Model Training and Configurations
The team utilized XLM-R (a multilingual variant of RoBERTa) as the base architecture. They explored three distinct training configurations to understand the impact of multilingual data:
- No-pre-training: A baseline using the standard XLM-R model.
- All-to-One: The model is trained on multilingual queries but paired with a single specific programming language.
- All-to-All: The model is trained on the entire mix of natural languages and programming languages simultaneously, encouraging the learning of a shared semantic space.
3. Quality Control and Back-translation
To assess the impact of translation "noise," the researchers employed back-translation. For instance, a Japanese query would be translated back into English to calculate BLEU scores. This allowed for a controlled experiment where the dataset was filtered to retain only high-quality translations, testing whether cleaner data leads to better retrieval performance.
Key Results and Discussion
The primary metric for evaluation was Mean Reciprocal Rank (MRR), which measures how high the correct code snippet appears in the search results.
Performance Across Languages
The "All-to-All" configuration emerged as the most robust, achieving performance parity with English-only models like CodeBERT while extending capabilities to multiple languages. As shown in the results table, the model achieved high MRR scores across various language pairs. For example, in the Go programming language, the model reached an MRR of .835 for English and .816 for Japanese.
Quantity Over Quality
A significant finding was the robustness of deep learning models to translation noise. While one might expect that filtering out "bad" translations would improve performance, the researchers found that aggressive filtering (removing over 150,000 pairs) actually led to a drop in MRR. This suggests that for code search, the sheer volume of data is more critical than perfect translation quality, as the model can learn underlying semantic patterns despite linguistic imperfections.
Generalization to Real-World Queries
To ensure the model's utility beyond docstrings, it was evaluated on human-annotated benchmarks like CoSQA and WQT. The results indicated that the NMT-augmented training data generalizes effectively to the shorter, often messier queries used by humans in real-world search scenarios.
Limitations and Future Work
Despite the success, several challenges remain. NMT models occasionally struggle with technical jargon or omit code-like sequences within text. Furthermore, docstrings serve as a proxy for search queries but do not perfectly mirror human search behavior. Future research could expand the scope to include more "low-resource" natural languages and a wider variety of programming languages.
The researchers have open-sourced their code and datasets, providing a foundation for the community to build more inclusive developer tools.
Summary updated