Large Language Models (LLMs) have achieved state-of-the-art performance across software engineering tasks, from code generation to translation. However, we identify and systematically evaluate a critical failure mode: Programming Language Confusion (PLC) -- the generation of code in unintended languages despite explicit instructions. Through evaluation of 10 popular LLMs across six multilingual datasets (LiveCodeBench, BabelCode variants, HumanEval-XL, and McEval), we demonstrate that PLC is pervasive, with some specialized models exhibiting the highest confusion rates. Our analysis reveals that PLC is not random noise but reflects systematic patterns: models consistently generate syntactically valid code even when it deviates from language specifications. This behavior produces distinct language migration patterns, most notably a strong default to Python and systematic shifts between syntactically similar language pairs (e.g., C#/Java). These migrations reflect statistical preferences learned from training data rather than goal-directed reasoning. We demonstrate that explicit language keywords provide the most effective mitigation, while natural language instructions have limited influence on model behavior. Furthermore, model quantization -- though essential for practical deployment -- significantly amplifies PLC and degrades syntactic stability in complex tasks. Our findings underscore that language fidelity should be treated as a core evaluation dimension for code LLMs. We advocate for standardized benchmarks and prompt formats with explicit language constraints to enable more reliable assessment and foster the development of robust, multilingual code generation systems.


翻译:大语言模型(LLMs)在从代码生成到翻译的各类软件工程任务中均取得了最先进的性能。然而,我们发现并系统性地评估了一种关键失效模式:编程语言混淆——即模型在接收到明确指令的情况下,仍生成了非目标语言的代码。通过对10个流行LLM在六个多语言数据集(LiveCodeBench、BabelCode变体、HumanEval-XL和McEval)上的评估,我们证明PLC现象普遍存在,一些专用模型甚至表现出最高的混淆率。我们的分析表明,PLC并非随机噪声,而是反映了系统性的模式:即使生成的代码偏离了语言规范,模型也始终生成语法有效的代码。这种行为产生了独特的语言迁移模式,最显著的是对Python的强烈默认倾向,以及在语法相似的语言对(例如C#/Java)之间发生的系统性偏移。这些迁移反映了模型从训练数据中学到的统计偏好,而非基于目标的推理。我们证明,显式的语言关键字提供了最有效的缓解措施,而自然语言指令对模型行为的影响有限。此外,模型量化——尽管对实际部署至关重要——显著加剧了PLC,并在复杂任务中降低了语法稳定性。我们的研究结果强调,语言保真度应被视为评估代码LLM的一个核心维度。我们主张建立具有明确语言约束的标准化基准测试和提示格式,以实现更可靠的评估,并促进开发鲁棒的多语言代码生成系统。

0
下载
关闭预览

相关内容

代码(Code)是专知网的一个重要知识资料文档板块,旨在整理收录论文源代码、复现代码,经典工程代码等,便于用户查阅下载使用。
大型语言模型的规模效应局限
专知会员服务
14+阅读 · 2025年11月18日
【ETZH博士论文】语言模型编程
专知会员服务
25+阅读 · 2025年6月14日
大型语言模型(LLMs),附Slides与视频
专知会员服务
70+阅读 · 2024年6月30日
《大型语言模型代码生成》综述
专知会员服务
68+阅读 · 2024年6月4日
大型语言模型对齐
专知会员服务
119+阅读 · 2023年9月27日
大语言模型简明指南
专知会员服务
143+阅读 · 2023年7月29日
NLP 与 NLU:从语言理解到语言处理
AI研习社
15+阅读 · 2019年5月29日
自然语言处理中的语言模型预训练方法
PaperWeekly
14+阅读 · 2018年10月21日
NLP通用模型诞生?一个模型搞定十大自然语言常见任务
人工智能头条
10+阅读 · 2018年6月29日
放弃 RNN/LSTM 吧,因为真的不好用!望周知~
人工智能头条
19+阅读 · 2018年4月24日
自然语言处理(二)机器翻译 篇 (NLP: machine translation)
DeepLearning中文论坛
12+阅读 · 2015年7月1日
国家自然科学基金
18+阅读 · 2017年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
4+阅读 · 2014年12月31日
国家自然科学基金
11+阅读 · 2012年12月31日
VIP会员
相关VIP内容
大型语言模型的规模效应局限
专知会员服务
14+阅读 · 2025年11月18日
【ETZH博士论文】语言模型编程
专知会员服务
25+阅读 · 2025年6月14日
大型语言模型(LLMs),附Slides与视频
专知会员服务
70+阅读 · 2024年6月30日
《大型语言模型代码生成》综述
专知会员服务
68+阅读 · 2024年6月4日
大型语言模型对齐
专知会员服务
119+阅读 · 2023年9月27日
大语言模型简明指南
专知会员服务
143+阅读 · 2023年7月29日
相关基金
国家自然科学基金
18+阅读 · 2017年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
4+阅读 · 2014年12月31日
国家自然科学基金
11+阅读 · 2012年12月31日
Top
微信扫码咨询专知VIP会员