Skip to main content
QUICK REVIEW

[论文解读] Latent Programmer: Discrete Latent Codes for Program Synthesis

Joey Hong, David Dohan|arXiv (Cornell University)|Dec 1, 2020
Software Engineering Research参考文献 48被引用 5
一句话总结

Latent Programmer (LP) 是一种神经程序合成方法,通过使用离散潜在编码来引导两级搜索:首先从输入/输出示例中预测高层次计划(潜在编码),然后在计划的条件下生成目标程序。与 RobustFill 等基线方法相比,该方法在较长程序上的合成准确率提升了超过10%,尤其在复杂合成任务中表现更优。

ABSTRACT

In many sequence learning tasks, such as program synthesis and document summarization, a key problem is searching over a large space of possible output sequences. We propose to learn representations of the outputs that are specifically meant for search: rich enough to specify the desired output but compact enough to make search more efficient. Discrete latent codes are appealing for this purpose, as they naturally allow sophisticated combinatorial search strategies. The latent codes are learned using a self-supervised learning principle, in which first a discrete autoencoder is trained on the output sequences, and then the resulting latent codes are used as intermediate targets for the end-to-end sequence prediction task. Based on these insights, we introduce the \emph{Latent Programmer}, a program synthesis method that first predicts a discrete latent code from input/output examples, and then generates the program in the target language. We evaluate the Latent Programmer on two domains: synthesis of string transformation programs, and generation of programs from natural language descriptions. We demonstrate that the discrete latent representation significantly improves synthesis accuracy.

研究动机与目标

  • 为解决程序合成中大规模程序空间搜索的挑战,提出一种受人类编程行为启发的两级搜索策略。
  • 学习有意义且解耦的程序高层次表征,使其可作为指导程序生成的计划。
  • 通过利用离散潜在编码作为中间计划,提升程序合成的准确性,特别是对较长、更复杂的程序。
  • 通过将高层次规划与低层次实现细节解耦,实现对程序空间更高效、更多样化的探索。

提出的方法

  • 该方法使用离散自编码器(具体为 VQ-VAE)学习程序的离散潜在编码表征,将每个程序映射为一串离散符号。
  • 训练一个潜在预测网络,将输入/输出示例映射到真实离散潜在编码,学习从规范中预测高层次计划。
  • 潜在程序解码器以自回归方式、基于预测的潜在编码逐标记生成目标语言程序,使用对潜在序列的交叉注意力机制。
  • 模型采用两级束搜索:首先生成 L 个最佳潜在编码,然后为每个编码生成 B/L 个最佳程序。
  • 训练期间,将变量名和参数名统一归一化为 ARG_i 和 VAR_i,以减少噪声并提升潜在编码学习效果。
  • 该方法在两个领域进行评估:基于 I/O 示例的字符串转换任务与基于文档字符串的代码生成任务,采用 BLEU 和准确率作为指标。

实验结果

研究问题

  • RQ1通过自监督表征学习获得的离散潜在编码能否作为程序合成的有效高层次计划?
  • RQ2与端到端方法相比,使用潜在编码的两级搜索是否能提升程序合成的准确性?
  • RQ3Latent Programmer 的性能如何随程序长度变化,尤其是在与基线方法对比时?
  • RQ4所学习的潜在编码是否可被有意义地解释为语义计划,例如识别出常见的编程模式?

主要发现

  • 与最先进的基线方法(如 RobustFill 和 Dual)相比,Latent Programmer 在较长程序上的合成准确率提升了超过10%。
  • 在代码生成任务中,LP 在束搜索大小为 100 时达到 BLEU 得分为 21.3,显著优于次佳基线方法(17.2)。
  • 该方法在较长程序上表现出显著优势,此时搜索空间复杂度最高,证明了基于计划的搜索策略的有效性。
  • 可解释性分析显示,潜在标记在常见编程模式(如文件操作或系统调用)上呈现有意义的聚类,这通过相关程序标记的 TF-IDF 分析得以验证。
  • 对变量名和参数名的归一化处理(统一为 ARG_i 和 VAR_i)显著提升了模型学习程序编码器中语义潜在结构的能力。

更好的研究,从现在开始

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

无需绑定信用卡

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