Abstract
Large Language Models (LLMs) have demonstrated remarkable capabilities in generating code from natural language descriptions. However, in the domain of data manipulation, these models often produce syntactically plausible but semantically incorrect programs. This paper presents a framework that leverages the execution of candidate programs on actual data to perform semantic reranking. By filtering and prioritizing programs based on their outputs, the proposed method achieves significant improvements in top-1 accuracy across SQL, Pandas, and Power Query M, with gains of up to 45% in low-resource programming languages.
Introduction
The challenge of program synthesis from natural language (NL) lies in bridging the gap between ambiguous human intent and precise executable code. While state-of-the-art LLMs like GPT-4 excel at generating code, they are prone to "hallucinations"—generating code that fails to execute or produces incorrect results. Traditional approaches incorporate data context (e.g., table schemas) during the prompting phase but neglect the rich information available in the execution output of generated candidates. This work addresses this gap by introducing a post-processing pipeline that uses execution results to verify and rank candidate programs.
The Semantic Reranking Pipeline
The core of the proposed approach is a multi-stage pipeline designed to move beyond simple probability-based ranking of code tokens.
The pipeline consists of four primary components:
- Temperature Mixing: To balance stability and diversity, the system combines samples generated at temperature 0 (high probability) with those at temperature 0.6 (high diversity).
- Semantic Filtering: Every candidate program is executed against the target dataset. Programs that result in runtime errors are immediately pruned from the candidate set.
- Semantic Interleaving: Recognizing that different code structures can produce identical outputs, the system groups candidates by their execution results. It then interleaves these groups to ensure the top-K results presented to the user are semantically diverse.
- Output-Prediction based Score Tuning: For languages where the LLM has lower confidence (like Power Query M), the model is tasked with predicting the expected output data for a given NL query. Candidate programs whose execution results match this predicted output receive a score boost.
Experimental Setup
The framework was evaluated across three distinct domains:
- SQL: Benchmarked using the standard Spider and KaggleDBQA datasets.
- Data Science (Pandas): Evaluated on the Jigsaw dataset.
- Business Intelligence (Power Query M): Tested on three new benchmarks: Forum (scraped from help sites), Product (real-world Microsoft benchmarks), and JigsawM (a Pandas-to-M adaptation).
Results and Discussion
The implementation of semantic reranking led to substantial performance improvements. In the Power Query M domain, specifically on the JigsawM benchmark, top-1 accuracy increased by an absolute 45%. For SQL tasks on the Spider benchmark, the system achieved 76% top-1 accuracy, setting a new state-of-the-art.
A key insight from this work is that execution serves as the ultimate arbiter of truth in data tasks. By prioritizing diversity over raw token probability, semantic interleaving ensures that the top results represent distinct logical interpretations of the user's query. Furthermore, the "alternative task" strategy—predicting data transformations rather than just code—provides a powerful cross-verification mechanism for low-resource languages.
Conclusion and Future Work
While highly effective, the reliance on code execution introduces challenges regarding safety and latency. Executing arbitrary code in general-purpose languages like Python requires robust sandboxing to prevent side effects. Additionally, the computational overhead of executing multiple candidates and predicting outputs must be optimized for real-time applications. Future research will explore non-execution-based clustering and the extension of these techniques to non-data-centric programming domains.
Summary updated