This is a fairly remarkable project which offers a library of Neural Networks written in JavaScript.
brain.js
GPU accelerated Neural networks in JavaScript for Browsers and Node.js
About
brain.js
is a GPU accelerated library for Neural Networks written in JavaScript.
π‘ This is a continuation of the harthur/brain, which is not maintained anymore. More info
Table of Contents
- Installation and Usage
- Examples
- Training
- Methods
- Failing
- JSON
- Standalone Function
- Options
- Streams
- Utilities
- Neural Network Types
Installation and Usage
NPM
If you can install brain.js
with npm:
npm install brain.js
CDN
<script src="//unpkg.com/brain.js"></script>
Download
Download the latest brain.js for browser
Installation note
β¦Here's an example showcasing how to approximate the XOR function from the README:
// provide optional config object (or undefined). Defaults shown.
const config = {
binaryThresh: 0.5,
hiddenLayers: [3], // array of ints for the sizes of the hidden layers in the network
activation: 'sigmoid' // supported activation types: ['sigmoid', 'relu', 'leaky-relu', 'tanh'],
leakyReluAlpha: 0.01 // supported for activation type 'leaky-relu'
};
// create a simple feed forward neural network with backpropagation
const net = new brain.NeuralNetwork(config);
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]
It's actively maintained. Definitely worth checking out.
This post is part of the new GitHunt DEV tag. Follow it out for more like this.
Top comments (8)
I love the GitHunt tag and the projects you've been posting, Ben. This has been on my list of libraries I need to play with for a long time. I like Martin's spam filter project idea; anyone else have any other projects or ideas for what to do with this that I can draw inspiration from?
I love this one. Used it a while back in a side project to filter spammy chat messages and it worked like a charm.
It's also one of the few JS ML libraries that are actively maintained.
A big "competitor" to brain.js is TensorFlow.js, which is backed by Google and Tensorflow in general is very widely used. It was exciting to see Tensorflow coming to JavaScript this year.
Great to hear you had success on spam filtering. That's a notoriously difficult problem without tech like this, but even with neural networks, I don't hear a lot of practical "this worked and how" examples.
If you wanted to write a DEV post on that experience, I think it would go over really well.
I built a sentence matching system using this library. It matched the words and characters in an input sentence against a database to make a best guess match. The standardised sentence version in the database was linked to properties we used for processing a response.
The response was a set of calculations rather than a chat app.
The library was useful in 3 ways:
Wow, looks great, thanks for sharing! I'll see if I can try it out soon!
does the speed of computation comparable with c tensorflow library?
Love this. Congrats!
If you're running in NodeJS anyway, I'd expect you're better of with some kind of wrapper around native TensorFlow bindings than running a neural network in pure JS.