kirancodes.me
To Proof Maintenance & Beyond!

Efficient Text-to-Code Retrieval with Cascaded Fast and Slow Transformer Models

Akhilesh Deepak Gotmare, Junnan Li, Shafiq Joty, Steven C. H. Hoi

Abstract

The goal of semantic code search or text-to-code search is to retrieve a semantically relevant code snippet from an existing code database using a natural language query. When constructing a practical semantic code search system, existing approaches fail to provide an optimal balance between retrieval speed and the relevance of the retrieved results. We propose an efficient and effective text-to-code search framework with cascaded fast and slow models, in which a fast transformer encoder model is learned to optimize a scalable index for fast retrieval followed by learning a slow classification-based re-ranking model to improve the accuracy of the top K results from the fast retrieval. To further reduce the high memory cost of deploying two separate models in practice, we propose to jointly train the fast and slow model based on a single transformer encoder with shared parameters. Empirically our cascaded method is not only efficient and scalable, but also achieves state-of-the-art results with an average mean reciprocal ranking (MRR) score of 0.7795 (across 6 programming languages) on the CodeSearchNet benchmark as opposed to the prior state-of-the-art result of 0.744 MRR. Our codebase can be found at this link.

BibTeX
@inproceedings{Gotmare-al:FSE23,
  author    = {Akhilesh Deepak Gotmare and
               Junnan Li and
               Shafiq Joty and
               Steven C. H. Hoi},
  title     = {Efficient {Text-to-Code} Retrieval with Cascaded Fast and Slow Transformer Models},
  booktitle = {{ESEC/SIGSOFT} {FSE}},
  pages     = {388--400},
  publisher = {{ACM}},
  year      = {2023},
}

Related papers