System and method for natural language code search

A cascaded neural network model combining a fast encoder and accurate classifier addresses the efficiency-comprehensiveness trade-off in code snippet search, improving retrieval performance in large code repositories.

JP2024538693AActive Publication Date: 2024-10-23SALESFORCE INC
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
JP2024520799
Authority / Receiving Office
JP · JP
Patent Type
Applications
Current Assignee / Owner
Priority Date
2022-01-28
Filing Date
2022-10-03
Publication Date
2024-10-23
Estimated Expiration
2042-10-03

AI Technical Summary

Technical Problem

Existing natural language search methods for code snippets face a trade-off between search efficiency and comprehensiveness, with fast encoder networks being inefficient but accurate binary classifiers being too slow for large code repositories.

Method used

A cascaded neural network model combining a fast encoder network and an accurate classifier network to improve search efficiency and accuracy by first identifying top candidates with the encoder and then refining them with the classifier.

Benefits of technology

The hybrid approach significantly enhances the speed and accuracy of retrieving semantically equivalent code snippets, balancing efficiency and comprehensiveness in large code repositories.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure 2024538693000001_ABST
    Figure 2024538693000001_ABST
Patent Text Reader

Abstract

An embodiment is directed to converting a natural language query into a programming language code snippet that semantically represents the query. The embodiment includes a cascaded neural network including an encoder network and a classifier network. The encoder network is faster but less accurate than the classifier network. The encoder network is trained to identify code candidates from a large set of code snippets using a contrastive learning framework. The classifier network is trained to identify code snippets that semantically represent the query from the code candidates using a binary classifier.
Need to check novelty before this filing date? Find Prior Art

Description

[Technical field]

[0001] This application claims priority to U.S. Provisional Patent Application No. 63 / 252,393, filed October 5, 2021, and U.S. Nonprovisional Patent Application No. 17 / 587,984, filed January 28, 2022, which are incorporated by reference herein in their entireties.

[0002] The present embodiments relate generally to machine learning systems and natural language processing (NLP), and more specifically to searching for code snippets using natural language. [Background technology]

[0003] Artificial intelligence (AI) models are widely used for a variety of applications. Some AI models may be used to search and / or generate code snippets in programming languages ​​in response to natural language input. For example, the natural language input may describe a function such as "filter the sales records that occurred at the zip code 94070," and the AI ​​model may generate or search code segments (e.g., Python, C#, etc.) that implement this function. Existing code generation systems have focused on either improving the speed of natural language search or improving the accuracy of natural language search. However, these existing natural language search methods suffer greatly from a trade-off between search efficiency and comprehensiveness. [Brief description of the drawings]

[0004] [Figure 1] 1 is a simplified diagram of a computing device implementing a code generator according to some embodiments.

[0005] [Diagram 2] 1 is a simplified diagram of a code generator according to some embodiments.

[0006] [Diagram 3] 1 is a simplified diagram of a method for training a code generator according to some embodiments.

[0007] [Figure 4] 1 is a simplified diagram of a method for determining code snippets that are semantically equivalent to a natural language query, according to some embodiments.

[0008] In the figures, elements with the same number have the same or similar functions. DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS

[0009] Natural language queries have been used to improve search in various domains, for example, web search, database search, legal search, etc. There is also interest in using natural language queries to search large sets of code snippets. Organizations with large code repositories may benefit from indexing and searching through the code and re-use code that they know works well. Some recent approaches to natural language search of code and code snippets leverage pairs of natural language and source code sequences to train text-to-code search models to search for examples of code snippets.

[0010] One approach to training the model involves using a contrastive learning framework. The model may be a fast encoder neural network, also known as a fast encoder. In the contrastive learning framework, pairs of natural language and program language sequences that match semantically are pulled together, while pairs that do not match semantically are pushed apart. The fast encoder network may use contrastive learning. The fast encoder network may be efficient for scenarios that involve searching a large number of candidate code snippets at the expense of semantic matching accuracy.

[0011] Another approach to training a model uses a binary classifier. This type of model uses a trained binary classifier that receives natural language and programming language sequences as input and predicts whether the natural language and programming language sequences match semantically. A model that uses a binary classifier may be considered a slow classifier. Although slow classifiers are more accurate, they become infeasible when searching for a large number of candidate code snippets due to the amount of time it takes the model to analyze the code snippet against the natural language sequence. In other words, a model trained using a contrastive learning framework may be at least 10 times faster but at least 10 times less accurate than a model that uses a binary classifier.

[0012] To improve natural language search of a large number of code snippets, embodiments are directed to a cascaded neural network model that includes both a fast encoder model and an accurate classifier model. The cascaded neural network model improves the efficiency of natural language search of a large set of code snippets. Specifically, the cascaded neural network model is a hybrid approach that combines a fast encoder network and a slow classifier network. First, the encoder network determines the top K code candidates from the set of code snippets based on a natural language query. Second, the top K code candidates are passed through a slow classifier network that pairs each code candidate with a natural language query and generates a confidence score for each pair. The code snippet with the highest confidence score may be the code snippet that semantically matches the natural language query.

[0013] The number K may indicate a threshold that identifies the number of code candidates that the encoder network may generate. The K threshold is preferably much smaller than the size of the set of code snippets. If the K threshold is too small, there is a high probability of missing the correct code snippet, and if the K threshold is too large, it may be infeasible to run the second stage slow classifier efficiently.

[0014] In some embodiments, the memory overhead for storing the fast encoder network and the slow classifier network may be minimized by sharing or partially sharing the weights of the networks, for example, the transformer encoder of the fast encoder and the slow classifier may be shared by training a transformer encoder to be used in both the fast encoder network and the slow classifier network.

[0015] As used herein, the term "network" may include any artificial intelligence network or system, neural network or system, and / or any hardware or software-based framework including any training or learning model implemented therein or in conjunction therewith.

[0016] As used herein, the term "module" may include a hardware or software-based framework that performs one or more functions. In some embodiments, a module may be implemented on one or more neural networks.

[0017] 1 is a simplified diagram of a computing device implementing a code generator according to some embodiments described herein. As shown in FIG. 1, computing device 100 includes a processor 110 coupled to a memory 120. The operation of computing device 100 is controlled by processor 110. Also, while computing device 100 is shown with only one processor 110, it is understood that processor 110 may be representative of one or more central processing units, multi-core processors, microprocessors, microcontrollers, digital signal processors, field programmable gate arrays (FPGAs), application specific integrated circuits, graphic processing units (GPUs), etc. within computing device 100. Computing device 100 may be implemented as a standalone subsystem, as a board added to a computing device, and / or as a virtual machine.

[0018] Memory 120 may be used to store software executed by computing device 100 and / or one or more data structures used during operation of computing device 100. Memory 120 may include one or more types of machine-readable media. Some common forms of machine-readable media may include, for example, a floppy disk, a flexible disk, a hard disk, a magnetic tape, any other magnetic medium, a CD-ROM, any other optical medium, punch cards, paper tape, any other physical medium with a pattern of holes, a RAM, a PROM, an EPROM, a FLASH-EPROM, any other memory chip or cartridge, and / or any other medium adapted to be read by a processor or a computer.

[0019] Processor 110 and / or memory 120 may be located in any suitable physical location. In some embodiments, processor 110 and / or memory 120 may be implemented on the same board, the same package (e.g., a system in package), the same chip (e.g., a system on chip), etc. In some embodiments, processor 110 and / or memory 120 may include distributed, virtualized, and / or containerized computing resources and multiple processors. Consistent with such embodiments, processor 110 and / or memory 120 may be located in one or more data centers and / or cloud computing facilities.

[0020] In some examples, memory 120 may include a non-transitory tangible machine-readable medium including executable code that, when operated by one or more processors (e.g., processor 110), may cause the one or more processors to perform methods described in further detail herein. For example, as shown, memory 120 includes instructions for a natural language (NL) processing module, such as code generator 130, that may be used to implement and / or emulate the systems and models and / or to implement any of the methods described further herein. In some examples, code generator 130 may receive input 140, such as, for example, natural language text, queries, or computer code, via data interface 115. Data interface 115 may be either a user interface that receives input 140 from a user, or a communications interface that receives or retrieves input 140 stored in memory 120 or another memory storage device, such as a database. Code generator 130 may generate output 150, such as a programmable language (PL) sequence, code, or code snippet that is semantically equivalent to the natural language text or query. In some embodiments, the code generator 130 may include a cascaded neural network including an encoder network 132 and a classifier network 134 such that the output of the encoder network 132 may be partially input to the classifier network 134.

[0021] FIG. 2 is a simplified diagram 200 of a code generator according to some embodiments. As illustrated in FIG. 2, the code generator 130 includes an encoder network 132 and a classifier network 134. The code generator 130 receives a natural language query or textual natural language query 202. The natural language query 202 may be the input 140 discussed in FIG. 1. The natural language query 202 may be human written or spoken text, such as "filter the sales records that occurred at the zip code 94070," which the code generator 130 may convert into a programming language sequence, such as a code snippet. The code generator 130 passes the natural language query 202 through the encoder network 132. The encoder network 132 may generate K code candidates 204A-204K. The code candidates 204A-204K may be programming language code snippets that semantically represent the natural language query 202 and / or that semantically match the natural language query 128. The classifier network 134 may receive pairs of code candidates 204A-204K from the natural language query 202. Each pair may include one of the candidates 204A-204K and the natural language query 202. The classifier network 134 may generate a code snippet 206, which is a semantic representation of the natural language query 202.

[0022] In some embodiments, the encoder network 132 is significantly faster, e.g., at least 10 times more, than the classifier network 134. Indeed, due to the speed of the encoder network 132, the encoder network 132 may quickly determine the code candidates 204A-204K from a large set of available code snippets. On the other hand, the classifier network 134 is slower than the encoder network 132, but is significantly more accurate, e.g., at least 10 times more accurate, in identifying code snippets that semantically match the natural language query 202. As shown in FIG. 2, the classifier network 134 receives pairs of the code candidates 204A-204K and the natural language query 202, and identifies the code snippet 206, which is a semantic representation of the natural language query 202. By using a hybrid approach including the encoder network 132 and the classifier network 134, the code generator 130 improves the speed and accuracy for determining the code snippet 206, which is a semantic representation of the natural language query 202.

[0023] In some embodiments, the encoder network 132 may be or include bidirectional encoder representations from transformers (BERT) or a variant of a BERT network. The BERT network or a variant of a BERT network may be pre-trained on programming language sequences in a variety of programming languages ​​to extract code snippets from text input. An exemplary pre-trained BERT network is GraphCodeBERT or CodeBERT. Exemplary programming languages ​​may be Ruby, JavaScript, Go, Python, Java, C, C++, C#, Php, etc. During the training phase, to recognize the code candidates 204, the encoder network 132 may be further trained in a contrastive learning framework using a bimodal dataset. In the bimodal dataset, positive pairs of semantically matching natural language query and programming language sequence representations are pulled together. Meanwhile, negative paired representations, which are randomly paired natural language queries and programming language sequences, are pushed apart. A contrastive loss function, such as the infoNCE loss function, may be used to train the encoder network 132 and is reproduced below.

number

[0024] Once trained, the encoder network 132 generates a set of candidate code snippets, denoted as code snippets 208.

number

number

[0025] In some embodiments, after generating the code snippet index 210, the encoder network 132 generates a natural query x i (natural language query 202), θ (x i ), query the code snippet index 210, and return the code snippet from C (the code snippets 208) that corresponds to the nearest neighbor(s) in the code snippet index 210. The nearest neighbor(s) may be calculated using a distance metric determined by a similarity function, for example, a cosine similarity function. Then, given a natural language query x i The rank r assigned to the correct code snippet from the set C of code snippets (code snippet 208) for i Using the MRR (mean reciprocal ranking) metric

number

[0026] In some embodiments, the classifier network 134 may also be or include bidirectional encoder representations from transformers (BERT) or a variation of a BERT network. The BERT network or a variation of a BERT network may be pre-trained on a programming language sequence to extract code snippets from a text input. An exemplary pre-trained BERT network may be GraphCodeBERT or CodeBERT, and exemplary programming languages ​​may be Ruby, JavaScript, Go, Python, Java, C, C++, C#, Php, etc.

[0027] The classifier network 134 is configured to process a natural language query x (shown as 202) i and a programming language sequence y j (one of the code candidates 204A-204K or another code sequence) as input, and i and the code sequence may be encoded together to perform binary classification. i and the code sequence y j In some embodiments, the classifier network 134 may predict whether a natural language input x i and the code sequence y j Concatenation of, [x i ;y j ] etc. may be received.

[0028] The classifier network 134 may be trained for binary classification using training batches. The training batches may include pairs, each pair including a natural language query and a code snippet. The training batches may be for a bimodal dataset, where positive pairs indicate a semantic match between the natural language query and the code snippet, and negative pairs indicate a semantic mismatch. A set of pairs including natural language queries and semantically programmed language sequences.

number

number

[0029] Training mini-batches of positive pairs

number

number

[0030] Once trained, the classifier network 134 may determine code snippets 206 from the natural language query 202 and the code candidates 204. For example, during inference, the classifier network 134 may receive multiple pairs as input, where each pair represents a set of candidate code snippets.

number

[0031] As mentioned above, the code generator 130 discussed herein includes a cascade of networks, such as the encoder network 132 and the classifier network 134, to combine the speed of the fast encoder network 132 with the accuracy of the classifier network 134 in a two-stage process. In the first stage, the encoder network 132 receives the natural language query 202 and generates code candidates 204A-204K from a set of code snippets C (code snippets 208). The encoder network 132 may determine an encoding of the natural language query 202 and match the encoding to a code snippet index 210 of the code snippet 208 using a distance function. In some embodiments, the encoder network 132 may determine K code candidates 204A-204K, where K is a configurable candidate threshold that may be a hyperparameter. Typically, the K candidates are the top candidates that have the closest distance in the code snippet index 210 to the encoding of the natural language query 202.

[0032] In a second stage, the code candidates 204 are paired with the natural language query 202. Exemplary pairs may be 202-204A, 202-204B, ..., 202-204K. The classifier network 134 receives the pairs 202-204A, 202-204B, ..., 202-204K. For each pair 202-204A, 202-204B, ..., 202-204K, the classifier network 134 returns a confidence score that the natural language query 202 semantically matches its counterpart in the code candidates 204A-204K using a binary classifier. Based on the confidence scores associated with the pairs 202-204A, 202-204B, ..., 202-204K, the classifier network 134 selects a code snippet 206 that semantically matches the natural language query 202. In some examples, the code snippet 206 may correspond to the pair with the highest confidence score.

[0033] As discussed above, the encoder network 132 is computationally faster but less accurate than the classifier network 134 in determining code snippets that semantically match a natural language query. Sequentially adding the classifier network 134 along with the encoder network 132 in a scheme where K<<|C| may add a small computational overhead. The second stage in which the classifier network 134 refines the code candidates 204A-204K improves retrieval performance if the value of K is set such that the recall of the encoder network 118 is reasonably high. In some embodiments, K may be a hyperparameter. Setting a very low K increases the likelihood of missing a code snippet 206 in the set of code candidates 204 passed to the classifier network 134. On the other hand, setting a high K makes the scheme infeasible for retrieval by the classifier network 134. However, setting K to a value such as 10 already provides a significant gain in retrieval performance compared to conventional code generation systems that only get a small improvement when K is set to 100 or more.

[0034] In some embodiments, the encoder network 132 and the classifier network 134 may share portions of the neural network structure. For example, the encoder network 132 and the classifier network 134 may share layer weights in a transformer encoder in a BERT network. By sharing the neural network structure, the memory overhead incurred by the encoder network 132 and the classifier network 134 is minimized. The sharing of the neural network structure by the encoder network 132 and the classifier network 134, e.g., the transformer layer, is represented by the infoNCE

number

number

[0035] In a shared embodiment, the classifier network 134 may have an additional classification layer or head that determines confidence scores for the pairs 202-204A, 202-204B, ..., 202-204K. The classifier network 134 would include a classification head on top of the transformer encoder. Additionally, the shared neural network structure may receive three inputs, the natural language query 202, the set C of candidate code snippets (code snippets 208), and the pairs 202-204A, 202-204B, ..., 202-204K. In a shared embodiment, two passes are made through the shared layer of the network, with the natural language query 202 being the input during the first pass and the pairs 202-204A, 202-204B, ..., 202-204K being input during the second pass.

[0036] 3 is a simplified diagram of a method 300 for training a code generator, according to some embodiments. One or more of the processes 302-304 of the method 300 may be implemented, at least in part, in the form of executable code stored on a non-transitory, tangible, machine-readable medium that, when executed by one or more processors, can cause the one or more processors to perform one or more of the processes 302-304.

[0037] In process 302, an encoder network is trained. For example, the encoder network 132, which may be a pre-trained BERT network, may be further trained in a contrastive learning framework to identify code snippets that semantically match natural language sequences. The contrastive loss function used to train the encoder network 132 may be a contrastive loss function, such as an infoNCE loss function. The training may include batches of negative and positive pairs, each pair including a natural language sequence and a programming language sequence. The training may continue iteratively until the infoNCE loss function is minimized.

[0038] In process 304, a classifier network is trained. For example, the classifier network 134, which may be a pre-trained BERT network, may be trained with binary classification to determine a probability score that a code snippet matches a natural language sequence. A cross-entropy objective function may be used to train the classifier network 134. Training may include batches of negative and positive pairs, each pair including a natural language sequence and a programming language sequence. Training may continue iteratively until the cross-entropy objective function is minimized.

[0039] 4 is a simplified diagram of a method 400 for generating code snippets that are semantically equivalent to natural language queries, according to some embodiments. One or more of the processes 402-408 of the method 400 may be implemented, at least in part, in the form of executable code stored on a non-transitory, tangible, machine-readable medium that, when executed by one or more processors, may cause the one or more processors to perform one or more of the processes 402-408.

[0040] In process 402, a code snippet index is generated. For example, the encoder network 132 receives code snippets 208 that may semantically correspond to a number of natural language queries. The encoder network 132 encodes the code snippets 208 and generates a code snippet index 210 that corresponds to the encoded code snippets. Process 402 may occur after the encoder network 132 is trained and before the encoder network 132 processes the natural language queries 202.

[0041] In process 404, code candidates for the natural language query are generated. For example, the encoder network 132 may receive the natural language query 202 and generate an encoding for the natural language query 202. The encoder network 132 may use the code snippet index 210 to match the encoding of the natural language query 202 to the encoding of the code snippet 208 to identify code candidates 204A-204K that may semantically match the natural language query 202. As mentioned above, the number of code candidates 204A-204K may be set using a number K, which may be a hyperparameter.

[0042] Pairs including a natural language query and a code candidate are generated in process 406. For example, the code generator 130 may generate pairs 202-204A, 202-204B, ..., 202-204K, each pair including the natural language query 202 and one of the code candidates 204A-204K.

[0043] In process 408, the code snippets are determined. For example, the classifier network 104 may receive pairs 202-204A, 202-204B, ..., 202-204K and determine a confidence score for each pair. The pair with the highest confidence score may be the code snippet 206 that semantically matches the natural language query 202.

[0044] Some examples of computing devices, such as computing device 100, may include a non-transitory tangible machine-readable medium that includes executable code that, when run by one or more processors (e.g., processor 110), may cause the one or more processors to perform the processes of methods 300-400. Some common forms of machine-readable media that may include the processes of methods 300-400 are, for example, a floppy disk, a flexible disk, a hard disk, a magnetic tape, any other magnetic medium, a CD-ROM, any other optical medium, a punch card, a paper tape, any other physical medium having a pattern of holes, a RAM, a PROM, an EPROM, a FLASH-EPROM, any other memory chip or cartridge, and / or any other medium adapted to be read by a processor or a computer.

[0045] This description and the accompanying drawings illustrating aspects, embodiments, implementations, or applications of the invention should not be construed as limiting. Various mechanical, compositional, structural, electrical, and operational changes may be made without departing from the spirit and scope of this description and claims. In some instances, well-known circuits, structures, or techniques have not been shown or described in detail so as not to obscure the embodiments of the present disclosure. Similar numbers in two or more figures represent the same or similar elements.

[0046] In this description, certain details are set forth that describe some embodiments that are not inconsistent with the present disclosure. Numerous details are set forth to provide a thorough understanding of the embodiments. It will be apparent to one skilled in the art that some embodiments may be practiced without some or all of these specific details. The specific embodiments disclosed herein are meant to be illustrative, but not limiting. One skilled in the art may recognize other elements that are not specifically described herein but are within the scope and spirit of the present disclosure. Additionally, to avoid unnecessary repetition, one or more features shown and described in connection with one embodiment may be incorporated in other embodiments unless otherwise specifically described or one or more features render one embodiment non-functional.

[0047] Although exemplary embodiments have been shown and described, a wide range of modifications, changes, and substitutions are contemplated in the foregoing disclosure, and in some instances, some features of the embodiments may be employed without the corresponding use of other features. Those skilled in the art will recognize many variations, alternatives, and modifications. Accordingly, the scope of the present invention should be limited only by the scope of the claims that follow, and it is appropriate that the claims be interpreted broadly in a manner consistent with the scope of the embodiments disclosed herein.

Claims

1. 1. A method for converting a natural language query into a programming language code snippet, comprising: generating a code snippet index from a plurality of code snippets in an encoder network; generating a plurality of code candidates for the natural language query using the code snippet index and the encoder network; generating a pair from the natural language query and the plurality of code candidates, the pair including the natural language query and a code candidate from the plurality of code candidates; and using a classifier network that sequentially follows the encoder network and the pair to determine the code snippet in the programming language for the natural language query, the code snippet being a semantic representation of the natural language query.

2. The method of claim 1 , further comprising training the encoder network to determine the code candidates with a contrastive loss function.

3. The method of claim 1 or 2, further comprising training the classifier network to determine the code snippets from the pairs using a cross-entropy objective function.

4. The method of claim 1 or 2, wherein the encoder network is an order of magnitude faster and an order of magnitude less accurate than the classifier network.

5. The method of claim 1 or 2, wherein the encoder network is trained with a different loss function than the classifier network.

6. The method of claim 1 or 2, wherein the encoder network shares a portion of a neural network structure with the classifier network.

7. Generating the plurality of code candidates includes: generating an encoding from the natural language query; and using the code snippet index to determine encodings of the plurality of code candidates that are within a distance from the encoding of the natural language query as determined by a distance function.

8. Determining the code snippet comprises: determining a confidence score for each pair of code candidates that they are semantic representations of the natural language query; ranking the confidence scores of the pairs; and selecting the pair of code candidates corresponding to the highest confidence score as the code snippet that is the semantic representation of the natural language query.

9. 1. A system for converting a natural language query into a programming language code snippet, comprising: a memory configured to store a cascaded neural network; a processor coupled to the memory, the processor configuring the cascaded neural network to: generating a code snippet index from a plurality of code snippets in an encoder network of the cascaded neural network; generating a plurality of code candidates for the natural language query using the code snippet index and the encoder network; generating a pair from the natural language query and the plurality of code candidates, the pair including the natural language query and a code candidate from the plurality of code candidates; and executing instructions to use the classifier network and the pair of cascaded neural networks to determine the code snippet in the programming language for the natural language query, the code snippet being a semantic representation of the natural language query.

10. The processor, training the encoder network to determine the code candidates with a contrastive loss function; 10. The system of claim 9, further configured to: train the classifier network to determine the code snippets from the pairs using a cross-entropy objective function.

11. 11. The system of claim 9 or 10, wherein the encoder network is an order of magnitude faster and an order of magnitude less accurate than the classifier network.

12. The system of claim 9 or 10, wherein the encoder network shares a portion of a neural network structure with the classifier network.

13. To generate the code candidates, the processor: generating an encoding from the natural language query; 11. The system of claim 9 or 10, further configured to: use the code snippet index to determine encodings of the plurality of code candidates that are within a distance from the encoding of the natural language query as determined by a distance function.

14. To determine the code snippet, the processor: determining a confidence score for each pair of code candidates that they are semantic representations of the natural language query; ranking the confidence scores of the pairs; and selecting the pair of code candidates corresponding to the highest confidence score as the code snippet that is the semantic representation of the natural language query.

15. 1. A non-transitory computer-readable medium having instructions stored thereon that, when executed by a processor, cause the processor to perform operations for converting a natural language query into a programming language code snippet, the operations comprising: generating a code snippet index from a plurality of code snippets in an encoder network; generating a plurality of code candidates for the natural language query using the code snippet index and the encoder network; generating a pair from the natural language query and the plurality of code candidates, the pair including the natural language query and a code candidate from the plurality of code candidates; and using a classifier network and the pair to determine the code snippet in the programming language for the natural language query, the code snippet being a semantic representation of the natural language query.

16. The operation includes: training the encoder network to determine the code candidates with a contrastive loss function; 16. The non-transitory computer-readable medium of claim 15, further comprising: training the classifier network to determine the code snippet from the pair using a cross-entropy objective function.

17. 17. The non-transitory computer-readable medium of claim 15 or 16, wherein the encoder network is an order of magnitude faster and an order of magnitude less accurate than the classifier network.

18. 17. The non-transitory computer-readable medium of claim 15 or 16, wherein the encoder network shares a portion of a neural network structure with the classifier network.

19. generating said code candidates generating an encoding from the natural language query; 17. The non-transitory computer readable medium of claim 15 or 16, further comprising: using the code snippet index to determine encodings of the plurality of code candidates that are within a distance from the encoding of the natural language query as determined by a distance function.

20. Determining the code snippet comprises: determining a confidence score for each pair of code candidates that they are semantic representations of the natural language query; ranking the confidence scores of the pairs; and selecting the pair of code candidates corresponding to the highest confidence score as the code snippet that is the semantic representation of the natural language query.

Citation Information

Patent Citations

  • Code search and code navigation

    US20200117446A1

  • Program generation device, program generation method, and program

    WO2021144904A1

  • Program generation device, program generation method, and program

    WO2021161428A1