The Magic of Machine Learning: How Computers Can Write Code by Themselves

Cover Image for The Magic of Machine Learning: How Computers Can Write Code by Themselves
Xander McKenzie
Xander McKenzie

Have you ever wondered if a computer can write code by itself? This may sound like science fiction, but it is actually possible with machine learning (ML). ML is a branch of artificial intelligence that allows computers to learn from data and perform tasks that normally require human intelligence. One of these tasks is code generation, which means creating code of programming languages for making software.

A recent review published in IEEE Access, a scientific journal, gives a detailed overview of the latest research on code generation using ML. The review covers 37 studies that use different ML methods, data sources, and applications for code generation. The review also discusses the benefits and challenges of this field.

The review explains that there are three main ways of using ML for code generation: description-to-code, code-to-description, and code-to-code. Description-to-code is when a computer can generate code from natural language descriptions, such as what the user wants the software to do. Code-to-description is when a computer can generate natural language descriptions from code, such as explaining what the code does or how to use it. Code-to-code is when a computer can generate code from existing code, such as fixing errors, improving quality, or changing languages.

The review analyzes the ML methods used for code generation in the selected studies. The most popular methods are recurrent neural networks (RNNs), transformers, and convolutional neural networks (CNNs). RNNs are good at capturing the order and structure of code, but they have some drawbacks such as forgetting information or being slow. Transformers are more powerful and efficient than RNNs, but they require a lot of data and computing power. CNNs are fast and effective at extracting features in code, but they have limited ability to capture long-term relationships.

The review also examines the data sources used for training and testing the ML methods for code generation. The data sources vary in size, quality, and domain. Some data sources are synthetic, meaning they are created by rules or existing methods. Synthetic data sources are easy to obtain and control, but they may not reflect the real-world complexity and diversity of code. Other data sources are real-world, meaning they are collected from open-source websites or online platforms. Real-world data sources are more realistic and challenging, but they may be noisy, inconsistent, or incomplete.

The review evaluates the results of the ML methods for code generation based on different measures and criteria. The measures include accuracy, precision, recall, F1-score, BLEU score, ROUGE score, perplexity, and human evaluation. The criteria include functionality, readability, maintainability, reusability, and generalizability of the generated code. The review finds that the results vary depending on the application, method, data source, and measure used. The review also identifies some limitations and challenges of the current research on code generation using ML.

The review concludes with some suggestions for future work on code generation using ML. The suggestions include improving the quality and diversity of the data sources; developing more robust and interpretable ML methods; exploring more applications and domains for code generation; and addressing ethical and social issues related to automatic software development.

E. Dehaerne, B. Dey, S. Halder, S. De Gendt and W. Meert, "Code Generation Using Machine Learning: A Systematic Review," in IEEE Access, vol. 10, pp. 82434-82455, 2022, doi: 10.1109/ACCESS.2022.3196347.