arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2409.16416cs.SEcs.AI
收藏

通过预测代码复杂度来选择代码生成的提示工程技巧

Selection of Prompt Engineering Techniques for Code Generation through Predicting Code Complexity

York University(约克大学)

Chung-Yu Wang, Alireza DaghighFarsoodeh, Hung Viet Pham

AI总结:

提出PET-Select模型,通过预测代码复杂度并利用对比学习为查询选择最合适的提示工程技巧,在MBPP和HumanEval上提升了pass@1准确率并大幅减少token使用。

摘要:

大型语言模型(LLMs)在软件工程任务中展现了出色的性能。然而,提高其生成正确且可靠代码的准确性仍具挑战。为解决此问题,人们开发了众多提示工程技巧(PETs),但没有任何单一方法是普遍最优的。为每个查询选择合适的PET十分困难,主要原因有两点:(1) 交互式提示技巧可能无法持续带来预期收益,特别是对于较简单的查询;(2) 当前的自动化提示工程方法缺乏适应性,且未能充分利用多阶段响应。为克服这些挑战,我们提出了PET-Select,这是一种与PET无关的选择模型,它使用代码复杂度作为代理来对查询进行分类,并选择最合适的PET。通过结合对比学习,PET-Select能有效区分简单与复杂问题,从而能够为每个查询的复杂度水平选择最适合的PET。我们在MBPP和HumanEval基准上使用GPT-3.5 Turbo和GPT-4o进行的评估显示,pass@1准确率提升了1.9%,同时token使用量减少了74.8%。此外,我们提供了定量和定性结果,以证明PET-Select如何有效地为每个代码生成查询选择最合适的技巧,进一步展示了其在优化PET选择方面的效率。

英文摘要:

Large Language Models (LLMs) have demonstrated impressive performance in software engineering tasks. However, improving their accuracy in generating correct and reliable code remains challenging. Numerous prompt engineering techniques (PETs) have been developed to address this, but no single approach is universally optimal. Selecting the right PET for each query is difficult for two primary reasons: (1) interactive prompting techniques may not consistently deliver the expected benefits, especially for simpler queries, and (2) current automated prompt engineering methods lack adaptability and fail to fully utilize multi-stage responses. To overcome these challenges, we propose PET-Select, a PET-agnostic selection model that uses code complexity as a proxy to classify queries and select the most appropriate PET. By incorporating contrastive learning, PET-Select effectively distinguishes between simple and complex problems, allowing it to choose PETs that are best suited for each query's complexity level. Our evaluations on the MBPP and HumanEval benchmarks using GPT-3.5 Turbo and GPT-4o show up to a 1.9% improvement in pass@1 accuracy, along with a 74.8% reduction in token usage. Additionally, we provide both quantitative and qualitative results to demonstrate how PET-Select effectively selects the most appropriate techniques for each code generation query, further showcasing its efficiency in optimizing PET selection.

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

↑