Code Search based on Context-aware Code Translation

Weisong Sun, Chunrong Fang, Yuchen Chen, Guanhong Tao, Tingxu Han +1 more
2/16/2022
cs.SEcs.AI

Official code: wssun/TranCS (12 stars, Python, MIT, last commit 2021-11-14).

Abstract

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.

Show full abstract

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).

View on arXivView PDF

Code Implementations(1)

wssun/TranCSOfficial100%
MIT
123PythonSep 4, 20215 years agoMIT

Similar Papers

Cite this paper

@article{sun2022code,
  title  = {Code Search based on Context-aware Code Translation},
  author = {Weisong Sun and Chunrong Fang and Yuchen Chen and Guanhong Tao and Tingxu Han and Quanjun Zhang},
  year   = {2022},
  eprint = {2202.08029},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2202.08029}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2202.08029.svg)](https://codeofpaper.com/paper/2202.08029)

Discussion