Neural language models can be successfully trained on source code, leading to applications such as code completion. However, their versatile autoregressive self-supervision objective overlooks important global sequence-level features that are present in the data such as syntactic correctness or compilability. In this work, we pose the problem of learning to generate compilable code as constraint satisfaction. We define an Energy-Based Model (EBM) representing a pre-trained generative model with an imposed constraint of generating only compilable sequences. We then use the KL-Adaptive Distributional Policy Gradient algorithm (Khalifa et al., 2021) to train a generative model approximating the EBM. We conduct experiments showing that our proposed approach is able to improve compilability rates without sacrificing diversity and complexity of the generated samples.
翻译:神经语言模型可以成功地接受源代码培训,从而导致代码完成等应用。然而,它们的多功能自动递减自我监督目标忽略了数据中存在的重要的全球序列级特征,如合成正确性或可调和性。在这项工作中,我们提出了学习生成可调和代码的问题,以此作为制约性满意度。我们定义了一种能源模型,它代表了一种预先训练的基因模型,它是一种只生成可调和序列的制约。然后我们使用KL-Adapive分配政策梯度算法(Khalifa et al., 2021)来培训一种与 EBM 相近的基因模型。我们进行实验表明,我们提出的方法能够提高可调和率,同时又不牺牲所生成样品的多样性和复杂性。