Brain.js is a JavaScript library for deploying a neural network in the browser or on Node.js. It uses a computer’s GPU (graphics processing unit) for calculations, or pure JavaScript when GPU isn’t available.
The lead developer of Brain.js is Robert Plummer, by day a full-stack engineer at iFIT. I reached out to him to find out more about Brain.js, including its beginnings, what it’s currently used for, and plans for the future.
As the name of Plummer’s project suggests, neural networks are computer systems that mimic how a biological brain works. A neural network is made up of connected nodes, loosely modeled on the neurons in a brain. Also like brains, neural networks need to be trained on data that is input into the system — a type of machine learning known as deep learning.
The key benefit of Brain.js is that it uses the world’s most popular web programming language, JavaScript. Also, according to an IBM developer tutorial, a neural network-powered app built with Brain.js “can be created with surprisingly little code.”
So what are the use cases for neural networks in a browser? According to Plummer, they are “unlimited,” but he gave a couple of examples from the Brain.js community. “I’ve seen people use it for managing seeds in a farming community,” he said, “and I’ve seen people use it for predicting stock market prices or weather within a location.”
He cautioned that at this stage, data fed into a Brain.js-powered web app requires supervised training. Unsupervised learning and reinforcement learning have not yet made it into the library, he said.
I asked how Brain.js compares to programming neural networks in Python or R, two languages commonly used in machine learning. Does JavaScript have the same level of power?
Plummer confirmed that using JavaScript is “just as powerful,” but he noted that “there is some overhead” to using the number-crunching parts. However, he said, “we offer the capability of using the GPU, which is GLSL [OpenGL Shading Language], which is a subset of C++.” This is “very similar” to working with Python or R, he added.
Although Plummer is the lead developer of Brain.js and has been working on it since 2016, the library has its roots in a previous project created by Heather Arthur, called brain. Arthur had described her project as “a simple neural network library.” However, she stopped maintaining it around 2014. After some discussion among the brain community, Plummer cloned Arthur’s project in January 2016 — and thus Brain.js was born.
As an aside, Heather Arthur wrote a blog post in 2017 explaining why she abandoned not just brain, but all of her GitHub projects. It turns out that each one was a “personal side project” and she found it difficult to maintain them all, since she had no “organizational support.” There was “a massive amount of tedious effort,” she continued, which led her to declare “bankruptcy on GitHub.”
Perhaps Arthur was ahead of her time with brain, but fortunately, her work inspired a group of JavaScript developers (Plummer among them) to continue — and extend — the project.
As for why Plummer became interested in brain and wanted to continue it, he told me that until Arthur’s project, he’d “never seen neural nets developed as simply and understandably.”
“JavaScript is a beautiful language,” he said. “It’s very simple, and there’s no reason that it can’t be very performant. There are some things that are still kind of holding it back, but that’s slowly but surely moving forward.”
It’s been six and a half years since Plummer started Brain.js, so I asked how different is it now from Arthur’s original project?
“In its original incarnation, it was just a feedforward neural net with the ability to output that as a single algorithm — a single trained neural net within basically one big long, long, line of code,” he replied. A feedforward neural net is a type of neural net where node connections do not form a loop.
“Since then,” continued Plummer, “we’ve added GPU as well. So you can write in JavaScript and that compiles to GLSL (or a subset of C++); it took two and a half to three years to make that work.”
Ironically, Plummer seems to have a similar problem to Arthur in terms of maintaining the Brain.js project — a lack of support. He’s the only active developer on the project and has to work on it outside the hours he spends on his day job.
“I’m quite busy with my day job and I don’t get to it as frequently as possible,” Plummer said, regarding work on Brain.js. “I’ve had developers come and go over the years. And I reach out to them, you know […] but for the most part, it’s just me.”
Plummer spends what little spare time he has mostly fixing bugs. But he’s also started working on “reinforcement neural nets, strongly typed,” which is a class of algorithms that aims to improve automatically based on experience.
A lot of deep learning projects will continue to use the likes of TensorFlow, or big company platforms like IBM Watson Studio or Google Cloud AI Platform. But if you’re a web developer wanting to try out deep learning inside the browser or on Node.js, then Brain.js is worth checking out. Especially if you have seeds to manage or stock prices to predict.
Feature image via Shutterstock.