News: 1591989008

  ARM Give a man a fire and he's warm for a day, but set fire to him and he's warm for the rest of his life (Terry Pratchett, Jingo)

Facebook boffins bake robo-code converter to take the pain out of shifting between C++, Java, Python

(2020/06/12)


Facebook researchers have applied recent advances they've made in the unsupervised machine translation of human languages to a source code conversion system.

In [1]a research paper recently distributed through ArXiv, boffins at the beleaguered ad biz describe a project called TransCoder.

TransCoder is a transpiler, also known as a transcompiler or source-to-source compiler. Various modern programming languages like Dart and TypeScript include transpilers that can convert source code in a different language.

TransCoder is intended for use with older languages like COBOL or Python 2 that don't have this facility built-in, or where source code has to be integrated into a codebase in a different language where there's no direct transpilation path.

One of the reasons for trying to build an automated code converter is that such work tends to be expensive. The paper points to the $750m and five years of time spent by the Commonwealth Bank of Australia to convert its platform from COBOL to Java.

A transpiler and subsequent tweaking could make such shifts faster and cheaper, it's supposed, though the involvement of Accenture and SAP in the bank platform project probably didn't help price-wise. Management fees don't pay themselves, you know.

Over the past few years, Facebook AI boffins have devised a way to use neural networks to do [2]unsupervised machine translation . Rather than feeding the system word pairs of text in, say, English and French, a neural network gets sentences from monolingual data sets in two different languages and maps them together in a data representation called a latent space. From this, the system can work out translation between the two tongues without supervision or data labeling.

Let the machine mind try

Marie-Anne Lachaux, Baptiste Rozière, Lowik Chanussot, and Guillaume Lample, part of a Facebook AI group based in France, have applied this approach to unsupervised training in TransCoder. Using open source code from GitHub projects, they've created a system that accurately translates functions between C++, Java, and Python.

Developers renew push to get rid of objectionable code terms to make 'the world a tiny bit more welcoming' [3]READ MORE

"TransCoder could help port a project from Python to C++," said Lachaux, Rozière, and Lample in an email to The Register . "It may make the code faster and also more maintainable since code written in strongly-typed languages can be easier to understand. However, TransCoder would not solve every issue around bad code quality."

They pointed to code duplication, bad variable and function names, and suboptimal algorithms as issues TransCoder would not address.

TransCoder, they said, is intended to be an assistive tool for developers and is still at an early stage of development. "Currently, TransCoder is only able to translate at function-level, and cannot translate entire projects," they said. "The generated functions and production code have to be tested; they are not guaranteed to be correct."

The researcher said machine language translation is now widely accepted, even among professional translators. They believe programmers will also adopt machine learning-based tools as they improve.

To test their system, they created a test set of 852 parallel functions and associated unit tests.

"Although never provided with parallel data, the model manages to translate functions with a high accuracy, and to properly align functions from the standard library across the three languages, outperforming rule-based and commercial baselines by a significant margin," the paper explains.

The baselines used for comparison came from j2py, a Java-to-Python translation framework, and Tangible Software Solutions, a commercial source code converter that turns C++ into Java. The paper claims TransCoder "significantly outperforms both baselines in terms of computational accuracy, with 74.8 per cent and 68.7 per cent in the C++ → Java and Java → Python directions, compared to 61 per cent and 38.3 per cent for the baselines."

Lachaux, Rozière, and Lample said TransCoder can help improve code performance by translating source code in Python, for example, into a language with less overhead that can be optimized by a compiler like C++ or Java.

"We believe the automatic translations would typically be on par with human translations in terms of computational performance," they said. "However, expert programmers could do more than just translate (e.g. improve the algorithm) or use some tricks to make the algorithm more efficient (e.g. bitwise operations on int instead of operations on boolean arrays) while our automatic translator would not."

They expect that TransCoder will be used to deal with legacy code by porting it to a more modern language. Facebook, they said, is one company among many that has legacy code and they're looking at ways its codebase could be improved through machine learning applications.

"We plan to release our source code and datasets," said Lachaux, Rozière, and Lample. "We also plan to release the best version of our model for people who do not have the infrastructure to retrain it. We hope this will encourage further research in this direction." ®

Sponsored: [4]Kubernetes: Your Hybrid Cloud Strategy



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

[2] https://engineering.fb.com/ai-research/unsupervised-machine-translation-a-novel-approach-to-provide-fast-accurate-translations-for-more-languages/

[3] https://www.theregister.com/2020/06/08/developers_renew_push_to_get/

[4] https://go.theregister.com/tl/1956/-8472/kubernetes-your-hybrid-cloud-strategy?td=wptl1956

Coversion costs?

martinusher

The way this is written implies that the $750 milliom spent converting a code base from COBOL to Java was merely line by line translating of the source. I don't have any knowledge of this project but based on my experience the transation would be taken as an opportunity to upgrade the systems and its functionality. That is, the 'conversion' was really a system rewrite with all the complexity in design, coding, integration and testing that would entail.

"faster and...more maintainable"

Mike Shepherd

TransCoder...could help port a project from Python to C++...It may make the code faster and also more maintainable since code written in strongly-typed languages can be easier to understand .

Get real. Anyone who's maintained human-written code will have experienced wanting to shake its author by the throat, because typical source code is of abysmal quality. We're a long way from any machine that will improve on that. So don't ask me to work on TransCode's output, because it will have to do a lot more than change x=2 to int x=2 (even if it gets that right) to compensate for the general mess with which it will likely start and to which it can only add.

As for speed, there has been very little code worth speeding up for the last 40 years or more. The overwhelming problem, then and still now, is how to write clear and reliable source that reflects the requirements accurately. Making code faster is appropriate in niche cases, which most of us need rarely to address.

Re: "faster and...more maintainable"

Def

I don't think I can name a single application I've ever used (or a lot I've worked on for that matter) that wouldn't have been better if they'd been faster.

Making code faster is only becoming a niche as higher level languages take more control away from the programmer, and as fewer and fewer programmers really understand the performance consequences of their choices and know how to optimise their code.

Re: "faster and...more maintainable"

RM Myers

Wow, two comments that I can both agree and disagree with, at the same time. Having designed and helped write a series of programs almost 40 years ago which saved over $300K per year in processing time, with probably less than $30K in programming time, I definitely disagree with the "no program in last 40 years comment". Plus, having been involved with systems that had thousands of users at my former employer, I can tell you performance can be critical. We had several large projects that were never implements because the systems were too slow.

At the same time, there were many times where performance was much less important than maintainability, both from a quality perspective and overall cost. When a limited number of management people are making long term billion dollar decisions based on reports and analysis from your system, being fast is much less important than being accurate. And senior management doesn't tend to like it when small changes take months to implement, so lack of maintainability can be career threatening.

YMMV

Based on language translation

HildyJ

It's one thing if you translate "I seem to be having this tremendous difficulty with my lifestyle", into a Vl'Hurgs and I it comes out as the most dreadful insult imaginable.

But if you're dealing with code, less than 100% accurate translation will cause errors which may be catastrophic and will be difficult to track down. Having a neural network do this instead of programmers just makes it faster to generate errors.

Can’t wait

Anonymous Coward

Looking forward to the logical endpoint of this work: a ML system which, shown images of a language manual and an ISA manual, generates a compiler.

My reason tells me that land cannot be sold - nothing can be sold but
such things as can be carried away. Black Hawk, (Saulk)