Source code representation with deep learning techniques is an important research field. There have been many studies that learn sequential or structural information for code representation. But sequence-based models and non-sequence-models both have their limitations. Researchers attempt to incorporate structural information to sequence-based models, but they only mine part of token-level hierarchical structure information. In this paper, we analyze how the complete hierarchical structure influences the tokens in code sequences and abstract this influence as a property of code tokens called hierarchical embedding. The hierarchical embedding is further divided into statement-level global hierarchy and token-level local hierarchy. Furthermore, we propose the Hierarchy Transformer (HiT), a simple but effective sequence model to incorporate the complete hierarchical embeddings of source code into a Transformer model. We demonstrate the effectiveness of hierarchical embedding on learning code structure with an experiment on variable scope detection task. Further evaluation shows that HiT outperforms SOTA baseline models and show stable training efficiency on three source code-related tasks involving classification and generation tasks across 8 different datasets.
翻译:含有深层学习技术的源代码代表是一个重要的研究领域。 许多研究都为代码代表学习了序列或结构信息。 但是,基于序列的模型和非序列的模型都有其局限性。 研究人员试图将结构信息纳入基于序列的模型, 但是它们只包含象征性等级结构信息的一部分。 在本文中, 我们分析完整的等级结构如何影响代码序列中的代号, 并抽象地将这种影响作为代号属性的属性, 称为等级嵌入。 等级嵌入进一步分为声明级全球等级和象征级地方等级。 此外, 我们提议采用一个简单而有效的序列模型, 将源代码的完整等级嵌入纳入一个变异模式。 我们展示了学习代码结构中的等级嵌入的有效性, 实验了不同范围检测任务。 进一步的评估表明, HIT 超越了SOTA基线模型, 并展示了涉及8个不同数据集分类和生成任务的三种源代码相关任务的稳定培训效率。</s>