Live data from Hacker News

Deep learning to translate between programming languages

ai.facebook.com

51–60 of 81 posts

Re: Deep learning to translate between programming languages

#51
post #28

Earlier quoted context omitted.

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 languag…

> "undefined" corners but that's not because we don't understand them but because they are deliberately left open. Even they are precisely defined. Not sure what language you are referring to, because this statement is very vague, but it's worth pointing out that undefined behavior in the C/C++ sense is absolutely not precisely defined. If a program executes undefined behavior in either of these languages, the entire…

> it's worth pointing out that undefined behavior in the C/C++ sense is absolutely not precisely defined.

I think OP means "it is precisely defined by the spec which actions result in undefined behaviour"

Re: Deep learning to translate between programming languages

#52
post #33
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…

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...

$(LANG) => IR can be done by LLVM itself...

And that conversion misses out important details like comments. Perhaps the ideal solution takes as input both the original code and the IR to generate output.

Re: Deep learning to translate between programming languages

#53
post #22

Earlier quoted context omitted.

I think the theory is a small subset of engineers can do work that speeds up the entire codebase for the rest of the engineers instead of spending time rewriting that entire code base and also retraining all of those engineers.

I think this is just it; at some point, code becomes a numbers game, an investment game. Rewriting their PHP codebase to, say, C++ would cost 10000 work-years, whereas creating HVVM cost 100 (random numbers) at a 1000% improvement in performance. Rewrites at that scale are really expensive and take forever, and by the time it's done they'll be running behind the facts already.

Yeah, exactly.

I like to think that Mark Zuckerberg read Joel's post and took it to heart.

But the pattern is super noticeable for FB, once you start paying attention.

Re: Deep learning to translate between programming languages

#54
post #26

Earlier quoted context omitted.

That'd be truly remarkable as in actual magic. Take this rather simple example: PointList interpolate(PointList sample_points, OrderedRealNumberList points_to_interpolate); This function can be auto-documented from its name and the names and types of its arguments alone. No ML required - simple pattern matching and LUTs will do. But then again, do you really need a detailed documentation in such case? Where a documen…

Guessing !! N,X, and F are probably related to NE,XE, and FE "E" means "error"? Maybe. IERR is an error flag. Idiomatic fortran there. Each of those variables will be defined later on, in the code. at least with a type (not required, but it is not 1960 anymore). In that declaration is where some comments would be. REAL*8 N ! Radius of the body in radians Point being that fortran is not hopelessly opaque. A subroutine…

> In that declaration is where some comments would be.

Admittedly, I haven't read a lot of Fortran code, but I have yet to see anybody who includes such comments. It wouldn't be so bad except also:

a) the only code I see in Fortran is numerics code, therefore written by mathematicians or other people who seem to believe that using more than one letter to describe a term is an admission of weakness

b) people write function names as if it costs $1000 per extra character

c) there often doesn't seem to be any introductory resources to the concepts that are being implemented that might let me discover what cryptic one-letter variable names might actually refer to

Re: Deep learning to translate between programming languages

#55

I've been thinking of a pandoc-like tool to translate between languages, i.e. a transpiler. You would need to write down the most general abstract syntax tree (AST) that encompasses all supported languages' features, as well as a way to read languages into this AST, and write the AST into languages. The cool thing about pandoc is the ability to transform the AST between the read and write. In the context of a transpi…

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

Re: Deep learning to translate between programming languages

#56
post #33
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…

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.

Re: Deep learning to translate between programming languages

#57
post #27

Earlier quoted context omitted.

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 languag…

So why does it work better than the commercially available tools at the moment as claimed in the article?

This article is a classic example of Facebook PR doing a wonderful job of selling the research and linked paper [1] claiming too much in the introduction. Please, please talk to actual researchers before you buy such claims.

If you go through the paper - you have to check the evaluation section to see how they measured their success. They used some programs from GeeksforGeeks to evaluate their approach. Problems on GeeksforGeeks do not represent the vast majority of programming tasks encountered in daily life. This is very much in contrast to the overarching claims presented in the introduction of the paper.

Second issue with the evaluation: they use BLEU scores to judge how good their translations are. BLEU makes sense for natural language translations (even that is widely debated in the NLP community these days). For a program there is no concept of an almost correct program (based on how things look similar), it is either correct or not. Eg. if I am asked to write a program to add two numbers and I write `x - y`, I am not almost correct, I am completely wrong. And in some ways that is what their model does, it optimizes for BLEU scores.

Third, the correctness of the programs are tested based on 10 random inputs. Are 10 random inputs enough to cover the entire input space that can be accepted by a program?

It is indeed a great advance in the application of ML technology, but it is nowhere close to the broader claims. One can even debate, ROI on time spent in gathering and curating data and then checking the correctness of translation from such system vs the ROI on writing rules for a rule based system since all programming languages are easily expressible that way.

[1]: https://arxiv.org/pdf/2006.03511.pdf

Re: Deep learning to translate between programming languages

#58
post #37
post #35

I see the potential to speed up code a lot. Say that you could translate Python to C++ or Nim that would speed up the program a lot. You could profile and translate select hot often used code paths. This has the potential too save a lot of energy by using more efficient programs.

That seems like a lot of effort when Julia is both high-level and efficient already.

Ok but I have 3 million lines of Python code, so that doesn't help me. I'm not gonna spend a year or two writing everything in Julia.

Re: Deep learning to translate between programming languages

#59

Cool magic trick but I fail to see anything useful coming out of it. I would not blindly rewrite code, rather see how it can be improved and maybe dig a bit in the existing functionality, clean it out, use the new language in my advantage... Also as a programmer your mental modal is completely out of sync, how do you work on such application suddenly now that its all in Python (coming from C++)? Or is this shipped to…

You would, but FB and some other companies are dealing with 20 years and millions of lines of code written by a small army of developers. If they decide to switch language and rebuild their services, just doing it manually will in all likelihood take longer and more people if they don't apply tricks like automatic conversion, because it takes more effort to rebuild than to build fresh due to multiple reasons.

But the options aren’t “manual” and “ai”. There is a third option of using classical static analysis and compiler techniques that have been around for decades to do transpilation and large scale refactors.

There are entire companies already build around this.

Re: Deep learning to translate between programming languages

#60
post #55

I've been thinking of a pandoc-like tool to translate between languages, i.e. a transpiler. You would need to write down the most general abstract syntax tree (AST) that encompasses all supported languages' features, as well as a way to read languages into this AST, and write the AST into languages. The cool thing about pandoc is the ability to transform the AST between the read and write. In the context of a transpi…

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.
Post reply on HN