Skip to main content
QUICK REVIEW

[论文解读] Can ChatGPT replace StackOverflow? A Study on Robustness and Reliability of Large Language Model Code Generation

Zhong Li, Zilong Wang|arXiv (Cornell University)|Aug 20, 2023
Software Engineering Research被引用 6
一句话总结

本文提出了 RobustAPI,一个用于评估大型语言模型(LLMs)生成代码的可靠性与鲁棒性的基准,重点关注 Java 中的 API 误用问题。尽管功能正确,GPT-4 的 API 误用率仍高达 62%,凸显了在无验证的情况下使用 LLM 生成代码时在实际软件中存在重大风险。

ABSTRACT

Recently, the large language models (LLMs) have shown extraordinary ability in understanding natural language and generating programming code. It has been a common practice of software engineers to consult LLMs when encountering coding questions. Although efforts have been made to avoid syntax errors and align the code with the intended semantics, the reliability and robustness of the code generationfrom LLMs have not yet been thoroughly studied. The executable code is not equivalent to the reliable and robust code, especially in the context of real-world software development. The misuse of APIs in the generated code could lead to severe problem, such as resource leaks, program crashes. To make things worse, the users of LLM code generation services are actually the developers that are most vulnerable to these code that seems right -- They are always novice developers that are not familiar with the APIs that LLMs generate code for them. Therefore, they could hardly tell the misuse in the code generated by LLMs, which further facilitates the incorrect code applied in real-world software. Existing code evaluation benchmark and datasets focus on crafting small tasks such as programming questions in coding interviews, which however deviates from the problem that developers would ask LLM for real-world coding help. To fill the missing piece, in this work, we propose a dataset RobustAPI for evaluating the reliability and robustness of code generated by LLMs. We collect 1208 coding questions from StackOverflow on 24 representative Java APIs. We summarize thecommon misuse patterns of these APIs and evaluate them oncurrent popular LLMs. The evaluation results show that evenfor GPT-4, 62% of the generated code contains API misuses,which would cause unexpected consequences if the code isintroduced into real-world software.

研究动机与目标

  • 为解决现有评估框架缺乏对 LLM 生成代码的可靠性与鲁棒性评估(超越功能性正确性)的问题。
  • 识别并量化真实世界软件开发场景中常见的 API 误用模式。
  • 开发一个反映来自 Stack Overflow 的实际开发者查询的基准,聚焦于广泛使用的 Java API。
  • 评估提示工程策略(如上下文学习和 API 规则注入)在减少误用方面的有效性。
  • 开源数据集与评估框架,以支持未来在可靠代码生成方面的研究。

提出的方法

  • 作者从 Stack Overflow 收集了 1,208 个与 18 个代表性 Java API 相关的真实编程问题。
  • 通过抽象语法树(AST)将正确的 API 使用模式形式化为结构化的调用序列,以定义正确的使用序列。
  • 开发了自定义评估器,通过将生成代码的 AST 结构与预期使用模式进行对比,分析其正确性。
  • 在四种 LLM 上评估了该基准:GPT-3.5、GPT-4、Llama-2 和 Vicuna-1.5,采用零样本和少样本提示设置。
  • 研究同时使用功能性正确性与 API 误用检测作为评估指标,误用定义为对结构化调用序列的违反。
  • 测试了温度设置与提示工程(如添加 API 规则)的影响,以评估其对减少误用的作用。

实验结果

研究问题

  • RQ1即使代码在语法上正确且与用户意图在功能上一致,LLM 生成代码中的 API 误用有多普遍?
  • RQ2使用相关示例进行上下文学习是否能显著降低 LLM 生成代码中的 API 误用率?
  • RQ3与少样本提示相比,在提示中注入显式的 API 使用规则是否能提高生成代码的可靠性?
  • RQ4哪些 Java API 最容易被 LLM 误用,其主要的误用模式是什么?
  • RQ5温度设置与模型架构在多大程度上影响 API 误用的可能性?

主要发现

  • 尽管 GPT-4 是测试中最为先进的模型,其生成代码中的 API 误用率仍高达 62%,表明存在广泛存在的可靠性问题。
  • 即使使用少样本相关示例,GPT-3.5 的误用率仍保持在 38.56%,表明少样本提示的改进效果有限。
  • 在提示中注入 API 使用规则并未显著降低误用率,GPT-3.5 在此设置下的误用率高达 65.01%。
  • GPT-4 的编译失败率最低(<10%),而 GPT-3.5 的失败率更高,尤其在高温设置下更为明显。
  • Android API Activity.setContentView 在所有模型中误用率最低,表明某些 API 对 LLM 来说更具可预测性。
  • 最常见的误用模式包括缺少异常处理、资源关闭不当以及方法调用顺序错误。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。