Multi-Perspective Alignment Mechanism for Code Search
Shun Yang, Bo Cai · 2022
Developers often tend to search and reuse code snippets from large code repositories to improve their programming skills. To support code reuse, early code search models used information retrieval (IR) techniques to index a large corpus of code and then returned relevant code based on search statements. However, IR-based models can cause information loss due to keyword matching. To solve this problem, developers applied deep learning (DL) techniques to encode search models. However, these models either learn isolated representations of codes and queries or learn interdependent representations of codes and queries in a single way, which both limit the effectiveness of the models.In this study, we propose a code search model MpaCS, which can interact from multiple perspectives to enable cross-language retrieval between code and query statements. MpaCS extracts code and query information from the code textual features (i.e., method name, and tokens), the code structural feature (i.e., abstract syntax tree), and the query feature (i.e., tokens). We first implement the alignment between code features and query features at the fragment level. Then we propose a context matching module to achieve a deeper interaction between the code and the query. Finally, we propose a new attention network to explore the maximum alignment relationship between code and query from another perspective. We evaluate the performance of MpaCS on two existing large-scale datasets with 69k and 105k code snippets, respectively. Experimental results show that MpaCS outperforms four state-of-the-art models DeepCS [1],UNIF [2], MPCAT [3] and CARLCS-CNN [4].