Large pre-trained language models have been used to generate code,providing a flexible interface for synthesizing programs from natural language specifications. However, they often violate syntactic and semantic rules of their output language, limiting their practical usability. In this paper, we propose Synchromesh: a framework for substantially improving the reliability of pre-trained models for code generation. Synchromesh comprises two components. First, it retrieves few-shot examples from a training bank using Target Similarity Tuning (TST), a novel method for semantic example selection. TST learns to recognize utterances that describe similar target programs despite differences in surface natural language features. Then, Synchromesh feeds the examples to a pre-trained language model and samples programs using Constrained Semantic Decoding (CSD): a general framework for constraining the output to a set of valid programs in the target language. CSD leverages constraints on partial outputs to sample complete correct programs, and needs neither re-training nor fine-tuning of the language model. We evaluate our methods by synthesizing code from natural language descriptions using GPT-3 and Codex in three real-world languages: SQL queries, Vega-Lite visualizations and SMCalFlow programs. These domains showcase rich constraints that CSD is able to enforce, including syntax, scope, typing rules, and contextual logic. We observe substantial complementary gains from CSD and TST in prediction accuracy and in effectively preventing run-time errors.
翻译:使用经过培训的大型语言模型来生成代码,为来自自然语言规格的合成程序提供了灵活的界面,为合成自然语言规格的程序提供了一个灵活的界面。 但是,它们往往违反其输出语言的合成和语义规则,限制了其实际使用性。 在本文中,我们提议Synchromesh:一个大幅提高经过培训的代码生成模式可靠性的框架。 同步chromesh由两个部分组成。 首先,它从一个培训银行中检索了几个例子,它使用了目标相似性图例(TST),这是一个用于选择语义错误的新方法。 TST学会学会学会学会了识别描述类似目标程序的语句,尽管表面自然语言特征存在差异。 然后,Synchromesh将这些实例输入到一个经过事先培训的语言模型和样本程序之中,使用Constraced Semantict de(CSDM) :这些将输出限制到一套目标语言的有效程序。 CSCSCSD对部分产出进行抽查,不需要再训练或微调语言模型。 我们通过从自然语言的逻辑规则(包括Svidual-L)的Svidual-rial Stilal Stalalal rial rial criviewal ridustration ridustration ridustral) riducal cal rical cal rical creal crical ripal prewal pral pral pral pressal pressal) pral press 和SUcal amtionalmationalmationalmation 3,我们用Sideal 和SBal 和SDL 3 和SDL creal-SDL 3 ex 范围,我们用SBal 和SBal 和SDal 和SVDal 3 和SDal 3 和SVDal-al-al-SBal-SDal-al-SBal-SBal-SBal-SBal-SBal-SBal-SBal-SBal-SDML Cal-SDMDRal-SBal-SBal-SBal-SD