MCoNaLa: A Benchmark for Code Generation from Multiple Natural Languages

Zhiruo Wang, Grace Cuenca, Shuyan Zhou, Frank F. Xu, Graham Neubig · DOI

TL;DR

This paper introduces MCoNaLa, a new benchmark dataset for natural language (NL) to code generation that extends beyond English to Spanish, Japanese, and Russian. The authors demonstrate that current state-of-the-art models struggle significantly with these non-English languages, highlighting the need for more language-comprehensive approaches in code intelligence.

What Problem Does This Paper Address?

The field of natural language to code generation has seen rapid advancements, enabling applications like code summarization and automatic code writing. However, these advancements are overwhelmingly English-centric. This creates a significant barrier for developers who are not proficient in English, limiting their access to these powerful tools. The paper aims to address this gap by creating a benchmark that allows for the evaluation of code generation models across multiple natural languages, moving beyond the English-only paradigm.

Methods

The authors built upon the methodology of the English Code/Natural Language Challenge (CoNaLa) dataset. They collected natural language intents and corresponding Python code snippets from Stack Overflow forums in Spanish, Japanese, and Russian. To ensure high-quality data, they employed native speakers proficient in both the target language and Python. A key part of their annotation process involved rewriting intents to disambiguate them and align them with the code snippets, often by specifying variable names found in the code. They also used a bootstrapped MBART classifier to help filter out irrelevant "how-to" questions. For evaluation, they explored three train-test settings: "translate-train" (translating training data to the target language), "translate-test" (translating test data to English), and "zero-shot" (training on English and testing directly on target languages).

Datasets

The primary dataset introduced in this paper is MCoNaLa. It consists of 341 Spanish, 210 Japanese, and 345 Russian NL-code snippet pairs. This dataset is intended for evaluation purposes due to its relatively small size. For training, the authors leverage the larger English CoNaLa dataset, which contains 2,879 manually annotated samples and additional data from English Stack Overflow and API documents.

Key Insights and Ideas

  • The English-centricity of code generation is a significant barrier: The stark performance drop observed for non-English languages clearly demonstrates that current models do not generalize well beyond English.
  • Cross-lingual NL-to-Code is challenging: Even with sophisticated multilingual models, achieving performance comparable to English is a distant goal.
  • Language similarity matters: The paper suggests that English's structural similarity to Python might contribute to its better performance, while other languages present greater challenges.
  • Code-specific models show promise but still struggle: Models designed with code-specific objectives (like TRANX and TAE) outperform general seq2seq models, but the cross-lingual gap persists.
  • MCoNaLa is a valuable tool for driving progress: Despite its size, the dataset is shown to be effective in revealing significant differences between models and highlighting areas for improvement.

Key Results

The experiments revealed a substantial performance gap between English and the target languages. The highest average BLEU score achieved across all non-English languages and experiment settings was 7.28, a stark contrast to the 33.41 score on English. Models with code-specific designs (TRANX and TAE) generally outperformed the multilingual MBART model, but the performance variation across languages was consistent. For instance, Spanish consistently showed lower scores compared to Japanese and Russian. Significance tests confirmed that MCoNaLa can effectively differentiate between model performances, even with its limited size.

Limitations and Future Work

The authors acknowledge that MCoNaLa is limited to languages available on Stack Overflow and primarily uses BLEU for evaluation. They suggest future work could involve expanding to other programming forums and incorporating more evaluation metrics like functional correctness and robustness. They also note that while machine translation (MT) is a useful tool for bridging language gaps, its quality can still be suboptimal, potentially impairing intent-snippet alignment and contributing to poor performance in translated settings. This suggests that improving MT quality or developing alternative cross-lingual transfer methods is crucial.

Summary updated

BibTeX
@inproceedings{wang2023mconala,
  author = {Zhiruo Wang and Grace Cuenca and Shuyan Zhou and Frank F. Xu and Graham Neubig},
  title = {{MCoNaLa: A Benchmark for Code Generation from Multiple Natural Languages}},
  booktitle = {EACL (Findings)},
  year = {2023},
  doi = {10.18653/v1/2023.findings-eacl.20},
}
Figure