Skip to main content
QUICK REVIEW

[论文解读] From Words to Code: Harnessing Data for Program Synthesis from Natural Language

Anirudh Khatry, Joyce Cahoon|arXiv (Cornell University)|May 2, 2023
Software Engineering Research被引用 6
一句话总结

该论文提出了一种新颖的程序合成框架,通过执行反馈的语义重排序和温度混合,利用数据上下文提升从自然语言生成代码的性能。通过在输入数据上执行候选程序,并利用输出信号(语义过滤、交错排序和分数调优)进行重排序,该方法在仅使用 GPT-4 和 Codex 的上下文学习情况下,在 SQL、Pandas 和 Power Query M 基准测试中实现了最高 45% 的 top-1 准确率提升和 34% 的 top-3 准确率改进。

ABSTRACT

Creating programs to correctly manipulate data is a difficult task, as the underlying programming languages and APIs can be challenging to learn for many users who are not skilled programmers. Large language models (LLMs) demonstrate remarkable potential for generating code from natural language, but in the data manipulation domain, apart from the natural language (NL) description of the intended task, we also have the dataset on which the task is to be performed, or the "data context". Existing approaches have utilized data context in a limited way by simply adding relevant information from the input data into the prompts sent to the LLM. In this work, we utilize the available input data to execute the candidate programs generated by the LLMs and gather their outputs. We introduce semantic reranking, a technique to rerank the programs generated by LLMs based on three signals coming the program outputs: (a) semantic filtering and well-formedness based score tuning: do programs even generate well-formed outputs, (b) semantic interleaving: how do the outputs from different candidates compare to each other, and (c) output-based score tuning: how do the outputs compare to outputs predicted for the same task. We provide theoretical justification for semantic interleaving. We also introduce temperature mixing, where we combine samples generated by LLMs using both high and low temperatures. We extensively evaluate our approach in three domains, namely databases (SQL), data science (Pandas) and business intelligence (Excel's Power Query M) on a variety of new and existing benchmarks. We observe substantial gains across domains, with improvements of up to 45% in top-1 accuracy and 34% in top-3 accuracy.

研究动机与目标

  • 解决在数据操作任务中自然语言到代码生成准确率低的问题,现有方法未能充分利用输入数据上下文。
  • 通过引入实际程序执行输出以克服仅依赖提示工程的局限性,实现更优的候选程序排序。
  • 通过引入基于数据感知的重排序机制,利用程序输出和语义相似性,提升程序合成中的 top-K 准确率。
  • 在无需微调或用户提供的测试用例的情况下实现高准确率代码生成,仅依赖自然语言描述和输入数据。
  • 为语义交错排序提供理论依据,并引入温度混合等实用技术,以提升大语言模型生成候选程序的多样性与质量。

提出的方法

  • 使用高和低温度采样混合的方式,从大语言模型生成多个候选程序(top-N),以增加多样性。
  • 在输入数据集的样本上执行每个候选程序,收集实际输出,过滤掉语法错误或无法执行的程序(语义过滤)。
  • 应用语义重排序,使用三种信号:(a) 正确性与语义过滤,以剔除格式错误的输出;(b) 语义交错排序,基于输出相似性对候选程序进行聚类和重排;(c) 基于输出的分数调优,利用大语言模型预测的输出。
  • 使用温度混合技术,将不同温度设置下的样本组合,以提高捕捉高质量候选程序的可能性。
  • 使用综合得分对候选程序进行重排序,该得分整合了对数概率、执行成功率和输出相似性,以优先选择正确程序。
  • 提出一种基于输出预测的新型分数调优技术,使生成的程序输出与大语言模型预测的输出对齐,从而提升排序性能。

实验结果

研究问题

  • RQ1与仅依赖提示工程相比,利用输入数据的实际程序执行输出是否能显著提升 NL-to-code 合成的准确率?
  • RQ2基于输出相似性的语义交错排序在重排序候选程序方面有多有效?其理论基础是否成立?
  • RQ3温度混合在多大程度上提升了大语言模型在程序合成任务中生成候选程序的多样性与质量?
  • RQ4基于输出的分数调优是否能通过使生成输出与大语言模型预测输出对齐,从而提升排序性能?
  • RQ5所提出的框架是否在无需微调或用户提供的测试用例的情况下,在多种数据操作领域(SQL、Pandas、Power Query M)达到最先进性能?

主要发现

  • 该框架在数据库、数据科学和商业智能任务中,实现了最高 45% 的 top-1 准确率提升和 34% 的 top-3 准确率提升。
  • 使用 Codex 模型时,该方法在 top-1 执行准确率上达到 76%,仅通过提示工程和执行反馈即超越了现有最先进方法。
  • 结合执行反馈的语义重排序显著优于基于对数概率的标准排序方法,尤其在降低错误或格式错误程序的排名方面表现更优。
  • 温度混合提升了候选程序的多样性,并提高了正确程序进入 top-N 集合的可能性,从而提升了 top-K 准确率。
  • 为语义交错排序提供了理论依据,表明基于输出相似性的聚类与重排可增强排序性能。
  • 该方法在无需用户提供的测试用例或模型微调的情况下取得优异结果,仅依赖自然语言描述和输入数据样本。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。