Code Search based on Context-aware Code Translation
arXiv:2202.08029 · doi:10.1145/3510003.3510140
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. 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).
arXiv commentto be published in the 44th IEEE/ACM International Conference on Software Engineering (ICSE 2022) (ICSE'22)
References in corpus (12)
- Adam: A Method for Stochastic Optimization
- Efficient Estimation of Word Representations in Vector Space
- Neural Machine Translation by Jointly Learning to Align and Translate
- Distributed Representations of Sentences and Documents
- CodeSearchNet Challenge: Evaluating the State of Semantic Code Search
- Query Expansion Based on Crowd Knowledge for Code Search
- Self-Supervised Contrastive Learning for Code Retrieval and Summarization via Semantic-Preserving Transformations
- CoaCor: Code Annotation for Code Retrieval with Reinforcement Learning
- Opportunities and Challenges in Code Search Tools
- Learning API Usages from Bytecode: A Statistical Approach
- deGraphCS: Embedding Variable-based Flow Graph for Neural Code Search
- OCoR: An Overlapping-Aware Code Retriever
Cited by in corpus (5)
- Code Search: A Survey of Techniques for Finding Code
- Survey of Code Search Based on Deep Learning
- Approaching Code Search for Python as a Translation Retrieval Problem with Dual Encoders
- Deep Code Search with Naming-Agnostic Contrastive Multi-View Learning
- DeCoMa: Detecting and Purifying Code Dataset Watermarks through Dual Channel Code Abstraction