Brain.js is a Neural Networks In JavaScript.
About
Brain.js is a GPU accelerated library for Neural Networks written in JavaScript. The source code is available on GitHub. It is a continuation of the harthur/brain, which is not maintained anymore.
A full introduction is available as the project's README.md, and recommended tutorials are available on the project's Github Wiki.
Example
Here is an example of creating, training, and applying a model which replicates an XOR function created with Brain.js.
// create a simple feed forward neural network with backpropagation
const net = new brain.NeuralNetwork();
net.train([
{ input: [0, 0], output: [0] },
{ input: [0, 1], output: [1] },
{ input: [1, 0], output: [1] },
{ input: [1, 1], output: [0] },
]);
const output = net.run([1, 0]); // [0.987]
Once initiated and trained, a model created with Brain.js can be exported as a zero-dependency function in 100% ES6 with net.toFunction()
, as explained here.