Live data from Hacker News

Deep learning to translate between programming languages

ai.facebook.com

11–20 of 81 posts

Re: Deep learning to translate between programming languages

#11

To imagine future compilers may just one day be AI powered is mind boggling to me.

I've heard that LLVM uses neural networks to drive the register allocator. I don't know how well it works, but it's a pretty cool idea.

I listened to a talk about this at pldi, wrt the auto-vectorizer. Given a piece of of sequential code, there are many ways to auto-vectorize it, and finding the fastest one is computationally complex. The current auto-vectorizer uses a faster algorithm that won't always generate the fastest possible vectorization. When they threw a neural network at it, they found it sometimes generated faster code than the slow 'optimal' algorithm, because the neural net was able to take into account factors the humans hadn't thought to in their model.

Re: Deep learning to translate between programming languages

#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 concurrency, there is very little similar code at all to learn from.

Re: Deep learning to translate between programming languages

#13
I think that while the current technology could do such a thing, the current data absolutely cannot. Think of the parallel with language translations. We have tons of books that are all painstakingly translated from language to another by talented translators who even try to persevere idioms of each language, television and other media as well. I don't think there are even any copies out there of a faithful language translation in programming space as there is in language space

Re: Deep learning to translate between programming languages

#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?

Re: Deep learning to translate between programming languages

#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 the right tool. The problem is the variations in the problem space: generic programs, need for idiomatic code, renewed design and lack of human insight and ownership. Sure for an easy and specialized solution, this will work and may be helpful as a one-off. That is, if one just wants a straight port and test alot.

Re: Deep learning to translate between programming languages

#17

I can't imagine this working out for producing idiomatic code, especially between very divergent languages like Haskell and C++. Their example is almost straight syntactic replacement, not very impressive. And their real-world use-case is for migrating COBOL projects to python??

Facebook as a company do not believe in ever rewriting large code bases. You can view lots of their open source/technical achievements as out growths of this belief: - 2004, write PHP as it's fastest for now

- 2008: PHP is too slow, compile it to C++

- 2011: C++ is too slow, write a VM and compile to assesmbly

- 2012: PHP's type system sucks, write a better typer in OCaml (Hack)

- They have done much the same for Javascript and Python (look at all the typing tools provided by Instagram).

This stuff is just an outgrowth of their deep deep belief in writing code to handle the crazy amount of code they already have.

Re: Deep learning to translate between programming languages

#18

I can't imagine this working out for producing idiomatic code, especially between very divergent languages like Haskell and C++. Their example is almost straight syntactic replacement, not very impressive. And their real-world use-case is for migrating COBOL projects to python??

Facebook as a company do not believe in ever rewriting large code bases. You can view lots of their open source/technical achievements as out growths of this belief: - 2004, write PHP as it's fastest for now - 2008: PHP is too slow, compile it to C++ - 2011: C++ is too slow, write a VM and compile to assesmbly - 2012: PHP's type system sucks, write a better typer in OCaml (Hack) - They have done much the same for Jav…

How well does that really work out? It seems like that would aggregate a lot of cruft, or are there ways around that?

Re: Deep learning to translate between programming languages

#19

I can't imagine this working out for producing idiomatic code, especially between very divergent languages like Haskell and C++. Their example is almost straight syntactic replacement, not very impressive. And their real-world use-case is for migrating COBOL projects to python??

To be fair, there's a great use case for migrating COBOL to python. But I don't think banks would trust an automatic conversion done using ML...

Re: Deep learning to translate between programming languages

#20
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…

And it's also a quite nonsensical use of ML technology, to be honest. Neural nets are good for problem domains with fuzzy definitions of right and wrong as you find them in the physical world out there. Is this a tiger or a rock? Is this food or poison? Should I walk around this pond or swim through it? That's what the human brain is good at handling and neural nets are trying to approximate that.

Programming languages, on the other hand, are domains that are entirely man-made. We have created the rules, they are known in its entirety (in contrast to knowing all objects over there in the shade below the tree), and they are optimized to be so precise that they can be followed mechanically by a comparatively simple machine. Sure there are a few "undefined" corners but that's not because we don't understand them but because they are deliberately left open. Even they are precisely defined. So, with two precise definitions of semantics for two programming languages, it should be possible to build a translation based on those rules. Inherently, this is not an "empirical" endeavour, it's a logical/mathematical well-defined one.

Using neural nets for this is using the wrong hammer for the job. It's like using them for deriving the implementation of a sorting algorithm or to find the first 100k digits of pi. It just does not make sense.

And I'm not talking about "idiomatic" translations. That's a less well-defined domain an maybe that would be more suitable, but the post explicitly excludes this kind of thing. In principle, without providing examples of idiomatic style to the learning machinery, this can't ever work.

Post reply on HN