arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2403.17214cs.SEcs.AI
收藏

代码翻译大语言模型评估中的输出格式偏差

Output Format Biases in the Evaluation of Large Language Models for Code Translation

School of Computing, Queen's University, ON, Canada(计算学院,皇后大学,加拿大);Centre for Software Excellence, Huawei Canada(软件卓越中心,华为加拿大)

Marcos Macedo, Yuan Tian, Filipe R. Cogo, Bram Adams

AI总结:

针对代码翻译LLM评估中非代码元素干扰评估指标的问题,对11个开源和5个闭源LLM进行实证分析,提出结合提示工程与正则表达式的代码提取策略,有效缓解输出格式偏差并实现可靠评估。

摘要:

编程语言(PLs)之间的代码翻译是软件工程中的一项关键任务,有助于遗留系统的现代化、确保跨平台兼容性以及提升软件性能。大多数现有研究指导 LLMs 执行代码翻译,并通过将生成的输出运行于测试套件或将其与参考输出(ground truth)进行比较来评估其性能。然而,这些输出可能不仅包含可执行的源代码,还包含额外的非代码元素,例如自然语言解释或格式化标记。我们将源代码与非代码元素的组合称为输出格式。理解和处理输出格式的变化至关重要,因为非代码元素会干扰评估指标,导致对模型性能和比较的评估产生偏差。我们对 11 个指令微调的开源 LLMs 的输出进行了实证分析,涵盖 5 种 PLs:C、C++、Go、Java 和 Python。结果显示,我们评估的 LLMs 产生的输出中有 26.4% 至 73.7% 需要后处理。为了减轻输出格式偏差,我们提出了一种结合提示工程和正则表达式的策略,能够有效地从混合格式的输出中提取源代码,使这 11 个开源模型平均达到 92.73% 的代码提取成功率(CSR)。我们的实证研究证实,输出格式偏差会影响广泛使用的基于执行的指标,即计算准确率(CA),以及基于文本的指标,即 BLEU、CodeBLEU 和 CrystalBLEU。此外,我们测试了 5 个闭源 LLMs,并观察到它们也生成不同分布的输出格式,这可能导致输出格式偏差。我们的结果强调了减轻输出格式偏差的必要性,以实现 LLMs 代码翻译的可靠评估。

英文摘要:

Code translation between programming languages (PLs) is a critical task in software engineering, facilitating the modernization of legacy systems, ensuring cross-platform compatibility, and enhancing software performance. Most existing studies instruct LLMs to perform code translation and evaluate their performance by either running the generated outputs through test suites or comparing them to reference outputs (ground truth). These outputs, however, may contain not only executable source code but also additional non-code elements, such as natural language explanations or formatting tokens. We refer to the combination of source code and non-code elements as the output format. It is crucial to understand and address variations in output format, as non-code elements can interfere with evaluation metrics, resulting in biased assessments of model performance and comparisons. We conduct an empirical analysis of the outputs from eleven instruct-tuned open-source LLMs, across five PLs: C, C++, Go, Java, and Python. The results show that between 26.4% and 73.7% of outputs produced by our evaluated LLMs necessitate post-processing. To mitigate output format bias, we propose a strategic combination of prompt engineering and regular expressions that effectively extracts source code from mixed-format outputs, enabling the eleven open-source models to achieve an average Code Extraction Success Rate (CSR) of 92.73%. Our empirical study confirms that output format bias affects widely used execution-based metrics, i.e., Computational Accuracy (CA), and text-based metrics, i.e., BLEU, CodeBLEU and CrystalBLEU. Additionally, we test five closed-source LLMs and observe that they also generate varying distributions of output formats, which could lead to output format biases. Our results highlight the need to mitigate the output format bias to enable reliable evaluations in LLMs for code translation.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑