[论文解读] Tree-to-tree Neural Networks for Program Translation
引入一个带注意力机制的树到树神经网络(包括一个父注意力馈送机制)来通过对齐源子树与目标子树来翻译程序;在 CoffeeScript↔JavaScript 和 Java→C# 基准测试中优于最先进的基线。
Program translation is an important tool to migrate legacy code in one language into an ecosystem built in a different language. In this work, we are the first to employ deep neural networks toward tackling this problem. We observe that program translation is a modular procedure, in which a sub-tree of the source tree is translated into the corresponding target sub-tree at each step. To capture this intuition, we design a tree-to-tree neural network to translate a source tree into a target one. Meanwhile, we develop an attention mechanism for the tree-to-tree model, so that when the decoder expands one non-terminal in the target tree, the attention mechanism locates the corresponding sub-tree in the source tree to guide the expansion of the decoder. We evaluate the program translation capability of our tree-to-tree model against several state-of-the-art approaches. Compared against other neural translation models, we observe that our approach is consistently better than the baselines with a margin of up to 15 points. Further, our approach can improve the previous state-of-the-art program translation approaches by a margin of 20 points on the translation of real-world projects.
研究动机与目标
- 将程序翻译作为一个模块化、树结构化的任务来激发神经模型的潜力。
- 提出一个 tree-to-tree encoder–decoder 架构,将源解析树翻译成目标解析树。
- 在目标树展开过程中融入注意力机制,以定位对应的源子树。
- 通过将父注意力向量 e_t 传入左/右子节点的解码器,增强模型的父注意力馈送机制。
提出的方法
- 将源/目标解析树转换为二叉表示(Left-Child Right-Sibling)。
- 使用 Tree-LSTM 编码器计算源树及子树的嵌入。
- 使用队列驱动的展开解码成目标树,通过在共享词汇表上的 softmax 预测节点值。
- 计算对源子树的注意力权重以形成嵌入 e_s,然后将其与解码器状态结合以产生 e_t。
- 通过将父注意力向量 e_t 输入到左右子解码器,应用父注意力馈送机制。
实验结果
研究问题
- RQ1tree-to-tree 神经体系结构是否能够在程序翻译任务上超越序列到序列和基于树的基线?
- RQ2对源解析树的注意力机制是否提高翻译质量,且所提的父注意力馈送对性能有何影响?
- RQ3模型在真实代码库中对不同语言对和程序长度的扩展性如何?
主要发现
- tree-to-tree 模型在程序翻译任务上持续优于基线,在基准上实现程序准确度最高可达 15 点的提升。
- 在 CoffeeScript→JavaScript 数据集上,模型在最佳基线之上实现最高约 20 点的改进,尤其是对较长程序。
- 没有注意力时模型在多个任务上接近 0%,而有注意力时在某些设置下性能提升至超过 90%。
- 对 Java→C#,tree-to-tree 方法显著优于以前的 SMT 基于方法,在真实世界项目上的程序准确度提升约 20%(因项目而异)。
- 引入父注意力馈送机制相对于没有它的变体在性能上有显著提升,尤其当树大小增大时。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。