IP Library Granted Patent US 12,265,805
Granted Patent B2
US 12,265,805 · App. 18/102,039 · Granted Apr 1, 2025

Syntactically coherent code segmentation

Inventors: Navneet Potti (Sunnyvale, CA); Joshua Howland (Mountain View, CA)
Assignee: GOOGLE LLC
G06F8/433G06F8/425G06F8/427
View Patent ↗
Loading inventors, assignments & file history…
Monitor This Case
Get email alerts when status or documents change.
Order Certified Copies
Most orders are placed with the USPTO same day — all within 24 business hours.
Order via The Patent Place →
Pre-filled with this patent's details
Quick Facts
Patent No.
US 12,265,805
App. No.
18/102,039
Granted
Apr 1, 2025
Kind
B2
Abstract

Techniques are described herein for segmenting source code into syntactically coherent sequences of tokens that satisfy constraints inherent in sequence-to-sequence networks. In various implementations, source code may be processed to generate one or more graphs representing the source code. One or more of the graphs may then be traversed to identify one or more sequences of tokens within the source code that satisfy an input constraint of a sequence-to-sequence network. The source code may be segmented into the identified one or more sequences of tokens. The one or more sequences of tokens may then be processed using the sequence-to-sequence network.

Claims (42)

1. A method implemented by one or more processors and comprising:

processing source code to generate one or more graphs representing the source code;

traversing one or more of the graphs to identify one or more sequences of tokens within the source code that satisfy an input constraint of a trained machine learning model comprising a transformer network with an attention mechanism, wherein the input constraint comprises a limit on how many tokens can be processed during a single iteration of the transformer network;

segmenting the source code into the identified one or more sequences of tokens; and

processing the one or more sequences of tokens using the transformer network.

2. The method of claim 1 , wherein the one or more graphs include an abstract syntax tree (AST) representing the source code.

3. The method of claim 1 , wherein the one or more graphs include at least one of a data flow graph (DFG) or a control flow graph (CFG) representing the source code.

4. The method of claim 1 , wherein the traversing one or more of the graphs to identify the one or more sequences of tokens includes:

determining a count of tokens represented by a node of one or more of the graphs; and

comparing the count of tokens to the input constraint of the transformer network.

5. The method of claim 4 , wherein determining the count includes:

identifying a portion of the source code represented by the node; and

consulting an interval tree based on the identified portion of the source code to determine the count.

6. The method of claim 4 , wherein the node is a first node, the count is a first count, and the method further comprises:

in response to a determination that the first count of tokens satisfies the input constraint of the transformer network, determining a second count of tokens represented by a second node of one or more of the graphs, and comparing the second count of tokens to the input constraint of the transformer network.

7. The method of claim 6 , wherein the second node comprises a sibling node of the first node.

8. The method of claim 4 , wherein the node is a first node, the count is a first count, and the method further comprises:

in response to a determination that the first count of tokens fails to satisfy the input constraint of the transformer network, determining a second count of tokens represented by a child node of the first node, and comparing the second count of tokens to the input constraint of the transformer network.

9. A system comprising one or more processors and memory storing instructions that, in response to execution by the one or more processors, cause the one or more processors to:

process source code to generate one or more graphs representing the source code;

traverse one or more of the graphs to identify one or more sequences of tokens within the source code that satisfy an input constraint of a trained machine learning model comprising a transformer network with an attention mechanism, wherein the input constraint comprises a limit on how many tokens can be processed during a single iteration of the transformer network;

segment the source code into the identified one or more sequences of tokens; and

process the one or more sequences of tokens using the transformer network.

10. The system of claim 9 , wherein the one or more graphs include an abstract syntax tree (AST) representing the source code.

11. The system of claim 9 , wherein the one or more graphs include at least one of a data flow graph (DFG) or a control flow graph (CFG) representing the source code.

12. The system of claim 9 , wherein the instructions to traverse one or more of the graphs to identify the one or more sequences of tokens include instructions to:

determine a count of tokens represented by a node of one or more of the graphs; and

compare the count of tokens to the input constraint of the transformer network.

13. The system of claim 12 , wherein the instructions to determine the count include instructions to:

identify a portion of the source code represented by the node; and

consult an interval tree based on the identified portion of the source code to determine the count.

14. The system of claim 12 , wherein the node is a first node, the count is a first count, and the system further comprises instructions to:

in response to a determination that the first count of tokens satisfies the input constraint of the transformer network, determine a second count of tokens represented by a second node of one or more of the graphs, and compare the second count of tokens to the input constraint of the transformer network.

15. The system of claim 14 , wherein the second node comprises a sibling node of the first node.

16. The system of claim 12 , wherein the node is a first node, the count is a first count, and the system further comprises instructions to:

in response to a determination that the first count of tokens fails to satisfy the input constraint of the transformer network, determine a second count of tokens represented by a child node of the first node, and compare the second count of tokens to the input constraint of the transformer network.

17. At least one non-transitory computer-readable medium comprising instructions that, when executed by one or more processors, cause the one or more processors to:

process source code to generate one or more graphs representing the source code;

traverse one or more of the graphs to identify one or more sequences of tokens within the source code that satisfy an input constraint of a trained machine learning model comprising a transformer network with an attention mechanism, wherein the input constraint comprises a limit on how many tokens can be processed during a single iteration of the transformer network;

segment the source code into the identified one or more sequences of tokens; and

process the one or more sequences of tokens using the transformer network.

18. The at least one non-transitory computer-readable medium of claim 9 , wherein the one or more graphs include at least one of a data flow graph (DFG) or a control flow graph (CFG) representing the source code.

Assignments (2)
CORRECTIVE ASSIGNMENT TO CORRECT THE COMPANY NAME FROM X DEVELOPMENT LLC TO GOOGLE LLC PREVIOUSLY RECORDED ON REEL 62700 FRAME 192. ASSIGNOR(S) HEREBY CONFIRMS THE ASSIGNMENT. Recorded Dec 11, 2024
From: POTTI, NAVNEET; HOWLAND, JOSHUA
To: GOOGLE LLC
Reel/Frame 069587/0192 →
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Feb 15, 2023
From: POTTI, NAVNEET; HOWLAND, JOSHUA
To: X DEVELOPMENT LLC
Reel/Frame 062700/0192 →
Continuity (1)
Related Publication 20240256235A1 · Aug 1, 2024
References Cited (5)
US 20200264852A1 · Craymer, III · 2020 [cited by examiner]
US 20230176838A1 · Bronevetsky · 2023 [cited by examiner]
“Interval Tree” Wikipedia. Retrieved from https://en.wikipedia.org/w/index.php?title=Interval_tree&oldid=1122891003, 9 pages. [cited by applicant]
Dwivedi et al., “A Generalization of Transformer Networks to Graphs” arXiv:2012.09699v2 [cs.LG] 8 pages, dated Jan. 24, 2021. [cited by applicant]
Sharma et al., “A Survey on Machine Learning Techniques for Source Code Analysis” arXiv:2110.09610v2 [cs.SE] 73 pages, dated Sep. 13, 2022. [cited by applicant]