Annotations for developers
Techniques are described herein for translating source code in one programming language to source code in another programming language using machine learning. A method includes: receiving first source code in a first higher-level programming language; processing the first source code, or an intermediate representation thereof, using a sequence-to-sequence neural network model to generate a sequence of outputs, each including a probability distribution; generating second source code in a second higher-level programming language by, for each output in the sequence of outputs: determining a highest probability in the probability distribution associated with the output; in response to the highest probability exceeding a first threshold, generating a predicted portion of the second source code based on a token that corresponds to the highest probability; and in response to the highest probability not exceeding the first threshold, generating a placeholder; and outputting the second source code.
1 . A method implemented by one or more processors, the method comprising:
receiving first source code in a first higher-level programming language;
processing the first source code, or an intermediate representation of the first source code, using a neural network model to generate a sequence of outputs, wherein each output in the sequence of outputs comprises a probability distribution;
generating second source code in a second higher-level programming language by, for each output in the sequence of outputs, generating a predicted portion of the second source code based on the probability distribution, wherein in response to a highest probability in the probability distribution not exceeding a threshold, the predicted portion of the second source code is determined to be a low-confidence translation;
outputting the second source code;
for at least one of the predicted portions of the second source code, receiving confirmation that the predicted portion of the second source code is a correct translation of a corresponding portion of the first source code; and
retraining the neural network model by using in a feedback loop the confirmation that the predicted portion of the second source code is the correct translation.
2 . The method according to claim 1 , further comprising compiling the second source code using a compiler for the second higher-level programming language to generate a compiled representation of the second source code.
3 . The method according to claim 1 , further comprising:
for an additional one of the predicted portions of the second source code, receiving a rejection indicating that the additional one of the predicted portions of the second source code is an incorrect translation of a corresponding portion of the first source code; and
retraining the neural network model by using in a feedback loop the rejection indicating that the additional one of the predicted portions of the second source code is the incorrect translation.
4 . The method according to claim 1 , further comprising:
for an additional one of the predicted portions of the second source code, receiving a rejection indicating that the additional one of the predicted portions of the second source code is an incorrect translation of a corresponding portion of the first source code, and receiving a replacement portion of the second source code;
replacing the additional one of the predicted portions of the second source code with the replacement portion of the second source code; and
retraining the neural network model by using in a feedback loop the rejection indicating that the additional one of the predicted portions of the second source code is the incorrect translation and the replacement portion of the second source code.
5 . The method according to claim 1 , wherein the processing is performed on the intermediate representation of the first source code, and
further comprising generating the intermediate representation of the first source code by compiling the first source code using a compiler for the first higher-level programming language.
6 . The method according to claim 1 , further comprising, for each of the predicted portions of the second source code that are determined to be the low-confidence translation, providing, in a user interface, a visual indication that the predicted portion of the second source code is the low-confidence translation.
7 . The method according to claim 6 , wherein the visual indication is based on a confidence level that the predicted portion of the second source code is a correct translation of a corresponding portion of the first source code.
8 . A computer program product comprising one or more non-transitory computer-readable storage media having program instructions collectively stored on the one or more non-transitory computer-readable storage media, the program instructions executable to:
receive first source code in a first higher-level programming language;
process the first source code, or an intermediate representation of the first source code, using a neural network model to generate a sequence of outputs, wherein each output in the sequence of outputs comprises a probability distribution;
generate second source code in a second higher-level programming language by, for each output in the sequence of outputs, generating a predicted portion of the second source code based on the probability distribution, wherein in response to a highest probability in the probability distribution not exceeding a threshold, the predicted portion of the second source code is determined to be a low-confidence translation;
output the second source code;
for at least one of the predicted portions of the second source code, receive confirmation that the predicted portion of the second source code is a correct translation of a corresponding portion of the first source code; and
retrain the neural network model by using in a feedback loop the confirmation that the predicted portion of the second source code is the correct translation.
9 . The computer program product according to claim 8 , wherein the program instructions are further executable to compile the second source code using a compiler for the second higher-level programming language to generate a compiled representation of the second source code.
10 . The computer program product according to claim 8 , wherein the program instructions are further executable to:
for an additional one of the predicted portions of the second source code, receive a rejection indicating that the additional one of the predicted portions of the second source code is an incorrect translation of a corresponding portion of the first source code; and
retrain the neural network model by using in a feedback loop the rejection indicating that the additional one of the predicted portions of the second source code is the incorrect translation.
11 . The computer program product according to claim 8 , wherein the program instructions are further executable to:
for an additional one of the predicted portions of the second source code, receive a rejection indicating that the additional one of the predicted portions of the second source code is an incorrect translation of a corresponding portion of the first source code, and receive a replacement portion of the second source code;
replace the additional one of the predicted portions of the second source code with the replacement portion of the second source code; and
retrain the neural network model by using in a feedback loop the rejection indicating that the additional one of the predicted portions of the second source code is the incorrect translation and the replacement portion of the second source code.
12 . The computer program product according to claim 8 , wherein the processing is performed on the intermediate representation of the first source code, and
further comprising generating the intermediate representation of the first source code by compiling the first source code using a compiler for the first higher-level programming language.
13 . The computer program product according to claim 8 , wherein the program instructions are further executable to, for each of the predicted portions of the second source code that are determined to be the low-confidence translation, provide, in a user interface, a visual indication that the predicted portion of the second source code is the low-confidence translation.
14 . The computer program product according to claim 13 , wherein the visual indication is based on a confidence level that the predicted portion of the second source code is a correct translation of a corresponding portion of the first source code.
15 . A system comprising:
a processor, a computer-readable memory, one or more non-transitory computer-readable storage media, and program instructions collectively stored on the one or more non-transitory computer-readable storage media, the program instructions executable to:
receive first source code in a first higher-level programming language;
process the first source code, or an intermediate representation of the first source code, using a neural network model to generate a sequence of outputs, wherein each output in the sequence of outputs comprises a probability distribution;
generate second source code in a second higher-level programming language by, for each output in the sequence of outputs, generating a predicted portion of the second source code based on the probability distribution, wherein in response to a highest probability in the probability distribution not exceeding a threshold, the predicted portion of the second source code is determined to be a low-confidence translation;
output the second source code;
for at least one of the predicted portions of the second source code, receive confirmation that the predicted portion of the second source code is a correct translation of a corresponding portion of the first source code; and
retrain the neural network model by using in a feedback loop the confirmation that the predicted portion of the second source code is the correct translation.
16 . The system according to claim 15 , wherein the program instructions are further executable to compile the second source code using a compiler for the second higher-level programming language to generate a compiled representation of the second source code.
17 . The system according to claim 15 , wherein the program instructions are further executable to:
for an additional one of the predicted portions of the second source code, receive a rejection indicating that the additional one of the predicted portions of the second source code is an incorrect translation of a corresponding portion of the first source code; and
retrain the neural network model by using in a feedback loop the rejection indicating that the additional one of the predicted portions of the second source code is the incorrect translation.
18 . The system according to claim 15 , wherein the program instructions are further executable to:
for an additional one of the predicted portions of the second source code, receive a rejection indicating that the additional one of the predicted portions of the second source code is an incorrect translation of a corresponding portion of the first source code, and receive a replacement portion of the second source code;
replace the additional one of the predicted portions of the second source code with the replacement portion of the second source code; and
retrain the neural network model by using in a feedback loop the rejection indicating that the additional one of the predicted portions of the second source code is the incorrect translation and the replacement portion of the second source code.
19 . The system according to claim 15 , wherein the processing is performed on the intermediate representation of the first source code, and
further comprising generating the intermediate representation of the first source code by compiling the first source code using a compiler for the first higher-level programming language.
20 . The system according to claim 15 , wherein the program instructions are further executable to, for each of the predicted portions of the second source code that are determined to be the low-confidence translation, provide, in a user interface, a visual indication that the predicted portion of the second source code is the low-confidence translation.