Exploring Multi-Lingual Bias of Large Code Models in Code Generation

Chaozheng Wang, Zongjie Li, Cuiyun Gao, Wenxuan Wang, Ting Peng, Hailiang Huang, Yuetang Deng, Shuai Wang, Michael R. LyuACM Transactions on Software Engineering and Methodology 2024 · DOI

Abstract

Large Code Models (LCMs) have significantly advanced automated software development. However, their performance is often uneven across different natural and programming languages. This paper investigates the "multi-lingual bias" in LCMs, where models perform substantially better with English instructions and high-resource programming languages like Python. We introduce X-HumanEval-X, a benchmark designed to quantify these biases, and MEIC, a large-scale multi-lingual instruction-tuning dataset. Our findings demonstrate that multi-lingual instruction tuning can reduce natural language bias by up to 84% and programming language bias by 40%, while simultaneously enhancing overall coding proficiency.

Introduction

The democratization of AI-assisted coding requires models that are equally effective regardless of the user's native language or the target programming language. Current LCMs are predominantly trained on English-centric text and Python-heavy code repositories. This leads to a dual-layered bias:

  1. Multi-Natural Language (NL) Bias: Discrepancies in performance when the same technical requirement is presented in different natural languages (e.g., English vs. Chinese).
  2. Multi-Programming Language (PL) Bias: Performance gaps between high-resource languages (Python) and lower-resource or syntactically complex languages (C++).

As illustrated in the figure above, even state-of-the-art models like DeepSeek-Coder 33B exhibit these failures. A simple logic test passed in an English-Python context can fail when the instruction is translated to Chinese or the solution is requested in C++.

Methodology

To address these biases, the researchers explored two main avenues: prompting strategies and instruction tuning.

Prompting Strategies

The study evaluated whether translating non-English prompts into English before processing could mitigate NL bias. They compared:

  • Self-Translation: The LCM translates its own prompt.
  • External Translation: Using specialized tools for One-Step or Multi-Step translation (breaking prompts into discrete logical statements).

Instruction Tuning

The authors hypothesized that training-level interventions are more robust. They developed several fine-tuning configurations using a variety of templates:

  • Monolingual Tuning: Training exclusively on English or Chinese instructions.
  • Mixed-NL Tuning: A balanced 50/50 blend of English and Chinese data.
  • Translation-Aware Tuning: A novel approach providing both English and Chinese versions of an instruction simultaneously, encouraging the model to learn cross-lingual semantic mappings.

Data Resources

The paper contributes two primary resources to the community:

  1. X-HumanEval-X: An evaluation benchmark derived from HumanEval-X, featuring instructions in English and Chinese paired with solutions in Python, Java, and C++.
  2. MEIC (Multi-EvolInstruct-Code): A comprehensive instruction-tuning dataset comprising 91,766 instances across two natural languages and over 20 programming languages, generated via the Evol-Instruct method with GPT-4.

Key Insights

The Self-Translation Trap

Counter-intuitively, asking an LCM to translate a Chinese prompt into English before solving it (Self-Translation) led to a performance decrease of over 60%. This suggests that current models are not yet reliable enough to serve as their own translators for complex technical specifications.

Cross-Lingual Synergy

Interestingly, instruction tuning on a single language (e.g., English) improved performance on others (e.g., Chinese). This indicates that LCMs develop a latent logical understanding that is somewhat independent of the specific natural language used.

Diversity as a Catalyst

The most significant reductions in bias came from data diversity rather than sheer volume. Mixing natural and programming languages during tuning provided the optimal balance between peak performance and fairness across languages.

The C++ Complexity Gap

PL bias proved more resilient than NL bias. Models consistently performed worse in C++ compared to Java or Python, likely due to C++'s syntactic complexity and manual memory management, which are less prevalent in the training corpora of high-resource languages.

Results and Discussion

The evaluation revealed that base models suffer an average 17.2% performance drop (Pass@1) when switching from English to Chinese instructions. The gap between Python and C++ was even wider, reaching 20.9%.

Multi-lingual instruction tuning emerged as the most effective solution, reducing NL bias by 84% and PL bias by 40%. Furthermore, this tuning improved absolute coding ability, with Pass@1 scores increasing by 31% to 46% across all tested scenarios. While external Multi-Step Translation reduced NL bias to 3.8%, it does not address the underlying PL bias or improve the model's intrinsic capabilities as effectively as tuning.

Conclusion and Future Work

While multi-lingual instruction tuning significantly mitigates bias, challenges remain. Future research should expand beyond English and Chinese to include the "long tail" of underrepresented natural languages. Additionally, addressing the persistent PL bias in complex languages like C++ may require specialized training techniques, such as weighted data sampling or language-agnostic code representations, to compensate for data imbalances in the wild.

Summary updated

BibTeX
@misc{wang2024exploring,
  author = {Chaozheng Wang and Zongjie Li and Cuiyun Gao and Wenxuan Wang and Ting Peng and Hailiang Huang and Yuetang Deng and Shuai Wang and Michael R. Lyu},
  title = {{Exploring Multi-Lingual Bias of Large Code Models in Code Generation}},
  year = {2024},
  eprint = {2404.19368},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2404.19368},
}
Figure