arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 1803.04715cs.LGcs.CLcs.SE
收藏

基于代码分布式向量表示的跨语言映射分层学习

Hierarchical Learning of Cross-Language Mappings through Distributed Vector Representations for Code

Singapore Management University(新加坡管理大学)

Nghi D. Q. Bui, Lingxiao Jiang

摘要:

将用一种程序设计语言编写的程序翻译成另一种语言对于需要用不同语言实现功能的软件开发任务可能是有用的。虽然过去的研究已经考虑了这个问题,但它们可能是特定于语言语法的,或者是特定于某些类型的代码元素(例如,令牌、短语、API使用)。本文提出了一种新的方法来自动学习跨语言表示的各种结构化代码元素,可用于程序翻译。我们的关键思想是两个折叠:首先,我们规范化和丰富的代码令牌流与额外的结构和语义信息,并训练跨语言的向量表示的令牌(又名。基于word 2 vec的共享嵌入,word 2 vec是一种用于产生词嵌入的基于神经网络的技术;其次,从自底向上的分层地,我们为更高粒度级别的代码元素构建共享嵌入(例如,表达式、语句、方法)从其组成部分的嵌入中提取,然后根据嵌入之间的相似性在跨语言的代码元素之间建立映射。我们对9个软件项目的约40,000个Java和C#源文件的初步评估表明,我们的方法可以自动学习不同语言中各种代码元素的共享嵌入,并以合理的平均精度分数识别它们的跨语言映射。与现有的映射库API方法的工具相比,我们的方法可以准确地识别更多的映射。映射结果和代码可以在https://github.com/bdqnghi/hierarchical-programming-language-mapping上访问。我们相信,我们的想法,学习跨语言的向量表示与代码结构信息可以是一个有用的一步,自动程序翻译。

英文摘要:

Translating a program written in one programming language to another can be useful for software development tasks that need functionality implementations in different languages. Although past studies have considered this problem, they may be either specific to the language grammars, or specific to certain kinds of code elements (e.g., tokens, phrases, API uses). This paper proposes a new approach to automatically learn cross-language representations for various kinds of structural code elements that may be used for program translation. Our key idea is two folded: First, we normalize and enrich code token streams with additional structural and semantic information, and train cross-language vector representations for the tokens (a.k.a. shared embeddings based on word2vec, a neural-network-based technique for producing word embeddings; Second, hierarchically from bottom up, we construct shared embeddings for code elements of higher levels of granularity (e.g., expressions, statements, methods) from the embeddings for their constituents, and then build mappings among code elements across languages based on similarities among embeddings. Our preliminary evaluations on about 40,000 Java and C# source files from 9 software projects show that our approach can automatically learn shared embeddings for various code elements in different languages and identify their cross-language mappings with reasonable Mean Average Precision scores. When compared with an existing tool for mapping library API methods, our approach identifies many more mappings accurately. The mapping results and code can be accessed at https://github.com/bdqnghi/hierarchical-programming-language-mapping. We believe that our idea for learning cross-language vector representations with code structural information can be a useful step towards automated program translation.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑