Actor-critique code-to-code translation
Methods and systems of translation include performing a search of translation hypotheses for input source code in a first programming language to a second programming language. A constraint is extracted from the input source code. The constraint is applied to the translation hypotheses to generate a source code output in the second programming language.
1 . A computer-implemented method for translation, comprising:
performing a beam search of translation hypotheses for input source code in a first programming language to a second programming language;
extracting a constraint from the input source code; and
applying the constraint to the translation hypotheses, after a number of hypotheses are selected for consideration in a next iteration of the beam search, to generate a source code output in the second programming language.
2 . The method of claim 1 , wherein applying the constraint includes filtering a set of complete hypotheses generated by the search.
3 . The method of claim 1 , wherein applying the constraint includes limiting branches taken by the search according to the constraint.
4 . The method of claim 1 , wherein the beam search uses a translation model to generate the translation hypotheses.
5 . The method of claim 4 , wherein the constraint is applied before a number of hypotheses are selected for consideration in a next iteration of the beam search, and the number of hypotheses is determined by a beam width.
6 . The method of claim 4 , wherein the number of hypotheses is a beam width, reduced by a number of pruned hypotheses.
7 . The method of claim 6 , wherein a number of additional hypotheses are selected responsive to the number of pruned hypotheses exceeding a threshold value.
8 . The method of claim 4 , wherein the constraint is applied before a number of hypotheses are selected for consideration in a next iteration of the beam search, such that the number of hypotheses is maintained at a beam width.
9 . The method of claim 1 , wherein the constraint is selected from the group consisting of a number of variables in the output source code being the same as a number of variables in the input source code, names of variables in the output source code being the same as variables in the input source code, and data types of variables in the output source code being the same as variables in the input source code.
10 . The method of claim 1 , further comprising compiling or executing the source code output.
11 . A computer program product for translation, the computer program product comprising a computer readable storage medium having program instructions embodied therewith, the program instructions being executable by a hardware processor to cause the hardware processor to:
perform a beam search of translation hypotheses for input source code in a first programming language to a second programming language;
extract a constraint from the input source code; and
apply the constraint to the translation hypotheses, after a number of hypotheses are selected for consideration in a next iteration of the beam search, to generate a source code output in the second programming language.
12 . A system for translation, comprising:
a hardware processor; and
a memory that stores a computer program which, when executed by the hardware processor, causes the hardware processor to:
perform a beam search of translation hypotheses for input source code in a first programming language to a second programming language;
extract a constraint from the input source code; and
apply the constraint to the translation hypotheses, after a number of hypotheses are selected for consideration in a next iteration of the beam search, to generate a source code output in the second programming language.
13 . The system of claim 12 , wherein the constraint filters a set of complete hypotheses generated by the search.
14 . The system of claim 12 , wherein the constraint limits branches taken by the search according to the constraint.
15 . The system of claim 12 , wherein the beam search uses a translation model to generate the translation hypotheses.
16 . The system of claim 15 , wherein the constraint is applied before a number of hypotheses are selected for consideration in a next iteration of the beam search, and the number of hypotheses is determined by a beam width.
17 . The system of claim 15 , wherein the number of hypotheses is a beam width, reduced by a number of pruned hypotheses.
18 . The system of claim 17 , wherein a number of additional hypotheses are selected responsive to the number of pruned hypotheses exceeding a threshold value.
19 . The system of claim 15 , wherein the constraint is applied before a number of hypotheses are selected for consideration in a next iteration of the beam search, such that the number of hypotheses is maintained at a beam width.
20 . The system of claim 12 , wherein the constraint is selected from the group consisting of a number of variables in the output source code being the same as a number of variables in the input source code, names of variables in the output source code being the same as variables in the input source code, and data types of variables in the output source code being the same as variables in the input source code.