Is it possible to convert a code from one language to another using sequence to sequence programming. if not sequence to sequence, which algorithm can i use to do this?

  • $\begingroup$ Is it important that the converted code actually work? Are you trying to convert simple code snippets - in the raw language without libraries - or entire applications including core and maybe third-party libraries? $\endgroup$ Commented Oct 4, 2018 at 19:53
  • $\begingroup$ initially, i don't expect it to work. i want to be able to see a conversion which is atleast 20% correct $\endgroup$
    – rawwar
    Commented Oct 4, 2018 at 19:55
  • $\begingroup$ I just want to get started with some idea. $\endgroup$
    – rawwar
    Commented Oct 4, 2018 at 19:56
  • 1
    $\begingroup$ It is important to understand whether the end goal is to have working code, and what level it should operate at. If you expect inside the next 10 years to be converting more than a simple function with no dependencies, then that changes how you think about the problem. Your question is phrased as you want to have the end result, as opposed to learn the limits of a technique? $\endgroup$ Commented Oct 4, 2018 at 19:58

1 Answer 1


Yes, it is possible to convert code from one programming language to another using sequence-to-sequence neural networks. Sequence-to-sequence can learn to translate anything from anything if there are consistent patterns and enough paired examples.

However, it would not be efficient because the models would only indirectly learn the semantics (i.e., the meaning of the code) through the observed string literals (i.e., the characters that appear). It would be more efficient to map one observed sequence of string literals to semantics, then use the latent semantics representation to generate a new observed sequence of string literals.

There are a variety of ways of doing that depending on much you handicap yourself. If you give the model access to abstract syntax tree (AST), it becomes much easier. Then a tree-based Long Short-Term Memory (LSTM) could learn the semantic space.

Overall, this is a field of study that tries to build a Neural Network Transpiler.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.