基于上下文感知代码翻译的代码搜索
Code Search based on Context-aware Code Translation
摘要:
代码搜索是开发人员在软件开发期间广泛使用的技术。它根据开发人员的查询,从大型代码语料库中为他们提供语义相似的实现。现有技术利用深度学习模型来分别构造代码片段和查询的嵌入表示。抽象语法树、控制流图等特性,通常用于表示代码片段的语义。然而,这些特性的相同结构不一定表示代码片段的相同语义,反之亦然。此外,这些技术利用将查询词/代码令牌映射到嵌入表示的多个不同的词映射函数。这会导致查询和代码片段中相同单词/标记的不同嵌入。我们提出了一种新的上下文感知的代码翻译技术,将代码片段转换为自然语言描述(称为翻译)。代码翻译是在机器指令上进行的,其中上下文信息是通过模拟指令的执行来收集的。我们进一步设计了一个共享的词映射功能,使用一个单一的词汇表生成嵌入的翻译和查询。我们评估我们的技术,称为TranCS,CodeSearchNet语料库与1,000查询的有效性。实验结果表明,TranCS显着优于国家的最先进的技术的49.31%至66.50%的MRR(平均倒数排名)。
英文摘要:
Code search is a widely used technique by developers during software development. It provides semantically similar implementations from a large code corpus to developers based on their queries. Existing techniques leverage deep learning models to construct embedding representations for code snippets and queries, respectively. Features such as abstract syntactic trees, control flow graphs, etc., are commonly employed for representing the semantics of code snippets. However, the same structure of these features does not necessarily denote the same semantics of code snippets, and vice versa. In addition, these techniques utilize multiple different word mapping functions that map query words/code tokens to embedding representations. This causes diverged embeddings of the same word/token in queries and code snippets. We propose a novel context-aware code translation technique that translates code snippets into natural language descriptions (called translations). The code translation is conducted on machine instructions, where the context information is collected by simulating the execution of instructions. We further design a shared word mapping function using one single vocabulary for generating embeddings for both translations and queries. We evaluate the effectiveness of our technique, called TranCS, on the CodeSearchNet corpus with 1,000 queries. Experimental results show that TranCS significantly outperforms state-of-the-art techniques by 49.31% to 66.50% in terms of MRR (mean reciprocal rank).
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。