Using machine learning to translate between programming languages

By using machine learning-based generative adversarial networks to translate source code between programming languages ​​and generate human-readable synthetic natural code, it overcomes the barriers between different programming languages, improves the efficiency of software development and reduces costs.

CN114207576BActive Publication Date: 2025-09-23GOOGLE LLC
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202080050090.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Priority Date
2019-07-09
Filing Date
2020-07-09
Publication Date
2025-09-23
Estimated Expiration
2040-07-09

AI Technical Summary

Technical Problem

The boundaries between different programming languages ​​have become obstacles to software evolution, making replatforming and migrating code bases time-consuming and expensive, and making it difficult for programmers who are not familiar with the underlying programming languages ​​to effectively view and edit source code.

Method used

Using machine learning, specifically generative adversarial networks (GANs), we train generators and discriminators to translate source code between programming languages, generating synthetic, natural source code that is human-readable.

Benefits of technology

It achieves efficient translation between programming languages, reduces the cost of training new programmers, shortens refactoring and migration time, and improves development efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114207576B_ABST
    Figure CN114207576B_ABST
Patent Text Reader

Abstract

This article describes techniques for translating source code in one programming language into source code in another programming language using machine learning. In various embodiments, one or more components of one or more generative adversarial networks, such as a generator machine learning model, can be trained to generate "synthetic natural" source code that can be used as a translation of source code in an unfamiliar language. In some embodiments, a discriminator machine learning model can be employed to help train the generator machine learning model, for example, by being trained to distinguish between human-generated ("real") and machine-generated ("synthetic") source code.
Need to check novelty before this filing date? Find Prior Art

Description

Background Art

[0001] Computer software programming typically requires developers to read and / or write source code (i.e., program) in a specific language, such as Java, C++, C, Python, etc. Each programming language has its own advantages, disadvantages, nuances, idiosyncrasies, etc. Additionally, some programming languages ​​are better suited to certain stages of software development and / or the software life cycle than others. As an example, scripting languages ​​such as Python, JavaScript, Perl, etc. are often more effectively used in the early stages of software development because programmers using these languages ​​can turn around functional software relatively quickly.

[0002] Most programmers have at least a superficial understanding of multiple programming languages, but are only proficient in a few. Therefore, each programming language tends to have its own talent pool. When an entity such as a company chooses which programming language to use to form its code base, the size of the talent pool is a consideration. Unfortunately, the boundaries between different programming languages ​​have become one of the major obstacles to software evolution. As an example, suppose a company's code base is primarily written in a base programming language, but for whatever reason, the company decides that it needs new code written in a target programming language. The company's existing talent pool may be more specialized in the base programming language than in a second programming language. Hiring new programmers trained in the second programming language would be expensive. Training existing employees to program in the target programming language is also expensive. Replatforming and / or migrating the code base is also a time-consuming task, which consumes software development time. Summary of the Invention

[0003] This article describes techniques for translating source code in a "base" programming language into source code in another programming language, or "target" programming language, using machine learning. This allows, among other things, programmers who may not be familiar with the base programming language to review and / or edit source code written in the base language by first translating the source code into another, more familiar programming language.

[0004] Various types of machine learning models can be trained to translate between programming languages. In some embodiments, one or more generative adversarial networks ("GANs") can be trained, for example, for translation between one or more different programming languages. In some such embodiments, each GAN can be associated with a specific programming language. Each GAN can include a generator that is trained to generate "synthetically-naturalistic" (i.e., human-readable or human-friendly) source code in a target programming language, for example, based on input indicating source code in another programming language. Each GAN can also include a discriminator that is trained to distinguish between "real" source code written by a human in the target programming language and "synthetic" source code generated by the generator in the target programming language.

[0005] The generator and discriminator can be jointly trained (and with little or no supervision) using, for example, both “ground truth” or “human-written” source code snippets and synthetic natural source code snippets created based on the output of the generator. For example, assume that the synthetic natural source code snippet generated by the generator is considered by the discriminator to be “real”, i.e., written by a human. The adversarial loss associated with the output of the discriminator can reflect that the discriminator is “tricked” by the generator, and the discriminator can be trained accordingly. As another example, assume that the synthetic natural source code snippet generated by the generator is considered by the discriminator to be “synthetic”, i.e., generated by the generator. The adversarial loss associated with the output of the discriminator can reflect that the discriminator is not “tricked” by the generator, and the generator can be trained based on the adversarial loss. In various embodiments herein, the discriminator and / or generator can be trained using techniques such as backpropagation and gradient descent as examples.

[0006] When starting to train a GAN (or multiple) to facilitate translation between a base programming language and a target programming language, there may not always (or even often) be pairs of source code snippets that provide similar or corresponding functionality across the base programming language and the target programming language. Therefore, in some embodiments, a technique such as CycleGAN can be employed to jointly train one or more generators of one or more GANs to translate source code between the base programming language and the target programming language. By employing such a technique, there is no need to have functionally corresponding pairs of source code snippets in the base programming language and the target programming language.

[0007] The various machine learning models used for the generator and / or discriminator can take various forms. In some embodiments, one or both of the generator and the discriminator can take the form of a recursive neural network, such as a long short-term memory ("LSTM") or a gated recurrent unit ("GRU") network. In some embodiments, one or both of the generator and the discriminator can take the form of a sequence-to-sequence machine learning model, such as an encoder-decoder or an "autoencoder". In some such embodiments, the encoder-decoder can include an encoder trained to generate a latent space embedding based on a source code snippet written in a source programming language. The encoder can be coupled to, for example, a decoder that is trained to generate data indicating a source code snippet written in a target programming language (e.g., the source code itself, an abstract syntax tree or "AST", etc.) from the latent space embedding. In some embodiments, one or both of the generator and the discriminator can operate on a graph input and can take the form of, for example, a graph neural network ("GNN"), a graph convolutional network ("GCN"), a graph attention neural network ("GANN", not to be confused with a "GAN" or a generative adversarial network), etc.

[0008] Once the GAN(s) are trained, in some embodiments, the inference phase may proceed as follows. A source code snippet programmed in a base programming language (e.g., C++) may be processed (e.g., compiled) to generate a first "low-level representation." As used herein, a "low-level representation" may refer to bytecode, object code, binary code, assembly code, or any other representation of source code that is less human-readable than the source code from which the low-level representation was generated. The first low-level representation may then be processed (e.g., decompiled) to generate a "machine-friendly" or "unnatural" source code snippet in a target programming language (e.g., Java). As used herein, a "machine-friendly" or "unnatural" source code snippet is a snippet that is relatively incomprehensible to humans because it is generated by a computer from the low-level representation and lacks any style or other elements or features that make it understandable to humans (e.g., formatting, tabs, comments, etc.).

[0009] A non-natural source code snippet in a target programming language, and in some embodiments, an original source code snippet programmed in a base programming language, can be applied as input to a target programming language generator to generate a "human-friendly" or "synthetically natural" source code snippet in the target programming language. As used herein, a "human-friendly" or "synthetically natural" source code snippet is relatively understandable to humans, particularly compared to a machine-friendly or non-natural source code snippet, because it can include style or other elements / qualities that make it understandable to humans.

[0010] In various embodiments, synthetic natural source code snippets in a target programming language can be presented as output, for example, of a software development application. Thus, for example, a user unfamiliar with C++ but familiar with Java can select a C++ source code file to have all or a portion of the C++ source code file translated and displayed as natural-looking Java source code.

[0011] In some embodiments, a method implemented using one or more processors may include: processing a source code snippet programmed in a base programming language to generate a first low-level representation; processing the first low-level representation to generate an unnatural source code snippet in a target programming language; applying the unnatural source code snippet in the target programming language as input to a target programming language generator to generate a synthetic natural source code snippet in the target programming language; applying the synthetic natural source code snippet in the target language as input to a target programming language discriminator to generate an output that classifies the synthetic natural source code snippet as synthetic or artificially generated; and training one or both of the target programming language discriminator and the target programming language generator based on an adversarial loss of an output of the target programming language discriminator.

[0012] In various embodiments, a source code snippet programmed in a base programming language is also applied as input to the target language generator along with the unnatural source code snippet in the target programming language. In various embodiments, the method may further include: applying the synthetic natural source code snippet in the target programming language to the base programming language generator as input to generate a synthetic natural source code snippet in the base programming language; applying the synthetic natural source code snippet in the base programming language to the base programming language discriminator as input to generate an output that classifies the synthetic natural source code snippet in the base programming language as synthetic or artificially generated; and training one or both of the base programming language discriminator and the base programming language generator based on an adversarial loss of the output of the base programming language discriminator.

[0013] In various embodiments, the method may further include: compiling the synthesized natural source code snippet in the target programming language into a second low-level representation; and decompiling the second low-level representation to generate an unnatural source code snippet in the base programming language. In various embodiments, the unnatural source code snippet in the base programming language is also applied to a base programming language generator as input along with the synthesized natural source code snippet in the target programming language.

[0014] In various embodiments, one or both of the base programming language identifier and the base programming language generator are further trained based on similarity between source code snippets programmed in the base programming language and synthetic natural source code snippets in the base programming language. In various embodiments, the similarity comprises edit distance.

[0015] In various implementations, the first low-level representation includes object code or bytecode.

[0016] In another aspect, a method may include: processing a source code snippet programmed in a base programming language to generate a first low-level representation; processing the first low-level representation to generate an unnatural source code snippet in a target programming language; applying the unnatural source code snippet in the target programming language and the source code snippet programmed in the base programming language as input to a target programming language generator to generate a synthetic natural source code snippet in the target programming language; and rendering the synthetic natural source code snippet in the target programming language as an output of a software development application.

[0017] Additionally, some embodiments include one or more processors of one or more computing devices, wherein the one or more processors are operable to execute instructions stored in an associated memory, and wherein the instructions are configured to cause performance of any of the foregoing methods. Some embodiments also include one or more non-transitory computer-readable storage media storing computer instructions executable by the one or more processors to perform any of the foregoing methods.

[0018] It should be understood that all combinations of the foregoing concepts and additional concepts described in more detail herein are considered to be part of the subject matter disclosed herein. For example, all combinations of the claimed subject matter appearing at the beginning of this disclosure are considered to be part of the subject matter disclosed herein. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] Figure 1 An example environment is schematically depicted in which selected aspects of the present disclosure may be implemented, according to various implementations.

[0020] Figure 2 is a block diagram illustrating an example of how components of a generative adversarial network may be trained, according to various implementations.

[0021] Figure 3 Depicted are example applications of the techniques described herein, according to various implementations.

[0022] Figure 4 Flowcharts illustrating example methods for practicing selected aspects of the present disclosure are depicted.

[0023] Figure 5 Another flow chart illustrating an example method for practicing selected aspects of the present disclosure is depicted.

[0024] Figure 6 An example architecture for a computing device is shown. DETAILED DESCRIPTION

[0025] Figure 1An example environment is schematically depicted in which selected aspects of the present disclosure may be implemented, according to various implementations. Figure 1 Any computing device depicted in or elsewhere in the figures may include logic such as one or more microprocessors (e.g., a central processing unit or "CPU," a graphics processing unit or "GPU") that execute computer-readable instructions stored in memory, or other types of logic such as an application-specific integrated circuit ("ASIC"), a field-programmable gate array ("FPGA"), etc. Figure 1 Some of the systems depicted in , such as the code knowledge system 102 , can be implemented using one or more server computing devices forming what is sometimes referred to as a “cloud infrastructure,” but this is not required.

[0026] A code knowledge system 102 may be provided to assist the client 110 1-P Managing their respective code bases112 1-P In addition, the code knowledge system 102 may include a code translator 104 configured to perform selected aspects of the present disclosure in order to assist one or more clients 110 1-P Managing one or more corresponding code bases 112 1-P and / or one or more corresponding code libraries 112 1-P Each client 110 may be, for example, an entity or organization—such as a business (e.g., a financial institution, a bank, etc.), a nonprofit organization, a club, a university, a government agency—or any other organization that operates one or more software systems. For example, a bank may operate one or more software systems to manage funds under its control, including tracking deposits and withdrawals, tracking loans, tracking investments, etc. An airline may operate one or more software systems for booking / canceling / rebooking flight reservations, managing delays or cancellations of flights, managing personnel associated with a flight (such as passengers, crew, and ground staff), managing airport gates, etc.

[0027] The code translator 104 may be configured to leverage knowledge of multiple different programming languages ​​in order to edit, update, copy, migrate, or otherwise act upon its code base 112. 1-P Help client 110 1-P Translate between programming languages. For example, the code translator 104 can be configured to translate code snippets from one programming language to another programming language (e.g., on the fly) so that a developer proficient in a first programming language can view and / or edit source code originally written in a less familiar second programming language in the first programming language.

[0028] In various embodiments, the code knowledge system 102 may include machine learning ( Figure 1ML) database 104, which includes information indicating one or more trained machine learning models 106 1-N These trained machine learning models 106 1-N This may take various forms, which will be described in more detail below, including but not limited to generative adversarial network (“GAN”) components (such as a discriminator and / or generator), graph-based networks (such as a graph neural network (“GNN”), a graph attention neural network (“GANN”), or a graph convolutional neural network (“GCN”)), sequence-to-sequence models (such as an encoder-decoder), various flavors of recurrent neural networks (“RNNs,” e.g., long short-term memory or “LSTM,” gated recurrent units or “GRUs,” etc.), and any other type of machine learning model that may be applied to facilitate selected aspects of the present disclosure.

[0029] In some embodiments, the code knowledge system 102 may also access one or more programming language specific code libraries 108 1-M In some embodiments, these programming language specific code libraries 108 1-M Can be used, for example, to train a machine learning model 106 1-N In some such embodiments, and as will be described in further detail below, the programming language specific code library 108 1-M Can be combined with other data to train machine learning models106 1-N , such as other programming language specific code bases 108, to jointly learn transformations between programming languages.

[0030] In various embodiments, a client 110 that wishes to enable manipulation of its code base 112 in a programming language(s) other than the programming language(s) used to originally write the source code may communicate with the entity hosting the code knowledge system 102 ( Figure 1 (not shown) establish a relationship. When a developer wishes to view / edit source code snippets of the entity's code base 112 but is not familiar with the native programming language, the code translator 104 can provide a version of the source code snippet translated into the target programming language of the developer's preference. In some such embodiments, the code translator 104 can generate the translated source code snippets on the fly, for example, in real time. In other embodiments, the code translator 104 can operate, for example, in batch mode, to preemptively translate all or selected portions of the entity's code base 112 into the target programming language. In some embodiments where the developer then edits the translated source code snippets, assuming other necessary infrastructure is in place, the edited version can be translated back into the native programming language or left in the new target programming language.

[0031] Figure 2Is in machine learning model 106 1-N A block diagram of an example process flow that may be implemented in whole or in part by the code knowledge system 102 during training of the first programming language. Once trained, these models facilitate Figure 2 ) and the second programming language ( Figure 2 ) between the right side of the . Figure 2 The various components depicted in can be implemented by the code knowledge system 102, such as the code translator 104, or separately from the code knowledge system 102.

[0032] Starting from the top left, the first programming language source code ( Figure 2 The code base of the "first PL SC" segment 220 in FIG. 1 may include multiple source code files, libraries, etc., including samples of source code written by humans in a first programming language. Similarly, in the upper right, the second programming language source code ( Figure 2 The code library of the "second PL SC" segment 220 in the embodiment may include multiple source code files, libraries, etc., including samples of source code written by humans in the second programming language.

[0033] During training, a particular first programming language snippet A 222 written by a human developer may be obtained, for example, from a code base 220 or from another source. The particular first programming language snippet A 222 may be processed to generate a first "low-level representation" of the particular first programming language snippet A 222. The low-level representation may take various forms, such as object code or binary code, bytecode, or any other form "below" the human-written source code in the software development stack. Figure 2 In the example, a first programming language compiler 224 is used to compile a particular first programming language snippet A 222 into a first programming language binary and / or bytecode 2261 .

[0034] In some embodiments, the first programming language binary and / or bytecode 2261 can be translated into the second programming language binary and / or bytecode 2301, for example, by an intermediate representation (“IR”) translator 228. In other embodiments, the IR translator 228 can include a “built-in” compiler that directly translates the first programming language source code snippet A 222 into the second programming language binary and / or bytecode 2301. In such embodiments, the first programming language compiler 224 can be omitted and / or incorporated into the IR translator 228. For example, the IR translator can take the form of a low-level Java virtual machine (“LLJVM”) that converts, for example, C or C++ code (e.g., 222) into bytecode (e.g., 2301) that can be executed by a Java virtual machine (“JVM”).

[0035] In any case, once the second programming language binary / bytecode 2301 is generated, it can be processed, for example, by a second programming language decompiler 232 to generate the second programming language "machine-friendly" ( Figure 2 The second programming language machine-friendly source code snippet 234 may be an accurate and / or functional version of the source code in the second programming language. It may comply with various syntax and / or other constraints associated with the second programming language. However, the second programming language machine-friendly source code snippet 234 may be difficult for a human (e.g., a developer) to read because it is machine-generated. Therefore, it is described herein as "machine-friendly" because it may be "unnatural" to the point that a human developer cannot, at least not effectively, understand it.

[0036] In some embodiments, the second programming language machine-friendly source code snippet 234 can be applied as input to (across) the second programming language generator 236. The second programming language generator 236 can be a machine learning model that can take various forms, such as GNN, GANN, GCN, sequence-to-sequence model, RNN, LSTM, GRU, etc. In some embodiments, the second programming language generator 236 can also receive the first programming language source code snippet A 222 as input, which can be applied as input along with the second programming language machine-friendly source code snippet 234. Therefore, during training, the second programming language generator 236 effectively "learns" to act as a vocabulary and / or style "extractor."

[0037] The output of the second programming language generator 236 may be data indicating a second programming language "synthetic natural" source code snippet 238. The second programming language synthesized natural source code snippet 238 (and Figure 2 246) is so named because it is intended to be "human-friendly" or "human-readable," i.e., easily understood by human developers. For example, assuming the second programming language generator 236 is fully trained, its output should include style and / or vocabulary extracted from the first programming language source code snippet A 222 and / or from previous training examples using other source code snippets 220. In general, "data" "indicative" of a source code snippet can refer to the source code snippet itself or other representations of the source code, such as an abstract syntax tree ("AST"), a latent space embedding, etc.

[0038] However, in order to train the second programming language generator 236 to ensure that its output will be understandable to humans proficient in the second programming language, a second programming language identifier 240 can be provided. The second programming language identifier 240 can be trained to generate output that classifies the second programming language synthesized natural source code snippets 238 as synthesized or artificially generated. In various embodiments, the second programming language identifier 240 can be trained in part using a corpus or code base 242 of second programming language source code snippets. For example, during training, the second programming language identifier 240 can be trained using alternative "ground truth" second programming language source code snippets 242 and "synthesized" source code snippets in the form of second programming language synthesized natural source code snippets 238.

[0039] The second programming language identifier 240 and / or the second programming language generator 236 can be trained based on the adversarial loss of the output of the second programming language identifier 240. Assume that the output of the second programming language identifier 240 correctly classifies the input segment 238 as synthetic. This is an example of the second programming language generator 236 failing to "fool" the second programming language identifier 240. This can be used as a positive (or at least neutral) training example for the second programming language identifier 240 and as a negative training example for the second programming language generator 236.

[0040] As another example, assume that the output of the second programming language identifier 240 incorrectly classifies the input snippet 238 as genuine, when in fact it was synthetically generated by the second programming language generator 236. This is an example of the second programming language generator 236 successfully "fooling" the second programming language identifier 240. Therefore, this can be a negative training example for the second programming language identifier 240, and in some cases can be used as a positive training example for the second programming language generator 236.

[0041] As yet another example, assume that the output of the second programming language identifier 240 incorrectly classifies a “truth” or “real” second programming language source code snippet (e.g., from 242) as “synthetic.” This can serve as a negative training example for the second programming language identifier 240. In general, when machine learning models are described herein as being “trained,” it should be understood that various techniques can be used to train these models to be applicable, such as gradient descent, backpropagation, and the like, as described above.

[0042] use Figure 2In some embodiments, one or more machine learning models can be trained to translate from a second programming language to a first programming language. In some such instances, these components can be implemented as CycleGANs, so that code snippets in one language do not need to be precisely paired with code snippets of similar functionality in another language. Furthermore, CycleGANs can enable large-scale unsupervised training because source code corpora 220 and 242 (which can be enormous) can be used as training examples as described herein.

[0043] For example, in some embodiments, the second programming language synthesized natural source code snippet(s) 238 can be reused to train additional GAN ​​components associated with the first programming language, such as the first programming language generator 244 and / or the first programming language discriminator 248. Figure 2 In the second programming language synthesis natural source code snippet 238, for example, is processed by the second programming language compiler 250 into another low-level representation, which is in Figure 2 The first programming language binary and / or bytecode 2262 may be processed into a first programming language machine-friendly (or non-natural) source code snippet 254, for example, by a first programming language decompiler 252.

[0044] Similar to the input of the second programming language generator 236, Figure 2 In the example, both the first programming language machine-friendly source code snippet 254 and the second programming language synthesized natural source code snippet 238 (which plays a similar role as the first programming language source code snippet A 222 in the previous example) can be applied as input to the first programming language generator 244. The first programming language generator 244 can generate an output indicative of the first programming language synthesized natural source code snippet 246.

[0045] Similar to the example related to the second programming language, the first programming language synthesized natural source code snippet 246 can be applied as input to the first programming language identifier 248 to generate an output. The output can classify the first programming language synthesized natural source code snippet 246 as synthetic or artificially generated. As previously described, one or both of the first programming language identifier 248 and the first programming language generator 244 can be trained based on an adversarial loss of the output of the first programming language identifier 248.

[0046] In some embodiments, the first programming language identifier 248 and / or the first programming language generator 244 can be further trained based on the similarity between the first programming language source code snippet A 222 and the first programming language synthesized natural source code snippet 246. In some cases, this similarity can be referred to as a cycle consistency loss or restoration loss 254. The cycle consistency loss or restoration loss 254 can be determined in various ways. In some embodiments, the cycle consistency loss or restoration loss 254 can be determined based on the edit distance between the first programming language source code snippet A 222 and the first programming language synthesized natural source code snippet 246. In other embodiments, it can be the distance between the embeddings generated from 222 and 246 in the latent space. In other embodiments, it can take other forms.

[0047] The above description and Figure 2 The operations depicted in the examples are not meant to be limiting. For example, they may be performed in reverse. For example, human-written second programming language source code snippets 242 may be used to train first programming language generator 244 and / or first programming language identifier 248, rather than second programming language synthetic natural source code snippets 238 generated by second programming language generator 238.

[0048] Once trained Figure 2 The GAN components in the [ 2 ] can be used for various purposes. For example, the second programming language generator 236 can be used to translate a source code snippet in the first programming language (or data indicating a source code snippet, such as a latent space embedding or AST) into a source code snippet in the second programming language. Similarly, the first programming language generator 244 can be used to translate a source code snippet in the second programming language into a source code snippet in the first programming language. In some embodiments, a separate GAN can be trained for each pair of programming languages.

[0049] As previously described, in some embodiments, the first programming language generator 244, the first programming language identifier 248, the second programming language generator 236, and / or the second programming language identifier 240 can be implemented using a machine learning model that operates on the graph input. For example, for GNNs, the graph input can be in the form of an AST. Features can be extracted for each node of the AST (which can be manually selected or learned during training) to generate a feature vector for each node. Each node of the AST can represent a variable, an object, or other programming construct. Therefore, the features of the feature vector generated for the node can include features such as variable type (e.g., int, float, string, pointer, etc.), name, operator (or multiple) acting on the variable as an operand, etc. The feature vector of a node at any given point in time can be considered to be the "state" of the node. At the same time, each edge of the AST can be assigned a machine learning model, such as a specific type of machine learning model or a specific machine learning model trained on specific data.

[0050] Then, for each time step in a series of time steps, the feature vector or state of each node can be propagated to their neighbor nodes along the edge / machine learning model, for example, as a projection to the latent space. In some embodiments, the incoming node state to a given node at each time step can be summed with the current state of the given node, for example (which is order-invariant). As more time steps pass, the radius of the neighbor nodes of a given node that affects the AST increases.

[0051] Intuitively, knowledge about neighboring nodes is incrementally "baked into" the state of each node, and as the machine learning model is iterated more and more, more knowledge about increasingly distant neighbors is accumulated in the state of a given node. In some embodiments, the "final" state of all nodes of the AST can be reached after performing a certain desired number of iterations. This number of iterations can be a hyperparameter of the GNN. In some such embodiments, these final states can be summed to produce the overall state or embedding of the AST.

[0052] When a GNN is used to implement a generator (whether 236 or 244), the overall state or embedding of the AST can be applied as input to one or more additional machine learning models and / or other processing streams to generate synthetic natural source code. For example, an encoder-decoder network or "autoencoder" can be trained so that the encoder portion generates a latent space embedding from the input AST or source code, and the decoder portion translates the latent space embedding back to the original input. Once such an encoder-decoder network is trained, the decoder portion can be separated and applied to the latent space embedding generated by the GNN for the generator (e.g., 236, 244) to generate the AST and / or source code. In some embodiments where a GNN is used at least in part to implement a discriminator (e.g., 240, 248), the GNN can be coupled with a prediction layer, e.g., a softmax layer or a sigmoid function layer, which outputs yes or no (or 1 or 0, or a probability) based on the latent space embedding generated by the discriminator.

[0053] The techniques described herein may be used to provide a client device 110 operating, for example 1-P The present invention provides programmers with tools that facilitate translation between a source programming language and / or one or more target programming languages ​​(and in many cases, back again). These tools can be provided, for example, as features or plug-ins associated with software development tools. These tools can enable programmers to translate their source code into another programming language, or to view source code written in another, possibly unfamiliar, programming language in the light of the target programming language they were trained to develop the source code for.

[0054] Figure 3 An example of how a code snippet written in one programming language can be translated into a synthetic natural code snippet rendered in another programming language is depicted. In this example, a base source code snippet 360 is written in Java and prints the integers 1 to 5. At the bottom, a graphical user interface ("GUI") 362 is depicted that can be presented to a developer who is not familiar with Java but has expertise in another programming language. In this example, the code snippet 360 written in Java is converted by the code translator 104 into Python and rendered as part of the GUI 362. In this way, a developer operating the GUI 362 can view the source code in the programming language he or she is more familiar with. In some cases, the developer may be able to edit the translated source code. In some such embodiments, edits made by the developer (i.e., changes to the source code) are not automatically rendered. Figure 3 In some embodiments, the Python code in the code base may be translated back to Java before being stored and / or more permanently incorporated into the code base. In other embodiments, the edited Python code may be incorporated into the code base.

[0055] In some embodiments, the original source code 360 ​​can be sent to the code knowledge system 102 for translation by the code translator 104 before being sent to a computing device (not depicted) that renders the GUI 362. In other embodiments, the GUI 362 can be part of a software development application that performs programming language translation locally, for example using a plug-in or built-in functionality. Figure 3 The scenarios are for illustrative purposes only. The techniques described herein can be used to translate source code between programming languages ​​for any number of applications.

[0056] For example, assume that a first user trained in a base programming language sends a source code snippet in the base programming language to a second user, e.g., as an attachment or in the body of an email. In some embodiments, the source code in the base programming language can be translated into the target programming language on the way to the second user, e.g., by a code translator 104. Additionally or alternatively, in some embodiments, the second user's email application (or the email server storing the second user's emails) can have a plug-in configured with selected aspects of the present disclosure.

[0057] In some embodiments, a single user may operate a software development application to view multiple different source code snippets written in multiple different programming languages ​​that the user is not familiar with. In some such examples, multiple corresponding machine learning models (e.g., generators) may be used to translate the source code snippets from the multiple different programming languages ​​into a language (or languages) that the user better understands.

[0058] In some embodiments, the techniques described herein can be used to automatically convert source code written in one programming language into source code in another programming language without having to present the translated source code to a user as previously described. For example, a company may decide to replatform an existing code base 112 into a new programming language, for example, to gain new functionality and / or technical benefits (e.g., security features, processing speed features, etc.) that are not available in the original programming language. Such a company may be able to deploy the techniques described herein, or request that an entity associated with the code knowledge system 102 deploy the techniques described herein, to automatically convert all or a portion of the code base 112 from one programming language to another programming language.

[0059] Figure 44 is a flowchart illustrating an example method 400 for training various GAN components to translate between two programming languages ​​according to embodiments disclosed herein. For convenience, the operations of the flowchart are described with reference to a system performing the operations. The system may include various components of various computer systems, such as one or more components of the code knowledge system 102. Furthermore, while the operations of method 400 are illustrated in a particular order, this is not intended to be limiting. One or more operations may be reordered, omitted, or added.

[0060] At block 402, the system may process source code snippets programmed in a base programming language (e.g., C, C++) to generate a first low-level representation (e.g., bytecode and / or binary / object code, latent space embedding, etc.). Figure 2 , the first programming language compiler 224 compiles the first programming language source code snippet A 222 into a first programming language binary / bytecode 2261. In some cases, the first programming language binary / bytecode 2261 can then be translated, for example, by the IR translator 228 into a second programming language binary / bytecode 2301. Additionally or alternatively, in some embodiments where the IR translator 228 has and / or is a compiler (e.g., an LLJVM), the IR translator 228 can directly process the first programming language source code snippet A 222 into the second programming language binary / bytecode 2301.

[0061] At block 404, the system may decompile or otherwise process the first low-level representation to generate a non-natural source code fragment (e.g., in the target programming language). Figure 2 In the example, the second programming language decompiler 232 decompiles the second programming language binary / bytecode 2301 to generate a second programming language machine-friendly source code snippet 234 .

[0062] At block 406, the system may apply the unnatural source code snippet of the target programming language as input to a target programming language generator to generate a synthetic natural source code snippet of the target programming language. Figure 2 In the example, the second programming language machine-friendly source code snippet 234 is applied as input to the second programming language generator 236. In some embodiments, a source code snippet programmed in the base programming language is also applied as input to the target language generator along with the non-natural source code snippet in the target programming language. Figure 2 , both elements 234 and 222 are applied as input to a second programming language generator 236 to generate a second programming language synthesized natural source code snippet 238 .

[0063] At block 408, the system may apply the synthetic natural source code snippet in the target language as input to a target programming language identifier to generate an output that classifies the synthetic natural source code snippet as synthetic or artificially generated. Figure 2 In the example, the second programming language synthesized natural source code snippet 238 is applied as input to the second programming language identifier 240 to generate an output that classifies the second programming language synthesized natural source code snippet 238 as synthetic (machine-generated) or real (human-generated). In some embodiments, the second programming language identifier 240 or other identifiers described herein can also generate an output indicating whether the input (e.g., the second programming language synthesized natural source code snippet 238) conforms to the programming language "style" or language intrinsic nature of a given programming language.

[0064] At block 410, the system may train one or both of a target programming language identifier and a target programming language generator based on an adversarial loss of the output of the target programming language identifier. Figure 2 In the embodiment, one or both of the second programming language identifier 240 and / or the second programming language generator 236 are trained based on the correctness or incorrectness of the classification output by the second programming language generator 240 .

[0065] As previously mentioned Figure 2 As described, you can execute Figure 4 236 to train the first programming language generator 244 and / or the first programming language identifier 248. Furthermore, in some embodiments, the first programming language synthesized natural source code snippet 246 can be applied as input to the second programming language generator 236, e.g., along with the second programming language machine-friendly source code snippet 234, for training purposes (this is in addition to or in lieu of the combination of elements 222 and 234 used for training 236).

[0066] Figure 5 is a flowchart illustrating an example method 500 for performing inference using a GAN machine learning model using, for example, Figure 4 For convenience, the operations of the flowchart are described with reference to a system that performs the operations. The system may include various components of various computer systems, such as one or more components of the code knowledge system 102. Furthermore, while the operations of method 500 are shown in a particular order, this is not intended to be limiting. One or more operations may be reordered, omitted, or added.

[0067] At block 502, the system may process a source code snippet programmed in a base programming language to generate a first low-level representation. For example, the first programming source code snippet may be compiled by the first programming language compiler 224 to generate a first programming language binary / bytecode 2261, which may be translated by the IR translator 228 to generate a second programming language binary / bytecode 2301. Alternatively, the IR translator 228 may directly process the first programming language snippet to generate the second programming language binary / bytecode 2301.

[0068] At block 504, the system can process, e.g., decompile, the first low-level representation to generate a non-natural or "machine-friendly" source code snippet in the target programming language. For example, the second programming language decompiler 232 can decompile the second programming language binary / bytecode 2301 to generate the second programming language machine-friendly source code snippet 234.

[0069] At block 506, the system can apply the non-natural source code snippet of the target programming language and the source code snippet programmed in the base programming language as input to the target programming language generator to generate a synthetic natural source code snippet in the target programming language. For example, the first programming language snippet 222 and the second programming language machine-friendly source code snippet 234 can be applied as input to the second programming language generator 236. In some embodiments, during inference, the original first programming language snippet (which will be translated into the second programming language) can be omitted so that only the second programming language machine-friendly source code snippet 234 is applied to the second programming language generator 236. The output of the second programming language generator 236 can be a second programming language synthetic natural source code snippet 238.

[0070] At block 508, the system can render the synthesized natural source code snippet in the target programming language, for example, as output of a software development application. Figure 3 As shown, the second programming language synthesized natural source code snippet 238 may be rendered in whole or in part in a GUI associated with a software development application running, for example, on the client's computing system 110 .

[0071] Figure 66 is a block diagram of an example computing device 610 that can optionally be used to perform one or more aspects of the techniques described herein. The computing device 610 generally includes at least one processor 614 that communicates with a number of peripheral devices via a bus subsystem 612. These peripheral devices may include a storage subsystem 624 (including, for example, a memory subsystem 625 and a file storage subsystem 626), a user interface output device 620, a user interface input device 622, and a network interface subsystem 616. The input and output devices allow a user to interact with the computing device 610. The network interface subsystem 616 provides an interface to an external network and is coupled to corresponding interface devices in other computing devices.

[0072] The user interface input devices 622 may include a keyboard, a pointing device (such as a mouse, trackball, touchpad, or graphics tablet), a scanner, a touch screen incorporated into a display, an audio input device (such as a voice recognition system, a microphone), and / or other types of input devices. In general, the use of the term "input device" is intended to include all possible types of devices and ways of entering information into the computing device 610 or over a communication network.

[0073] User interface output device 620 may include a display subsystem, a printer, a fax machine, or a non-visual display such as an audio output device. The display subsystem may include a cathode ray tube (CRT), a flat panel device such as a liquid crystal display (LCD), a projection device, or some other mechanisms for creating a visible image. The display subsystem may also provide a non-visual display such as via an audio output device. Typically, the use of the term "output device" is intended to include all possible types of devices and methods for outputting information from computing device 610 to a user or another machine or computing device.

[0074] The storage subsystem 624 stores programming and data structures that provide the functionality of some or all of the modules described herein. For example, the storage subsystem 624 may include a Figure 4-5 Selected aspects of the method and implementation Figure 1-2 The logic of the various components is depicted in .

[0075] These software modules are typically executed by the processor 614 alone or in combination with other processors. The memory 625 used in the storage subsystem 624 can include multiple memories, including a main random access memory (RAM) 630 for storing instructions and data during program execution and a read-only memory (ROM) 632 in which fixed instructions are stored. The file storage subsystem 626 can provide persistent storage for program and data files and can include a hard drive, a floppy disk drive and associated removable media, a CD-ROM drive, an optical drive, or a removable media cartridge. Modules that implement the functionality of certain embodiments can be stored by the file storage subsystem 626 in the storage subsystem 624, or in other machines accessible by the processor 614 (or multiple).

[0076] The bus subsystem 612 provides a mechanism for the various components and subsystems of the computing device 610 to communicate with each other as intended. Although the bus subsystem 612 is shown schematically as a single bus, alternative implementations of the bus subsystem may use multiple busses.

[0077] The computing device 610 can be of various types, including a workstation, server, computing cluster, blade server, server farm, or any other data processing system or computing device. Due to the ever-changing nature of computers and networks, Figure 6 The description of the computing device 610 depicted in FIG is intended only as a specific example for the purpose of illustrating some embodiments. Many other configurations of the computing device 610 are possible with more Figure 6 The computing devices depicted in the drawings may have more or fewer components.

[0078] Although several embodiments have been described and illustrated herein, various other devices and / or structures may be utilized to perform the functions and / or obtain the results and / or one or more advantages described herein, and each of these variations and / or modifications is considered to be within the scope of the embodiments described herein. More generally, all parameters, dimensions, materials, and configurations described herein are intended to be exemplary, and actual parameters, dimensions, materials, and / or configurations will depend on one or more specific applications in which the teachings are used. Those skilled in the art will recognize or be able to determine many equivalents to the specific embodiments described herein using no more than routine experimentation. Therefore, it should be understood that the foregoing embodiments are presented only as examples, and within the scope of the appended claims and their equivalents, the embodiments may be practiced in a manner other than that specifically described and claimed. Embodiments of the present disclosure relate to each individual feature, system, article, material, kit, and / or method described herein. In addition, any combination of two or more such features, systems, articles, materials, kits, and / or methods is included within the scope of the present disclosure if such features, systems, articles, materials, kits, and / or methods are not mutually inconsistent.

Claims

1. A method for translating between programming languages ​​implemented using one or more processors, comprising: processing a source code fragment programmed in a base programming language to generate a first low-level representation; decompiling the first low-level representation to generate an unnatural source code fragment in a target programming language; applying the unnatural source code snippet of the target programming language as input to a target programming language generator to generate a synthetic natural source code snippet of the target programming language; applying a synthetic natural source code snippet in a target programming language as input to a target programming language discriminator to generate an output that classifies the synthetic natural source code snippet as synthetic or artificially generated; as well as One or both of the target programming language discriminator and the target programming language generator are trained based on an adversarial loss of an output of the target programming language discriminator.

2. The method according to claim 1, wherein Along with the non-natural source code snippet in the target programming language, a source code snippet programmed in the base programming language is also applied as input to the target programming language generator.

3. The method according to claim 1, further comprising: applying the synthetic natural source code snippet of the target programming language as input to a base programming language generator to generate a synthetic natural source code snippet of the base programming language; applying the synthetic natural source code snippet in the base programming language as input to a base programming language discriminator to generate an output that classifies the synthetic natural source code snippet in the base programming language as synthetic or artificially generated; as well as One or both of the base programming language discriminator and the base programming language generator are trained based on an adversarial loss of an output of the base programming language discriminator.

4. The method according to claim 3, further comprising: compiling synthetic natural source code snippets in a target programming language into a second low-level representation; as well as decompiling the second low-level representation to generate an unnatural source code fragment in a base programming language; Here, together with the synthesized natural source code snippets of the target programming language, unnatural source code snippets of the base programming language are also applied to the base programming language generator as input.

5. The method according to claim 3, wherein One or both of the base programming language identifier and the base programming language generator are further trained based on similarities between source code snippets programmed in the base programming language and synthetic natural source code snippets of the base programming language.

6. The method according to claim 5, wherein: The similarity includes edit distance.

7. The method according to claim 1, wherein The first low-level representation includes object code.

8. The method according to claim 1, wherein The first low-level representation comprises bytecodes.

9. A method for translating between programming languages ​​implemented using one or more processors, comprising: processing a source code fragment programmed in a base programming language to generate a first low-level representation; decompiling the first low-level representation to generate an unnatural source code fragment in a target programming language; applying the unnatural source code snippet in the target programming language and the source code snippet programmed in the base programming language as input to a target programming language generator to generate a synthetic natural source code snippet in the target programming language; as well as Rendering synthetic natural source code snippets in the target programming language as output of the software development application.

10. The method according to claim 9, wherein: Along with the unnatural source code snippet in the target programming language, a source code snippet programmed in the base programming language is also applied to the target programming language generator as input.

11. The method according to claim 9, wherein: The first low-level representation includes object code.

12. The method according to claim 9, wherein The first low-level representation comprises bytecodes.

13. A system for translating between programming languages ​​comprising one or more processors and a memory storing instructions that, in response to execution of the instructions by the one or more processors, cause the one or more processors to: processing a source code fragment programmed in a base programming language to generate a first low-level representation; processing the first low-level representation to generate an unnatural source code snippet in a target programming language; applying the unnatural source code snippet of the target programming language as input to a target programming language generator to generate a synthetic natural source code snippet of the target programming language; applying a synthetic natural source code snippet in a target programming language as input to a target programming language discriminator to generate an output that classifies the synthetic natural source code snippet as synthetic or artificially generated; as well as One or both of the target programming language discriminator and the target programming language generator are trained based on an adversarial loss of an output of the target programming language discriminator.

14. The system according to claim 13, wherein: Along with the unnatural source code snippet in the target programming language, a source code snippet programmed in the base programming language is also applied to the target programming language generator as input.

15. The system of claim 13, further comprising instructions to: applying the synthetic natural source code snippet of the target programming language as input to a base programming language generator to generate a synthetic natural source code snippet of the base programming language; applying the synthetic natural source code snippet in the base programming language as input to a base programming language discriminator to generate an output that classifies the synthetic natural source code snippet in the base programming language as synthetic or artificially generated; as well as One or both of the base programming language discriminator and the base programming language generator are trained based on an adversarial loss of an output of the base programming language discriminator.

16. The system of claim 15, further comprising instructions to: processing the synthetic natural source code snippet in the target programming language into a second low-level representation; and processing the second low-level representation to generate an unnatural source code snippet in a base programming language; in, Along with the synthesized natural source code snippet of the target programming language, an unnatural source code snippet of the base programming language is also applied to the base programming language generator as input.

17. The system according to claim 15, wherein: One or both of the base programming language identifier and the base programming language generator are further trained based on similarities between source code snippets programmed in the base programming language and synthetic natural source code snippets of the base programming language.

18. The system according to claim 17, wherein: The similarity includes edit distance.

19. The system of claim 13, wherein: The first low-level representation includes object code.

20. The system of claim 13, wherein: The first low-level representation comprises bytecodes.