Generating vector representations of code capturing semantic similarity

US11238306B2 · US · B2

Patent metadata
FieldValue
Publication numberUS-11238306-B2
Application numberUS-201816143701-A
CountryUS
Kind codeB2
Filing dateSep 27, 2018
Priority dateSep 27, 2018
Publication dateFeb 1, 2022
Grant dateFeb 1, 2022

How to read this patent

A practical reading order for non-experts. Skip the full description unless you need deep technical detail.

  1. Title

    What the patent document calls the invention.

  2. Abstract

    A short plain-language summary of the technical disclosure.

  3. Assignees and inventors

    Who owns or filed the patent and who is credited as inventor.

  4. Key dates

    Filing, priority, publication, and grant dates set the timeline.

  5. First independent claim

    The legal scope of protection — read this for what is actually claimed.

  6. CPC / IPC classifications

    Technology tags used to group this patent with similar filings.

  7. Citations and related patents

    Prior art links and similar publications in this corpus.

Abstract

Official abstract text for this publication.

A method, system and computer program product for obtaining vector representations of code snippets capturing semantic similarity. A first and second training set of code snippets are collected, where the first training set of code snippets implements the same function representing semantic similarity and the second training set of code snippets implements a different function representing semantic dissimilarity. A vector representation of a first and second code snippet from either the first or second training set of code snippets is generated using a machine learning model. A loss value is generated utilizing a loss function that is proportional or inverse to the distance between the first and second vectors in response to receiving the first and second code snippets from the first or second training set of code snippets, respectively. The machine learning model is trained to capture the semantic similarity in the code snippets by minimizing the loss value.

First claim

Opening claim text (preview).

The invention claimed is: 1. A method for obtaining vector representations of code snippets capturing semantic similarity, the method comprising: collecting a first training set of code snippets which implement a same function representing semantic similarity; collecting a second training set of code snippets which implement a different function representing semantic dissimilarity; generating a vector representation of a first code snippet and a second code snippet by utilizing a machine learning model, wherein said first and second code snippets are from one of said first and second training sets of code snippets, wherein said machine learning model outputs a first vector and a second vector based on said first and second code snippets; generating a loss value utilizing a loss function that is proportional to a distance between said first and second vectors in response to receiving said first and second code snippets from said first training set of code snippets; generating a loss value utilizing said loss function that is inverse to said distance between said first and second vectors in response to receiving said first and second code snippets from said second training set of code snippets; and training said machine learning model to generate vector representations of code snippets capturing semantic similarity between said code snippets by minimizing said loss value. 2. The method as recited in claim 1 further comprising: receiving a new set of code snippets; and generating vector representations of said new set of code snippets capturing semantic similarity between said new set of code snippets using said trained machine learning model. 3. The method as recited in claim 2 , wherein said new set of code snippets comprises a third code snippet and a fourth code snippet, where said vector representations of said new set of code snippets comprise a third vector and a fourth vector, wherein a distance between said third and fourth vectors represents a degree of semantic similarity between said third and fourth code snippets. 4. The method as recited in claim 1 , wherein said first or second training sets of code snippets are obtained via programming competitions or by synthesizing code. 5. The method as recited in claim 1 , wherein said distance comprises one of the following distances: angular, Euclidean, and Manhattan. 6. The method as recited in claim 1 , wherein said first and second vectors correspond to a real-valued vector of n dimensions, where n is a positive number. 7. The method as recited in claim 1 , wherein said first training set of code snippets implements said same function for a subset of input parameters. 8. A computer program product for obtaining vector representations of code snippets capturing semantic similarity, the computer program product comprising a computer readable storage medium having program code embodied therewith, the program code comprising the programming instructions for: collecting a first training set of code snippets which implement a same function representing semantic similarity; collecting a second training set of code snippets which implement a different function representing semantic dissimilarity; generating a vector representation of a first code snippet and a second code snippet by utilizing a machine learning model, wherein said first and second code snippets are from one of said first and second training sets of code snippets, wherein said machine learning model outputs a first vector and a second vector based on said first and second code snippets; generating a loss value utilizing a loss function that is proportional to a distance between said first and second vectors in response to receiving said first and second code snippets from said first training set of code snippets; generating a loss value utilizing said loss function that is inverse to said distance between said first and second vectors in response to receiving said first and second code snippets from said second training set of code snippets; and training said machine learning model to generate vector representations of code snippets capturing semantic similarity between said code snippets by minimizing said loss value. 9. The computer program product as recited in claim 8 , wherein the program code further comprises the programming instructions for: receiving a new set of code snippets; and generating vector representations of said new set of code snippets capturing semantic similarity between said new set of code snippets using said trained machine learning model. 10. The computer program product as recited in claim 9 , wherein said new set of code snippets comprises a third code snippet and a fourth code snippet, where said vector representations of said new set of code snippets comprise a third vector and a fourth vector, wherein a distance between said third and fourth vectors represents a degree of semantic similarity between said third and fourth code snippets. 11. The computer program product as recited in claim 8 , wherein said first or second training sets of code snippets are obtained via programming competitions or by synthesizing code. 12. The computer program product as recited in claim 8 , wherein said distance comprises one of the following distances: angular, Euclidean, and Manhattan. 13. The computer program product as recited in claim 8 , wherein said first and second vectors correspond to a real-valued vector of n dimensions, where n is a positive number. 14. The computer program product as recited in claim 8 , wherein said first training set of code snippets implements said same function for a subset of input parameters. 15. A system, comprising: a memory for storing a computer program for obtaining vector representations of code snippets capturing semantic similarity; and a processor connected to said memory, wherein said processor is configured to execute the program instructions of the computer program comprising: collecting a first training set of code snippets which implement a same function representing semantic similarity; collecting a second training set of code snippets which implement a different function representing semantic dissimilarity; generating a vector representation of a first code snippet and a second code snippet by utilizing a machine learning model, wherein said first and second code snippets are from one of said first and second training sets of code snippets, wherein said machine learning model outputs a first vector and a second vector based on said first and second code snippets; generating a loss value utilizing a loss function that is proportional to a distance between said first and second vectors in response to receiving said first and second code snippets from said first training set of code snippets; generating a loss value utilizing said loss function that is inverse to said distance between said first and second vectors in response to receiving said first and second code snippets from said second training set of code snippets; and training said machine learning model to generate vector representations of code snippets capturing semantic similarity between said code snippets by minimizing said loss value. 16. The system as recited in claim 15 , wherein the program instructions of the computer program further comprise: receiving a new set of code snippets; and generating vector representations of said new set of code snippets capturing semantic similarity between said new set of code snippets using said trained machine learning model. 17. The system as recited in claim 16 , wherein

Assignees

Inventors

Classifications

  • Matching criteria, e.g. proximity measures · CPC title

  • G06F40/30Primary

    Semantic analysis · CPC title

  • Generating training patterns; Bootstrap methods, e.g. bagging or boosting · CPC title

  • Supervised learning · CPC title

  • Learning methods · CPC title

Patent family

Related publications grouped by family.

External sources

Frequently asked questions

Answers are generated from the same data shown on this page.

What does patent US11238306B2 cover?
A method, system and computer program product for obtaining vector representations of code snippets capturing semantic similarity. A first and second training set of code snippets are collected, where the first training set of code snippets implements the same function representing semantic similarity and the second training set of code snippets implements a different function representing sema…
Who is the assignee on this patent?
IBM
What technology area does this patent fall under?
Primary CPC classification G06F40/30. Mapped technology areas include Physics.
When was this patent published?
Publication date Tue Feb 01 2022 00:00:00 GMT+0000 (Coordinated Universal Time) (B2). Legal status and post-grant events are not shown on this page.
What related patents are in patentsdb?
We list 3 related publications on this page (citations in our corpus or others sharing the same primary CPC).