# US 2025/0085942 A1 · Adapting existing source code snippets to new contexts

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2025/0085942 A1
- Document ID: US20250085942A1
- Status: Published application
- Kind: A1
- Application number: 18/960,573
- Filed: 2024-11-26
- Published: 2025-03-13
- Earliest claimed: 2021-01-27
- Assignees: Google Inc.
- Applicants: Google LLC
- Inventors: Qianyu Zhang; Bin Ni; Rishabh Singh; Olivia Hatalsky
- Web page: https://patentgrep.com/patent/US20250085942A1

## CPC

- G06F 8/447: {Target code generation}
- G06F 8/30: Creation or generation of source code
- G06F 8/33: Intelligent editors
- G06F 8/34: Graphical or visual programming
- G06F 8/36: Software reuse
- G06F 8/51: Source to source
- G06F 8/71: Version control (security arrangements therefor G06F21/57); Configuration management
- G06F 16/00: Information retrieval; Database structures therefor; File system structures therefor
- G06N 3/044: Recurrent networks, e.g. Hopfield networks
- G06N 3/0442: characterised by memory or gating, e.g. long short-term memory [LSTM] or gated recurrent units [GRU]
- G06N 3/0455: Auto-encoder networks; Encoder-decoder networks
- G06N 3/084: Backpropagation, e.g. using gradient descent
- G06F 16/2425: {Iterative querying; Query formulation based on the results of a preceding query}
- G06N 3/045: Combinations of networks
- G06N 3/088: Non-supervised learning, e.g. competitive learning
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)
- G06N: COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS

## Abstract

Implementations are described herein for adapting existing source code snippets to new contexts. In various implementations, a command may be detected to incorporate an existing source code snippet into destination source code. An embedding may be generated based on the existing source code snippet, e.g., by processing the existing source code snippet using an encoder. The destination source code may be processed to identify one or more decoder constraints. Subject to the one or more decoder constraints, the embedding may be processed using a decoder to generate a new version of the existing source code snippet that is adapted to the destination source code.

## Claims

### Claim 1

A method implemented using one or more processors, comprising:
detecting, at an application that facilitates text editing, a command to insert an existing textual snippet into a destination document between a first portion of the destination document and a second portion of the destination document;
causing an input for a language model to be assembled that includes first data indicative of the existing textual snippet, second data indicative of the first portion of the destination document that would precede the existing textual snippet, and third data indicative of a second portion of the destination document that would follow the existing textual snippet;
causing the input to be processed using the language model to generate a new version of the existing textual snippet adapted to a style of the destination document, wherein the style of the destination document comprises selection, placement, or formatting of symbols or tokens; and
causing the application to render visual output indicative of the new version of the existing textual snippet.

### Claim 2 (depends on 1)

The method of claim 1, wherein the existing textual snippet comprises an existing source code snippet and the new version of the existing textual snippet comprises a new version of the existing source code snippet.

### Claim 3 (depends on 2)

The method of claim 2, wherein the destination document comprises destination source code.

### Claim 4 (depends on 3)

The system of claim 3, wherein the existing source code snippet includes a function call, and the instructions to process include instructions to generate glue code to adapt the function call to the destination source code.

### Claim 5 (depends on 3)

The system of claim 3, wherein the new version of the existing source code snippet includes function names and variable names that are adapted to the destination source code.

### Claim 6 (depends on 3)

The system of claim 3, wherein the first data, second data, and third data comprise raw source code.

### Claim 7 (depends on 1)

The method of claim 1, wherein the destination document comprises a legal document.

### Claim 8 (depends on 4)

The method of claim 4, wherein the destination document comprises a contract.

### Claim 9 (depends on 1)

The method of claim 1, wherein the symbols or tokens comprise spaces, tabs, or parentheses.

### Claim 10 (depends on 1)

The method of claim 1, wherein the symbols or tokens comprise comments.

### Claim 11

A system comprising one or more processors and memory storing instructions that, in response to execution of the instructions by the one or more processors, cause the one or more processors to:
detect, at an application that facilitates text editing, a command to insert an existing textual snippet into a destination document between a first portion of the destination document and a second portion of the destination document;
cause an input for a language model to be assembled that includes first data indicative of the existing textual snippet, second data indicative of the first portion of the destination document that would precede the existing textual snippet, and third data indicative of a second portion of the destination document that would follow the existing textual snippet;
cause the input to be processed using the language model to generate a new version of the existing textual snippet adapted to a style of the destination document, wherein the style of the destination document comprises selection, placement, or formatting of symbols or tokens; and
cause the application to render visual output indicative of the new version of the existing textual snippet.

### Claim 12 (depends on 11)

The system of claim 11, wherein the existing textual snippet comprises an existing source code snippet and the new version of the existing textual snippet comprises a new version of the existing source code snippet.

### Claim 13 (depends on 12)

The system of claim 12, wherein the destination document comprises destination source code.

### Claim 14 (depends on 13)

The system of claim 13, wherein the existing source code snippet includes a function call, and the instructions to process include instructions to generate glue code to adapt the function call to the destination source code.

### Claim 15 (depends on 13)

The system of claim 13, wherein the new version of the existing source code snippet includes function names and variable names that are adapted to the destination source code.

### Claim 16 (depends on 13)

The system of claim 13, wherein the first data, second data, and third data comprise raw source code.

### Claim 17 (depends on 11)

The system of claim 11, wherein the destination document comprises a legal document.

### Claim 18 (depends on 14)

The system of claim 14, wherein the destination document comprises a contract.

### Claim 19 (depends on 11)

The system of claim 11, wherein the symbols or tokens comprise spaces, tabs, parentheses, or comments.

### Claim 20

At least one non-transitory computer-readable medium storing instructions that, in response to execution of the instructions by one or more processors, cause the one or more processors to:
detect, at an application that facilitates text editing, a command to insert an existing textual snippet into a destination document between a first portion of the destination document and a second portion of the destination document;
cause an input for a language model to be assembled that includes first data indicative of the existing textual snippet, second data indicative of the first portion of the destination document that would precede the existing textual snippet, and third data indicative of a second portion of the destination document that would follow the existing textual snippet;
cause the input to be processed using the language model to generate a new version of the existing textual snippet adapted to a style of the destination document, wherein the style of the destination document comprises selection, placement, or formatting of symbols or tokens; and
cause the application to render visual output indicative of the new version of the existing textual snippet.
