HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
harthur
brain
JavaScript2010–2017
harthur / brain · Archived

brain

Simple feed-forward neural network in JavaScript

13Distinct people
13Mentions
0Explicit recommenders
8KGitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

Simple feed-forward neural network in JavaScript

GitHub

Where it is used

No documented product use was verified in the last source check.

What people are saying

No recommendation phrase was found in the indexed comments.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

No other repository is repeatedly linked in the same discussions.

This week on Hacker News

Nov 7–Nov 14 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/14/2026, 3:03:16 PM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by year13 dated mentions

Observed mentions: 2010-07-03 03:16:10 UTC to 2017-05-09 13:16:53 UTC.

012342010-01-01 00:00:00 UTC to 2011-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments20102011-01-01 00:00:00 UTC to 2012-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2012-01-01 00:00:00 UTC to 2013-01-01 00:00:00 UTC (exclusive): 1 mentions; 1 submissions, 0 comments2013-01-01 00:00:00 UTC to 2014-01-01 00:00:00 UTC (exclusive): 4 mentions; 0 submissions, 4 comments20132014-01-01 00:00:00 UTC to 2015-01-01 00:00:00 UTC (exclusive): 4 mentions; 1 submissions, 3 comments2015-01-01 00:00:00 UTC to 2016-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2016-01-01 00:00:00 UTC to 2017-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2017-01-01 00:00:00 UTC to 2018-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2017

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
20102010-01-01 00:00:00 UTC2011-01-01 00:00:00 UTC101
20112011-01-01 00:00:00 UTC2012-01-01 00:00:00 UTC000
20122012-01-01 00:00:00 UTC2013-01-01 00:00:00 UTC110
20132013-01-01 00:00:00 UTC2014-01-01 00:00:00 UTC404
20142014-01-01 00:00:00 UTC2015-01-01 00:00:00 UTC413
20152015-01-01 00:00:00 UTC2016-01-01 00:00:00 UTC101
20162016-01-01 00:00:00 UTC2017-01-01 00:00:00 UTC101
20172017-01-01 00:00:00 UTC2018-01-01 00:00:00 UTC101

From the project README

An excerpt from the repository, fetched Nov 13, 2026.

Read the project’s introduction
This project has reached the end of its development as a simple neural network library. Feel free to browse the code, but please use other JavaScript neural network libraries in development like brain.js and convnetjs. brain brain is a JavaScript neural network library. Here's an example of using it to approximate the XOR function: var 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]}]); var output = net.run([1, 0]); // [0.987] There's no reason to use a neural network to figure out XOR however (-: so here's a more involved, realistic example: Demo: training a neural network to recognize color contrast Using in node If you have node you can install with npm: npm install brain Using in the browser Download the latest brain.js. Training is computationally expensive, so you should try to train the network offline (or on a Worker) and use the toFunction() or toJSON() options to plug the pre-trained network in to your website. Training Use train() to train the network with an array of training data. The network has to be trained with all the data in bulk in one call to train(). The more training patterns, the longer it will probably take to train, but the better the network will be at classifiying new patterns. Data format Each training pattern should have an input and an output, both of which can be either an array of numbers from 0 to 1 or a hash of numbers from 0 to 1. For the color constrast demo it looks something like this: var net = new brain.NeuralNetwork(); net.train([{input: { r: 0.03, g: 0.7, b: 0.5 }, output: { black: 1 }}, {input: { r: 0.16, g: 0.09, b: 0.2 }, output: { white: 1 }}, {input: { r: 0.5, g: 0.5, b: 1.0 }, output: { white: 1 }}]); var output = net.run({ r: 1, g: 0.4, b: 0 }); // { white: 0.99, black: 0.002 } Options train() takes a hash of options as its second argument: net.train(data, { errorThresh: 0.005, // error threshold to reach iterations: 20000, // maximum training iterations log: true, // console.log() progress periodically logPeriod: 10, // number of iterations between logging learningRate: 0.3 // learning rate }) The network will train until the training error has gone below the threshold (default 0.005) or the max number of iterations (default 20000) has been reached, whichever comes first. By default training won't let you know how its doing until the end, but set log to true to get periodic updates on the current training error of the network. The training error should decrease every time. The updates will be printed to console. If you set log to a function, this function will be called with the updates instead of printing to the console. The learning rate is a parameter that influences how quickly the network trains. It's a number from 0 to 1. If the learning rate is close to 0 it will take longer to train. If the learning rate is closer to 1 it will train faster but it's in danger of training to a local minimum and performing badly on new data. The default learning rate is 0.3. Output The output of train() is a hash of information about how the training went: { error: 0.0039139985510105032, // training error iterations: 406 // training iterations } Failing If the network failed to train, the error will be above the error threshold. This could happen because the training data is too noisy (most likely), the network doesn't have enough hidden layers or nodes to handle the complexity of the data, or it hasn't trained for enough iterations. If the training error is still something huge like 0.4 after 20000 iterations, it's a good sign that the network can't make sense of the data you're giving it. JSON Serialize or load in the state of a trained network with JSON: var json = net.toJSON(); net.fromJSON(json); You can also get a custom standalone function from a trained network that acts just like run(): var run = net.toFunction(); var output = run({ r: 1, g: 0.4, b: 0 }); console.log(run.toString()); // copy and paste! no need to import brain.js Options NeuralNetwork() takes a hash of options: var net = new brain.NeuralNetwork({ hiddenLayers: [4], learningRate: 0.6 // global learning rate, useful when training using streams }); hiddenLayers Specify the number of hidden layers in the network and the size of each layer. For example, if you want two hidden layers - the first with 3 nodes and the second with 4 nodes, you'd give: hiddenLayers: [3, 4] By default brain uses one hidden layer with size proportionate to the size of the input array. Streams The network now has a WriteStream. You can train the network by using pipe() to send the training data to the network. Example Refer to stream-example.js for an example on how to train the network with a stream. Initialization To train the network using a stream you must first create the stream by calling net.createTrainStream() which takes the following options: floodCallback() - the callback function to re-populate the stream. This gets called on every training iteration. doneTrainingCallback(info) - the callback function to execute when the network is done training. The info param will contain a hash of information about how the training went: { error: 0.0039139985510105032, // training error iterations: 406 // training iterations } Transform Use a Transform to coerce the data into the correct format. You might also use a Transform stream to normalize your data on the fly.
Read the full README on GitHub

What Hacker News says

13 sources
Because it is one of the most popular and accessible programming languages. It can act as a gateway language for the millions of devs out there to try out NN's without the barrier of learning another language. Here are some other neural networks in JS: https://github.com/harthur/brain: Neural Networks in JS https://github.com/stevenmiller888/mind: a flexible neural network library https://github.com/cazala/synaptic: an architecture-free neural network library for node.js and the browser Sllightly off topic, but the Machine Learning department of the University of Tokyo has built a whole set of libraries for machine learning in Javascript: http://mil-tokyo.github.io/miljs.html
In How to Create a Neural Network in JavaScript [video]
One of the constraints we gave ourselves was that we wanted a fully in-browser solution, and transparently secure - no server-side backend, therefore no data protection issues. With that in mind, any training we did would have to be done by us. This limits our rubber ducking to exploits within our areas of expertise, but does mean that any memory / cpu consumption occurs on the client machine. It is potentially limited, but it is not a drain on our resources. Secondly, this was very much a toy made for the fun of it, so our "brain" is entirely hard coded. The language processing is very static, and very simple - so it converts "my problem" into "your problem" so that it can ask suitable questions while faking some intelligence, and there is a state machine that would allow us to make the wizard more flexible based on certain inputs. So to
Read the rest
answer your question specifically, if following the previous conventions, I would have tried to find some kind of word mapping to find categories from words in the sentence. For example, the question "I can't seem to get my stitching to look neat" or "my crochet hook keeps getting stuck" - it would notice the words "stitching" and "crochet" and decide the questions are related to haberdashery, so ask general questions from that domain (e.g. "can you unpick a little way and try again?", "are you keeping a consistent pressure on your thread / wool?") Of course, this isn't perfect. A couple of people have noted that the duck can encourage you to hack people up (we discourage this course of action and offer no warrantee for any advice the duck appears to present, especially to anyone psychotically inclined). But inter-personal issues are one realm in which this dumb regex-matching falls down frequently - it's very hard to work out that the problem is actually a person, without asking the user directly. That said, this is something that the state machine allows. Sorry if this isn't a very good answer. I've seen tools like https://github.com/harthur/brain or https://github.com/NaturalNode/natural and would love to attempt something with that in the future, but yes - my guess is that it would be slow to train, hard for us to cover all bases, and may not fit into the memory of the client's computer. Alternatively, one thing that we considered and ultimately rejected (mostly on UX grounds) was allowing users to send us their conversations so that we could improve them - again, a manual process, but one that possibly could be automated with a proper AI library and a pre-generated 'brain'! What can I say? That's what v2 is for :)
In Duckie: Rubber Ducking as a service

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.