arXiv:2409.08692cs.SEcs.AI2024-09中稿 · ASE' 24被引 18

用概率模型优化代码生成结果评估,提升可信度。

B4: Towards Optimal Assessment of Plausible Code Solutions with Plausible Tests

  • 基于贝叶斯框架构建最优选择策略,以通过率后验概率为依据
  • 在最坏情况下性能比最强启发式方法高50%,随机选择高246%
  • 适合大模型生成代码的自动评估场景,尤其测试用例不可靠时

从多个生成的代码中选出最佳解是代码生成的关键任务,通常依赖开发者编写的可靠测试用例。但真实场景中可靠测试用例稀缺且成本高,研究者尝试自动生成测试用例进行评估。当代码和测试均合理但不可靠时,选择最佳解变得困难。现有启发式策略缺乏理论保证,且未知是否存在最优策略。本文首次在贝叶斯框架下证明最优策略可由解与测试的观测通过状态后验概率定义,并将其建模为整数规划问题。进一步提出一种高效近似方法,其误差受先验知识正确性约束。通过引入有效先验知识,显著提升代码生成任务评估效果。理论与实证分析表明,现有启发式方法在使用大语言模型生成的测试时表现有限。所提方法B4在复杂场景下相比最强启发式提升50%,相比随机选择提升246%。代码已开源:https://github.com/ZJU-CTAG/B4。

原文摘要 · Abstract (English)

Selecting the best code solution from multiple generated ones is an essential task in code generation, which can be achieved by using some reliable validators (e.g., developer-written test cases) for assistance. Since reliable test cases are not always available and can be expensive to build in practice, researchers propose to automatically generate test cases to assess code solutions. However, when both code solutions and test cases are plausible and not reliable, selecting the best solution becomes challenging. Although some heuristic strategies have been proposed to tackle this problem, they lack a strong theoretical guarantee and it is still an open question whether an optimal selection strategy exists. Our work contributes in two ways. First, we show that within a Bayesian framework, the optimal selection strategy can be defined based on the posterior probability of the observed passing states between solutions and tests. The problem of identifying the best solution is then framed as an integer programming problem. Second, we propose an efficient approach for approximating this optimal (yet uncomputable) strategy, where the approximation error is bounded by the correctness of prior knowledge. We then incorporate effective prior knowledge to tailor code generation tasks. Both theoretical and empirical studies confirm that existing heuristics are limited in selecting the best solutions with plausible test cases. Our proposed approximated optimal strategy B4 significantly surpasses existing heuristics in selecting code solutions generated by large language models (LLMs) with LLM-generated tests, achieving a relative performance improvement by up to 50% over the strongest heuristic and 246% over the random selection in the most challenging scenarios. Our code is publicly available at https://github.com/ZJU-CTAG/B4.

代码生成评估方法贝叶斯

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。