Towards Functional Correctness of Large Code Models with Selective Generation
Abstract
The hallucination of code generation models hinders their applicability to systems requiring higher safety standards. One critical bottleneck in addressing code hallucination is the difficulty of identifying the functional correctness of generated code, due to its unnatural form. We address this core bottleneck by automatically generating unit tests using dynamic code analysis tools, leveraging the executable nature of code. Accordingly, we propose a selective code generator that abstains from uncertain generations -- based on the functional correctness evaluated by generated unit tests -- to theoretically control the correctness among non-abstained answers, i.e., the false discovery rate. Finally, we propose to use generated unit tests in evaluation as well as in learning for precise code evaluation, calling this paradigm FuzzEval. We demonstrate the efficacy of our method along with the controllability of code hallucination and reasonable selection efficiency.
Lay Summary
Code hallucinations hinders the practical use of large language models to software engineering, but difficult to address due to un-natural form of code. We tackle this challenge through selective generation, where the model abstains from answering if the model determines that the generated code is likely to be incorrect. To determine whether the generated code is correct during calibration stage, we automatically generate and execute unit tests using techniques such as fuzzing. Based on these tests, we propose a method that is theoretically guaranteed and validated under diverse experimental setups. Our findings enables the reliable deployment of LLM-generated code by reducing potentially incorrect code.