Large Language Models for Code Generation from Multilingual Prompts: A Curated Benchmark and a Study on Code Quality

📄 arXiv: 2607.14816v1 📥 PDF

作者: Saima Afrin, Alessandro Midolo, Camilo Escobar-Velásquez, Mario Linares-Vásquez, Weiyuan Ding, Bowen Xu, Massimiliano Di Penta, Antonio Mastropaolo

分类: cs.SE, cs.AI

发布日期: 2026-07-16


💡 一句话要点

提出多语言提示下代码生成的基准研究以解决语言偏见问题

🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)

关键词: 大型语言模型 代码生成 语言偏见 多语言提示 编程质量

📋 核心要点

  1. 现有研究对代码生成中的语言偏见关注不足,尤其是在多语言提示下的代码质量和编程规范影响。
  2. 本文通过建立多语言提示的基准,系统性评估不同语言对代码生成质量的影响,旨在揭示语言偏见现象。
  3. 实验结果显示,提示语言对生成代码的功能正确性和质量有显著影响,且生成代码常常混合使用多种语言。

📝 摘要(中文)

大型语言模型(LLMs)在不同自然语言提示下执行相同编程任务时表现不同,这种现象称为语言偏见。尽管这一行为在一般文本生成中已被广泛研究,但其对代码生成质量和编程规范的影响仍然未被充分探讨。本文研究了描述编程任务所用语言如何影响GPT-4o mini、DeepSeek和Claude生成的源代码。我们对460个编码任务进行了评估,涵盖Python(230个)和Java(230个),并将原始英语提示翻译并手动整理为中文、印地语、西班牙语和意大利语,同时保持其技术含义。通过多维度评估生成的代码,包括功能正确性、结构质量、静态分析工具检测的问题以及标识符和注释中使用的语言特征,结果表明:英语提示并不总是产生最佳的功能正确性或代码质量,提示语言的影响依赖于编程语言和LLM,生成的代码常常在注释和字符串文字中混合使用英语和提示语言。这些发现为研究代码生成中的语言偏见提供了首个整理的多语言基准,并为开发更强大的多语言代码生成系统提供了见解。

🔬 方法详解

问题定义:本文旨在解决在多语言提示下,代码生成质量受到语言偏见影响的问题。现有方法未能充分探讨不同语言提示对代码生成的影响,导致生成代码的质量和规范性存在不确定性。

核心思路:通过对460个编码任务进行多语言提示的翻译和整理,评估不同提示语言对生成代码的影响,揭示语言偏见的存在及其对代码质量的影响。

技术框架:研究包含多个阶段:首先翻译和整理提示语言,其次使用不同的LLM生成代码,最后通过功能正确性、结构质量和静态分析等多维度评估生成的代码。

关键创新:本研究首次建立了多语言提示下的代码生成基准,系统性分析了语言偏见对代码质量的影响,提供了新的视角和数据支持。

关键设计:在实验中,使用了功能正确性测试、结构质量指标和静态分析工具,确保评估的全面性和准确性。

🖼️ 关键图片

img_0
img_1
img_2

📊 实验亮点

实验结果表明,英语提示并不总是产生最佳的功能正确性或代码质量,且生成的代码常常在注释和字符串中混合使用多种语言。这一发现为多语言代码生成系统的设计提供了重要的实证依据。

🎯 应用场景

该研究的潜在应用领域包括多语言编程环境、教育工具和代码生成平台。通过理解语言偏见对代码生成的影响,可以为开发更智能的多语言编程助手提供理论支持,从而提升编程效率和代码质量。

📄 摘要(原文)

Large Language Models (LLMs) perform differently on identical programming tasks when prompted in different natural languages, a phenomenon known as language bias. While this behavior has been widely studied for general text generation, its impact on code generation quality and programming conventions remains largely unexplored. We investigate how the language used to describe programming tasks affects the source code generated by GPT-4o mini, DeepSeek, and Claude. Our study comprises 460 coding tasks spanning Python (230) and Java (230). We translate and manually curate the original English prompts into Chinese, Hindi, Spanish, and Italian while preserving their technical meaning. We evaluate the generated code using multiple dimensions, including functional correctness through test pass rates, structural quality using established code metrics, issues detected by static analysis tools, and lexical characteristics such as the language used in identifiers and comments. Our results show that (i) English prompts do not consistently produce the best functional correctness or code quality, (ii) the impact of prompt language depends on both the programming language and the LLM, and (iii) generated code frequently mixes English with the prompt language in comments and string literals. These findings provide the first curated multilingual benchmark for studying language bias in code generation and offer insights for developing more robust multilingual code generation systems.