Table of Contents
Fetching ...

Ensuring Functional Correctness of Large Code Models with Selective Generation

Jaewoo Jeong, Taesoo Kim, Sangdon Park

TL;DR

The paper tackles functional hallucination in large code models by introducing selective code generation guided by alpha-entailment and automatically generated unit tests via fuzzing. It formalizes a false discovery rate for code entailment (FDR-CE), develops a learning algorithm (SCG) to produce abstention-enabled generators with theoretical guarantees, and redefines evaluation through FuzzEval. By leveraging dynamic code analysis to generate unit tests, it enables self-supervised learning and scalable, rigorous evaluation across multiple datasets, languages, and models. The approach demonstrates controllable hallucination with meaningful selection efficiency and shows the added value of fuzzing for both learning and evaluation, while acknowledging limitations like distribution shifts and dependence on scoring calibration.

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 \emph{executable nature} of code. Accordingly, we propose \emph{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, \ie 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 \emph{FuzzEval}. We demonstrate the efficacy of our method along with the controllability of code hallucination and reasonable selection efficiency.

Ensuring Functional Correctness of Large Code Models with Selective Generation

TL;DR

The paper tackles functional hallucination in large code models by introducing selective code generation guided by alpha-entailment and automatically generated unit tests via fuzzing. It formalizes a false discovery rate for code entailment (FDR-CE), develops a learning algorithm (SCG) to produce abstention-enabled generators with theoretical guarantees, and redefines evaluation through FuzzEval. By leveraging dynamic code analysis to generate unit tests, it enables self-supervised learning and scalable, rigorous evaluation across multiple datasets, languages, and models. The approach demonstrates controllable hallucination with meaningful selection efficiency and shows the added value of fuzzing for both learning and evaluation, while acknowledging limitations like distribution shifts and dependence on scoring calibration.

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 \emph{executable nature} of code. Accordingly, we propose \emph{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, \ie 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 \emph{FuzzEval}. We demonstrate the efficacy of our method along with the controllability of code hallucination and reasonable selection efficiency.
Paper Structure (39 sections, 3 theorems, 10 equations, 5 figures, 9 tables, 2 algorithms)

This paper contains 39 sections, 3 theorems, 10 equations, 5 figures, 9 tables, 2 algorithms.

Key Result

Lemma 1

For any $\alpha, \varepsilon_E \in (0, 1)$, and $\hat{{S}}$, we have $\mathcal{{R}}_\alpha(\hat{{S}}) \le \varepsilon_E + \mathcal{{R}}_{\alpha, \varepsilon_E}(\hat{{S}}).$

Figures (5)

  • Figure 1: Overview of our proposed selective code generation. We leverage an abstaining option to selectively generate code to control the rate of hallucination in an FDR. Our selective generator learns a selection function by leveraging dynamic code analysis tools to automatically generate unit tests and use them as a calibration set for the selection function and also as a test set for evaluation.
  • Figure 2: The box plots of the FDR-CE and selection efficiency for various LLMs ($\delta_S = 0.1$, $\varepsilon_S = 0.3$, $\varepsilon_E = 0.05$, $\alpha=0.35$). See Appendix \ref{['fig:1:codellama']} for results with CodeLlama 13B Instruct.
  • Figure 3: The FDR-CE results for GPT-4o with varying parameters and scoring functions. We use $\varepsilon_S=0.3, \delta_S=0.1, \alpha=0.35$, and $\varepsilon_E=0.05$ for Figure \ref{['fig:varying epsilon_S']} and \ref{['fig:varying alpha']} and $\varepsilon_S=0.2, \delta_S=0.1, \alpha=0.15$, and $\varepsilon_E=0.05$ for Figure \ref{['fig:varying_scoring_functions']}
  • Figure 4: The box plots of the FDR-CE and selection efficiency for CodeLlama 13B Instruct. We set $\delta_S = 0.1$, $\varepsilon_S = 0.3$, $\varepsilon_E = 0.05$, and $\alpha=0.35$. SCG fails to find a selective generator with a desired FDR-CE due to uncalibrated scoring function.
  • Figure 5: The FDR-CE results for GPT-4o with varying parameters ($\varepsilon_S=0.3, \delta_S=0.1, \alpha=0.35$, and $\varepsilon_E=0.05$). Each figure shows FDR-CE bound is satisfied for each settings. This is shown by upper whisker bar lying below the desired FDR-CE in the dotted line. Figure \ref{['fig:varying epsilon_E']} shows benefit of fuzzing in learning and Figure \ref{['fig:varying_eval_unit_tests']} show benefit of fuzzing in evaluation.

Theorems & Definitions (4)

  • Definition 1: $\alpha$-code entailment
  • Lemma 1
  • Theorem 1
  • Lemma 2