Skip to main content
QUICK REVIEW

[论文解读] Comparing large language models and human programmers for generating programming code

Wenpin Hou, Zhicheng Ji|arXiv (Cornell University)|Mar 1, 2024
Software Engineering ResearchComputer Science被引用 4
一句话总结

本研究系统评估了七种大型语言模型(LLMs)在多种提示策略、编程语言和任务难度下生成编程代码的表现。GPT-4 在使用优化提示策略时,在 LeetCode 和 GeeksforGeeks 编程竞赛中表现优于 85% 的人类参赛者,展现出强大的跨语言代码转换能力、从错误中学习的能力以及生成计算高效代码的能力,表明其在软件开发中具有极强的辅助潜力。

ABSTRACT

We systematically evaluated the performance of seven large language models in generating programming code using various prompt strategies, programming languages, and task difficulties. GPT-4 substantially outperforms other large language models, including Gemini Ultra and Claude 2. The coding performance of GPT-4 varies considerably with different prompt strategies. In most LeetCode and GeeksforGeeks coding contests evaluated in this study, GPT-4 employing the optimal prompt strategy outperforms 85 percent of human participants. Additionally, GPT-4 demonstrates strong capabilities in translating code between different programming languages and in learning from past errors. The computational efficiency of the code generated by GPT-4 is comparable to that of human programmers. These results suggest that GPT-4 has the potential to serve as a reliable assistant in programming code generation and software development.

研究动机与目标

  • 系统评估七种 LLM 在多种编程语言和任务难度下生成编程代码的表现。
  • 探究不同提示策略对 LLM 编程性能的影响,尤其是与标准提示的对比。
  • 在真实世界编程竞赛中,直接比较 LLM 生成代码的表现与人类程序员的表现。
  • 评估 LLM 在不同编程语言间翻译代码的能力,以及其生成代码的计算效率相对于人类编写代码的表现。
  • 检验 LLM 是否能从过往错误中学习,并在多次尝试中持续改进。

提出的方法

  • 本研究使用 25 个随机选取的 LeetCode 竞赛中选取的 100 个编程任务,以及来自 GeeksforGeeks 的较小数据集进行 LLM 评估,所有任务均发布于 2021 年 9 月之后,以匹配 GPT-4 的知识截止时间。
  • 设计并测试了五种不同的提示策略:标准提示、带思维链的反馈(feedback CI)、带思维链与自一致性验证的反馈,以及两种少样本提示的变体。
  • 通过单次尝试成功率、五次尝试成功率、挽救率(后续尝试中成功)以及计算效率(执行时间与内存使用量百分位数)来衡量 LLM 的表现。
  • 在代码翻译方面,GPT-4 使用 feedback CI 提示生成 Python3 代码,随后将其翻译为 Java、JavaScript 和 C++,按任务难度评估翻译成功率。
  • 通过将 GPT-4 生成的代码(优化前与优化后)与人类编写的代码在相同任务上的表现进行比较,使用运行时间与内存使用量的百分位数排名来评估计算效率。
  • 人类表现通过 LeetCode 和 GeeksforGeeks 的官方竞赛排名进行基准测试,LLM 的排名通过与人类参赛者进行百分位数比较确定。
Figure 1: A schematic illustrating the prompt strategies that were developed and assessed in this study.
Figure 1: A schematic illustrating the prompt strategies that were developed and assessed in this study.

实验结果

研究问题

  • RQ1提示策略的选择如何影响大型语言模型在不同任务难度下的编程表现?
  • RQ2当使用最优提示时,GPT-4 在 LeetCode 和 GeeksforGeeks 的真实编程竞赛中,相较于人类程序员的超越程度如何?
  • RQ3大型语言模型能否有效实现不同编程语言之间的代码翻译?翻译成功率如何随任务难度变化?
  • RQ4LLM 生成代码的计算效率与人类编写的代码相比如何,尤其是在自我优化前后?
  • RQ5LLM 是否能从先前的错误中学习并改进?这一能力是否可通过多次尝试的挽救率得到体现?

主要发现

  • 当使用最优提示策略(即带思维链与自一致性验证的反馈)时,GPT-4 在 LeetCode 的简单任务中单次尝试成功率高达 86.2%,中等难度任务为 60.0%,困难任务为 14.3%,在多数竞赛中超越了 85% 的人类参赛者。
  • GPT-4 的挽救率随尝试次数显著提升,到第五次尝试时,中等和困难任务的挽救率均超过 90%,表明其具备强大的错误恢复与学习能力。
  • GPT-4 展现出高水平的代码翻译成功率:在中等难度任务中,80% 的正确生成的 Python3 代码可成功翻译为其他语言(Java、JavaScript、C++),即使原始代码存在错误,其翻译表现依然强劲。
  • GPT-4 生成代码的计算效率与人类代码相当——经自优化后,其代码在所有任务难度下,运行时间与内存使用量的百分位数排名均达到或超过第 90 百分位。
  • 在所有指标上,GPT-4 均优于其他 LLM,包括 Gemini Ultra 和 Claude 2,尤其在复杂且难度较高的任务中,性能差距最为显著。
  • 本研究证实,提示工程显著提升了 LLM 的编程表现,其中 feedback CI 策略在所有模型中均实现了最高的成功率与挽救率。
Figure 2: Five-attempt and one-attempt success rates for tasks with varying difficulty levels. Each row represents a different prompt strategy and a different LLM. The text within each bar displays the success rate, the number of programming tasks solved, and the total number of tasks. Rows are orde
Figure 2: Five-attempt and one-attempt success rates for tasks with varying difficulty levels. Each row represents a different prompt strategy and a different LLM. The text within each bar displays the success rate, the number of programming tasks solved, and the total number of tasks. Rows are orde

阅读本论文

在 Nubint 阅读器中打开原文,边读边就任意段落提问。

在 Nubint 中阅读本论文

本解读由 AI 根据论文原文生成,引用前请核对原文。