Systems and methods for semantic code search
Abstract
Embodiments described herein provides a contrastive learning framework that leverages hard negative examples, that are mined globally from the entire training corpus for a given query to improve the quality of code and natural language representations. Specifically, similar examples from the training corpus are extracted and used as hard negatives in an online manner during training while keeping the minibatch construction random.
Interactive Citation Constellation Global Citation Ranking
Interactive SVG Citation Constellation renders in Rust/WebAssembly. Prior art cited: 3 · Forward citations: 0.
Claims (8)
- Claim 1Independent Claim
A method for a natural language code search system, the method comprising: receiving, via a communication interface, a training corpus of bimodal pairs, wherein at least one training pair from the training corpus includes a natural language description and a corresponding programming language snippet; encoding, at a beginning of a first training epoch for training a code search neural network model using the training corpus, by an encoder associated with a first set of model parameters of the code search neural network model implemented on one or more processors, the training corpus of natural language descriptions and programming language snippet into a set of representations in a feature space, wherein the natural language description is encoded into a natural language representation and the corresponding programming language snippet is encoded into a programming language representation, wherein the natural language representation and the programming language representation form a po
- Claim 2Depends on #1
The method of claim 1, wherein the set of nearest neighbor representations are selected from a plurality of programming language representations that are generated from the training corpus, as having closest distances to the natural language representation in the feature space, and wherein the set of negative pairs contains a negative pair formed by a selected programming language representation and the natural language representation.
- Claim 3Depends on #1
The method of claim 1, wherein the set of nearest neighbor representations are selected from a plurality of natural language representations that are generated from the training corpus, as having closest distances to the natural language representation in the feature space, and wherein the set of negative pairs contains a negative pair formed by a corresponding programming language representation of a selected natural language representation and the natural language representation.
- Claim 4Depends on #1
The method of claim 1, wherein the set of nearest neighbor representations are selected from a plurality of programming language representations that are generated from the training corpus, as having closest distances to the programming language representation in the feature space, and wherein the set of negative pairs contains a negative pair formed by a corresponding natural language representation of a selected programming language representation and the programming language representation.
- Claim 5Depends on #1
The method of claim 1, wherein the set of nearest neighbor representations are selected from a plurality of natural language representations that are generated from the training corpus, as having closest distances to the programming language representation in the feature space, and wherein the set of negative pairs contains a negative pair formed by a selected natural language representation and the programming language representation.
- Claim 6Depends on #1
The method of claim 1, wherein the encoder is a Transformer encoder.
- Claim 7Depends on #1
The method of claim 1, wherein the natural language representation and the programming language representation are obtained by constructing a FAISS index of the at least one training pair at a beginning of training with initial model parameters for the encoder.
- Claim 8Depends on #7
The method of claim 7, wherein the FAISS index is periodically re-constructed using updated model parameters for the encoder after a training epoch.
Technical Overview & Description
CROSS REFERENCES The instant application is a nonprovisional of and claims priority under 35 U.S.C. § 119 to co-pending and commonly-owned U.S. provisional application No. 63/189,854, filed May 18, 2021, which is hereby expressly incorporated by reference herein in its entirety. TECHNICAL FIELD The embodiments relate generally to machine learning systems and computer vision, and more specifically to a contrastive learning mechanism of natural language and code representation for sematic code search. BACKGROUND Machine learning systems have been widely used in natural language processing (NLP) tasks, e.g., in question and answering, text classification, and/or the like. Retrieving semantically relevant code functions given a natural language (NL) or programming language (PL) query is a task of great practical value towards building productivity enhancing tools for software developers. Existing approaches to solve this task usually involve leveraging transformer based masked language models that are pre-trained on NL and PL and fine-tuned for code search. For example, contrastive learning may be used based on pairs of NL and PL samples. Positive pairs of NL and PL samples (e.g., NL description that matches with or corresponds to the PL snippet) are pulled closer in a cluster while negative pairs of NL and PL samples (e.g., NL description that does not match with or correspond to the PL snippet) may be pushed away in the feature space. Traditionally, the negative pairs for training may be randomly generated from the training corpus. These existing approaches, however, often, under-utilize the bimodal setup of natural language and programming code. BRIEF DESCRIPTION OF THE DRAWINGS FIG. 1 is a simplified diagram illustrating a sematic code search based on a NL query, according to an embodiment described herein. FIG. 2 is a simplified diagram illustrating a contrastive learning framework for training the sematic code search module shown in FIG. 1 , according to one embod
Cited By — Indexed Forward Citations (0 of 0 total)
No indexed citing patents in this generation yet. Ingest USPTO/PatentsView bulk citation tables via patents-ingest to expand the local forward citation graph.
References Cited — Backward Prior Art (3)
| Patent | Title | Year | Citations |
|---|
Non-Patent Literature (10)
- Heyman, Geert, and Tom Van Cutsem.
- “
- Neural code search revisited: Enhancing code snippet retrieval through natural language intent.
- ”
- arXiv preprint arXiv:2008.12193 (2020). (Year: 2020).
- Le-Khac, Phuc H., Graham Healy, and Alan F. Smeaton.
- “
- Contrastive representation learning: A framework and review.
- ”
- Ieee Access 8 (2020): 193907-193934. (Year: 2020).