B4: 信頼性のあるテストを用いた妥当なコードソリューションの最適な評価に向けて
B4: Towards Optimal Assessment of Plausible Code Solutions with Plausible Tests
September 13, 2024
著者: Mouxiang Chen, Zhongxin Liu, He Tao, Yusu Hong, David Lo, Xin Xia, Jianling Sun
cs.AI
要旨
複数生成されたコードソリューションから最適なものを選択することは、コード生成における重要なタスクであり、信頼できる検証者(例:開発者が作成したテストケース)を使用して達成できます。信頼性の高いテストケースが常に利用可能であり、実践的に構築するのが高価であるため、研究者はコードソリューションを評価するために自動的にテストケースを生成することを提案しています。ただし、コードソリューションとテストケースの両方が妥当で信頼性がない場合、最適なソリューションを選択することは困難です。この問題に対処するためにいくつかのヒューリスティック戦略が提案されていますが、それらには強力な理論的保証が欠けており、最適な選択戦略が存在するかどうかは未解決の問題です。私たちの研究は2つの点で貢献しています。まず、ベイズ的枠組みの中で、最適な選択戦略は、ソリューションとテストの間の観測された合格状態の事後確率に基づいて定義できることを示します。最適なソリューションを特定する問題は、整数プログラミング問題として構築されます。第二に、この最適(しかし計算不可能な)戦略を近似する効率的なアプローチを提案し、その近似誤差が事前知識の正確性によって制限されることを示します。その後、効果的な事前知識を組み込んでコード生成タスクを調整します。理論的および実証的研究の両方が、既存のヒューリスティックが妥当なテストケースで最適なソリューションを選択する際に限界があることを確認しています。私たちが提案する近似最適戦略B4は、LLM(Large Language Models)によって生成されたコードソリューションをLLMが生成したテストで選択する際に、最も強力なヒューリスティックに対して最大50%の相対パフォーマンス向上と、最も困難なシナリオで最強のヒューリスティックに対して246%の相対パフォーマンス向上を達成します。私たちのコードはhttps://github.com/ZJU-CTAG/B4で公開されています。
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.Summary
AI-Generated Summary