Microsoft Has Developed an AI That Can Find and Fix Bugs in Code


Writing code is only the first step in creating something. Combing through your code for bugs and fixing them is time-consuming and often takes longer than anticipated, but is an essential step nonetheless.

If only there was a way to automatically fix bugs that goes beyond syntax errors and truly understands the intentions behind your code.

Recently, Microsoft developed an AI capable of detecting and fixing bugs in code using deep learning. But how did this piece of revolutionary tech come to exist, and how does it work?

What Is BugLab, and How Does It Work?

BugLab is an artificial intelligence Python implementation that hunts for and fixes bugs within code. It was developed by Miltos Alamanis and Marc Brockschmidt, two researchers at Microsoft Research. They managed to overcome the lack of labeled data often used in machine learning by resorting to self-supervised learning and allowing BugLab to train itself through a “hide-and-seek” game with lines of code.

BugLab was trained using two computing models; one that hides bugs within correct snippets of code, and another that seeks and corrects the bugs. Both models continuously learn from each other. Over time, the bug selector becomes better at hiding bugs in the code, and the detector becomes better at catching and fixing them.

Understanding the Code With BugLab

The majority of bugs that BugLab AI is trained to detect and fix don't result in logical errors but are only wrong as a result of the general context of the code. Understanding the developer's intent is essential to finding these bugs.

Treating snippets of code the same way as processing natural languages yields suboptimal results. It's still difficult for AI to understand the relationship between different statements when they’re split into individual tokens.

Instead, BugLab looks at the code as a whole. That way, each syntax, expression, symbol, and identifier are represented as points in a graph, allowing the AI to “understand” the connection and relationship between various nodes.

Neural network architectures are then used to train the debugging AI. They’re able to pull in insights from the rich structure of the code graph and provide reasons for each node’s relationship with the others.

Does BugLab Work on Real-Life Code?

It’s important to note that BugLab isn’t a replacement for a skilled programmer. That's because complex bugs still aren’t within reach.

Microsoft’s aim with the AI is to detect and fix commonly occurring bugs such as incorrect Boolean operators, like the use of “or” instead of “and” and vice versa, in addition to inverted value comparisons and variable misuses.

According to Microsoft, the results are promising, as BugLab is able to detect and automatically fix around 26 percent of bugs in a piece of code. Still, a significant percentage of accuracy is still lost due to false positives and missed bugs.

Future Applications of Microsoft BugLab

Microsoft’s goal with BugLab is saving software developers time, often spent going over their code looking for the smallest of bugs.

While the AI debug model is still in a work-in-progress, it has the chance of finding and fixing bugs that range anywhere from inconvenient to catastrophic. But in a few years, you can expect BugLab to become a must in every developer’s toolkit, even if it’s not perfect.

The Exponential Evolution of Self-Teaching AI

The more time AI models like BugLab have to train on real-life examples, the better and more accurate results they’ll yield.

One of the most challenging hurdles Microsoft researchers faced while developing BugLab was employing a human understanding of code and intention into the tool. But now that that’s mostly solved, you can expect BugLab to get better with time.

About The Author