hottub.patents
US 12,400,068 B2#3460029 Most CitedActiveUnited States (USPTO)Utility

Systems and methods for natural language code search

0Forward Citations (#3460029 Global)
0.0/yrCitation Velocity (#3460029 Global)
0.00Citation PageRank (#3460029 Global)
9Prior Art Cited
20Claims (3 Indep. · 17 Dep.)
4Drawings / Sheets

Abstract

Embodiments are directed to translating a natural language query into a code snippet in a programing language that semantically represents the query. The embodiments include a cascading neural network that includes an encoder network and a classifier network. The encoder network being faster but less accurate than the classifier network. The encoder network is trained using a contrastive learning framework to identify code candidates from a large set of code snippets. The classifier network is trained using a binary classifier to identify the code snippet that semantically represents the query from the code candidates.

Interactive Citation Constellation Global Citation Ranking

Interactive SVG Citation Constellation renders in Rust/WebAssembly. Prior art cited: 9 · Forward citations: 0.

Claims (20 — 3 Independent, 17 Dependent)

  1. Claim 1Independent Claim

    A method for translating a natural language query into a code snippet in a programming language, the method comprising: generating, at an encoder network, a plurality of code snippet indices and a natural language query representation from a plurality of code snippets and the natural language query, respectively; determining one or more code candidates based on distance metrics between the natural language query representations and the plurality of code snippet indices; generating text-code pairs from the natural language query and the determined one or more code candidates based on the distance metrics, a text-code pair including the natural language query and a code candidate from the determined one or more code candidates; jointly encoding, by a single encoder of a classifier network, an input sequence concatenating the natural language query and the code candidate from the text-code pair into one joint representation, wherein the single encoder and the encoder network share one or more encoder layers; predicting, by a classification head of the classifier network, a matching probability that the natural language query and the code candidate are a match using an input of the one joint representation outputted from the single encoder; and outputting the code candidate in the programming language in response to the natural language query based on the matching probability.

  2. Claim 2Depends on #1

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

  3. Claim 3Depends on #1

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

  4. Claim 4Depends on #1

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

  5. Claim 5Depends on #1

    The method of claim 1, wherein the encoder network is trained on a different loss function from the classifier network.

  6. Claim 6Depends on #1

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

  7. Claim 7Depends on #1

    The method of claim 1, wherein generating the code candidates further comprises: generating encodings from the natural language query; and determining, using the code snippet index, the encodings of the code candidates that are within a distance determined by a distance function from the encodings of the natural language query.

  8. Claim 8Depends on #1

    The method of claim 1, wherein determining the code snippet further comprises: determining a confidence score that a code candidate of each pair is the semantic representation of the natural language query; ranking confidence scores of the pairs; and selecting a code candidate of a pair corresponding to a highest confidence score as the code snippet that is the semantic representation of the natural language query.

  9. Claim 9Independent Claim

    A system for translating a natural language query into a code snippet in a programming language, the system comprising: a memory configured to store a cascading neural network; a processor coupled to the memory and configured to execute instructions for causing the cascading neural network to: generate, at an encoder network of the cascading neural network, a plurality of code snippet indices and a natural language query representation from a plurality of code snippets and the natural language query, respectively; determine one or more code candidates based on distance metrics between the natural language query representation and the plurality of code snippet indices; generate text-code pairs from the natural language query and the determined one or more code candidates based on the distance metrics, a text-code pair including the natural language query and a code candidate from the determined one or more code candidates; jointly encode, by a single encoder of a classifier network, an input sequence concatenating the natural language query and the code candidate from the text-code pair into one joint representation, wherein the single encoder and the encoder network share one or more encoder layers; predict, by a classification head of the classifier network, a matching probability that the natural language query and the code candidate are a match using an input of the one joint representation outputted from the single encoder; and output the code candidate in the programming language in response to the natural language query, based on the matching probability.

  10. Claim 10Depends on #9

    The system of claim 9, wherein the processor is further configured to: train, the encoder network to determine the code candidates on a contrastive loss function; and train, the classifier network to determine the code snippet from the pairs using a cross-entropy objective function.

  11. Claim 11Depends on #9

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

  12. Claim 12Depends on #9

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

  13. Claim 13Depends on #9

    The system of claim 9, wherein to generate the code candidates the processor is further configured to: generate encodings from the natural language query; and determine, using the code snippet index, encodings of the code candidates that are within a distance determined by a distance function from the encodings of the natural language query.

  14. Claim 14Depends on #9

    The system of claim 9, wherein to determine the code snippet the processor is further configured to: determine a confidence score that a code candidate of each pair is a semantic representation of the natural language query; rank confidence scores of the pairs; and select a code candidate of a pair corresponding to a highest confidence score as the code snippet that is the semantic representation of the natural language query.

  15. Claim 15Independent Claim

    A non-transitory computer readable medium having instructions stored thereon, that when executed by a processor cause the processor to perform operations for translating a natural language query into a code snippet in a programming language, the operations comprising: generating, at an encoder network, a plurality of code snippet indices and a natural language query representation from a plurality of code snippets and the natural language query, respectively; determining one or more code candidates based on distance metrics between the natural language query representations and the plurality of code snippet indices; generating text-code pairs from the natural language query and the determined one or more code candidates based on the distance metrics, a text-code pair including the natural language query and a code candidate from the determined one or more code candidates; jointly encoding, by a single encoder of a classifier network, an input sequence concatenating the natural language query and the code candidate from the text-code pair into one joint representation, wherein the single encoder and the encoder network share one or more encoder layers; predicting, by a classification head of the classifier network, a matching probability that the natural language query and the code candidate are a match using an input of the one joint representation outputted from the single encoder; and outputting the code candidate in the programming language in response to the natural language query based on the matching probability.

  16. Claim 16Depends on #15

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

  17. Claim 17Depends on #15

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

  18. Claim 18Depends on #15

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

  19. Claim 19Depends on #15

    The non-transitory computer readable medium of claim 15, wherein generating the code candidates further comprises: generating encodings from the natural language query; and determining, using the code snippet index, encodings of the code candidates that are within a distance determined by a distance function from the encodings of the natural language query.

  20. Claim 20Depends on #15

    The non-transitory computer readable medium of claim 15, wherein determining the code snippet further comprises: determining a confidence score that a code candidate of each pair is a semantic representation of the natural language query; ranking confidence scores of the pairs; and selecting a code candidate of a pair corresponding to a highest confidence score as the code snippet that is the semantic representation of the natural language query.

Technical Overview & Description

CROSS-REFERENCE TO RELATED APPLICATIONS This application is a nonprovisional of and claims priority under 35 U.S.C. 119 to U.S. Provisional Application No. 63/252,393, filed Oct. 5, 2021, which is hereby expressly incorporated by reference herein in its entirety. TECHNICAL FIELD The embodiments relate generally to machine learning systems and natural language processing (NLP), and more specifically to searching code snippets using natural language. BACKGROUND Artificial intelligence (AI) models have been widely used in a variety of applications. Some AI models may be used to search and/or generate code snippets in programming languages in response to a natural language input. For example, a 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 a code segment (e.g., in Python, C#, etc.) that implements this function. Existing code generation systems have focused on either improving the speed of natural language search or on improving the accuracy of the natural language search. However, these existing natural language search methods largely struggle with a tradeoff between efficiency and exhaustiveness of the search. BRIEF DESCRIPTION OF THE DRAWINGS FIG. 1 is a simplified diagram of a computing device that implements a code generator, according to some embodiments. FIG. 2 is a simplified diagram of a code generator, according to some embodiments. FIG. 3 is a simplified diagram of a method for training the code generator, according to some embodiments. FIG. 4 is a simplified diagram of a method for determining a code snippet that is semantically equivalent to a natural language query, according to some embodiments. In the figures, elements having the same designations have the same or similar functions. DETAILED DESCRIPTION Natural language queries are being used to improve search in different areas, e.g., web search, database search, legal search, and/or the li

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.

Non-Patent Literature (10)

  • CoSQA: 20,000+ Web Queries for Code Search and Question Answering, arXiv:2105.13239v1 (Year: 2021).
  • Lobato,
  • “
  • Neural networks with optimal accuracy and speed in their predictions,
  • ”
  • Toward Data Science.com, Jul. 20, 2017 (available at: https://towardsdatascience.com/neural-networks-with-optimal-accuracy-and-speed-in-their-predictions-d2cdc3b21b50) (Year: 2017).
  • Pengcheng Yin, Bowen Deng, Edgar Chen, Bogdan Vasilescu, Graham Neubig,
  • “
  • Learning to Mine Aligned Code and Natural Language Pairs from Stack Overflow
  • ”