For a complicated algorithm, its implementation by a human programmer usually starts with outlining a rough control flow followed by iterative enrichments, eventually yielding carefully generated syntactic structures and variables in a hierarchy. However, state-of-the-art large language models generate codes in a single pass, without intermediate warm-ups to reflect the structured thought process of "outline-then-detail". Inspired by the recent success of chain-of-thought prompting, we propose ChainCoder, a program synthesis language model that generates Python code progressively, i.e. from coarse to fine in multiple passes. We first decompose source code into layout frame components and accessory components via abstract syntax tree parsing to construct a hierarchical representation. We then reform our prediction target into a multi-pass objective, each pass generates a subsequence, which is concatenated in the hierarchy. Finally, a tailored transformer architecture is leveraged to jointly encode the natural language descriptions and syntactically aligned I/O data samples. Extensive evaluations show that ChainCoder outperforms state-of-the-arts, demonstrating that our progressive generation eases the reasoning procedure and guides the language model to generate higher-quality solutions. Our codes are available at: https://github.com/VITA-Group/ChainCoder.
翻译:对于复杂算法,人类程序员通常先勾勒出粗略的控制流框架,再通过迭代式细化逐步生成层次化语法结构和变量。然而,当前最先进的大语言模型采用单次生成方式,缺乏反映"先纲后目"结构化思维过程的中间预热环节。受最近思维链提示成功的启发,我们提出ChainCoder——一种渐进式生成Python代码的程序合成语言模型,即通过多次传递实现由粗到细的生成。我们首先通过抽象语法树解析将源代码分解为布局框架组件与附属组件,构建层次化表示;进而将预测目标重构为多轮目标,每轮生成子序列并按层次结构拼接;最后利用定制化Transformer架构联合编码自然语言描述与语法对齐的输入输出数据样本。大量评估表明,ChainCoder优于现有方法,验证了渐进式生成能简化推理过程并引导语言模型生成更高质量的解。我们的代码已开源:https://github.com/VITA-Group/ChainCoder。