Live data from Hacker News

Deep learning to translate between programming languages

ai.facebook.com

61–70 of 81 posts

Re: Deep learning to translate between programming languages

#61
post #33

Earlier quoted context omitted.

Yeah I was thinking it might be better to use something like LLVM IR as the “data structure” and then train deep nets to go $(LANG) => IR and then IR => $(LANG), trained with a lot of idiomatic well written code for each Lang, then the nets might be able to glean the intent more than implementation details. Not sure though, I’m not an expert in LLVM IR, so I’m not sure how feasible that is...

The issue is that LANG -> IR is a lossy transform: some constructs are lost, some language specific optimization passes could be applied, etc. Going from LANG1 -> LANG2 starts with more information, so it could in theory work better.

It would be interesting to see what neural translation systems (in general, not just for code) use as an implicit internal IR.

Re: Deep learning to translate between programming languages

#62
post #16

This sounds more impressive than it is. I kept an auto-translation going for quite a while from C# to Go just by creating some bash scripts. These languages are so similar, that while not idiomatic, you can be up and running with quite few rules and some simplifications to the original code. While I believe this is a good arena for algorithms to provide solution, I'm sceptical that ML in its current incarnations is t…

I have seen some ML methods that learn explicit structural mappings [1][2]. I think ML is great when used as such. Even RL can work, because it operates over discrete spaces.

But casting any problem with a discrete correct answer into floating point calculations that mimic probability is a bad idea.

[1] : Learning to Compose Neural Networks for Question Answering

[2] : Inferring and Executing Programs for Visual Reasoning

Re: Deep learning to translate between programming languages

#65
post #33

Earlier quoted context omitted.

Yeah I was thinking it might be better to use something like LLVM IR as the “data structure” and then train deep nets to go $(LANG) => IR and then IR => $(LANG), trained with a lot of idiomatic well written code for each Lang, then the nets might be able to glean the intent more than implementation details. Not sure though, I’m not an expert in LLVM IR, so I’m not sure how feasible that is...

The issue is that LANG -> IR is a lossy transform: some constructs are lost, some language specific optimization passes could be applied, etc. Going from LANG1 -> LANG2 starts with more information, so it could in theory work better.

It's lossy, the inverse is not well defined. But you could try to train a NN on reconstructing plausible (idiomatic) inputs leading to the current IR...

Re: Deep learning to translate between programming languages

#66
post #55

Earlier quoted context omitted.

You will need to create common library for all these languages, then write all your programs using your own libraries only.

I don't get why? The AST can be parsed by any single language. Haskell is particularly well-suited for writing parsers.

I believe the point is that you can have perfect syntactic compatibility, but that means nothing when your program calls boost::asio or a Common Lisp defmethod and you want to interpret it as Haskell.

The only way this could work is if you write the whole stdlib in your AST system.

Of course, this still won't mean your lazy Haskell program works as an eager C program. Language semantics are too different, even between similar languages, you'll ALWAYS hit corner cases on anything more than a toy program. Even if you translate C# to Java. Well, maybe C to C++ will work decently, as few programs use the diverging features.

Re: Deep learning to translate between programming languages

#67
post #16

This sounds more impressive than it is. I kept an auto-translation going for quite a while from C# to Go just by creating some bash scripts. These languages are so similar, that while not idiomatic, you can be up and running with quite few rules and some simplifications to the original code. While I believe this is a good arena for algorithms to provide solution, I'm sceptical that ML in its current incarnations is t…

How do you handle generics? Go doesn’t have them, right?

C# has an open source compiler (Rosyln) with an API that exposes lot of information, so for advanced needs there is this road too.

Re: Deep learning to translate between programming languages

#68
post #14
post #12

Even if it works, which I doubt, the maintenance question is more important than just porting. Porting is rarely done just because there is a new modern language. Writing a compiler/transcoder is likely easier and safer, guaranteed to work. I wonder what the deep learning would do with concurrent code and differences in the memory models of the languages. The part is rather hard for experts in both languages and conc…

It seems like you could maybe go through machine code as an intermediary?

That would only help if you are willing to translate all of the libraries the code uses. Otherwise, transforming a call to C's `qsort` to Java's `Arrays.Sort` is unlikely to have the desired effect.

Re: Deep learning to translate between programming languages

#70

Earlier quoted context omitted.

I don't get why? The AST can be parsed by any single language. Haskell is particularly well-suited for writing parsers.

I believe the point is that you can have perfect syntactic compatibility, but that means nothing when your program calls boost::asio or a Common Lisp defmethod and you want to interpret it as Haskell. The only way this could work is if you write the whole stdlib in your AST system. Of course, this still won't mean your lazy Haskell program works as an eager C program. Language semantics are too different, even betwee…

I see, thank you.
Post reply on HN