Brain.js: Making the Library Robust and Simple for beginners

Created on 2 Oct 2017  路  5Comments  路  Source: BrainJS/brain.js

User story:
Akash is a small kid and wanted to play around with some neural networks, kids these days like to be geeky. But he finds all the libraries to be quite hard to use since they talk about math jargon all over the place and a single function is asking him to give a thousand inputs. That's not cool.
Akash want's to get his ideas running on a Neural Network as soon as possible without the need to understand the complex math behind it.

The user story might seem a bit ridiculous, but I think will open up a number of possibilities to beginners.

My proposal is to build the library having a fine granular control.
Parallelly building a module inside the library that gives us access to preconfigured models that just work out of the box.

2 - Working <= 5

Most helpful comment

This issue is really important to me, so I want to expound upon where the api is headed. And not only do I was to make sure the library is easy, it will be GPU accelerated, and enterprise ready.

The actual api for FeedForward nets is currently implemented as (for v2, not yet released):

const net = new FeedForward({
  inputLayer: 
  hiddenLayers: [],
  outputLayer:
});

And the "twin" recurrent api (planned, not yet built):

const net = new Recurrent({
  inputLayer: 
  hiddenLayers: [],
  outputLayer:
});

Note: See anything related between them?

Now, we can easily have some sort of shortcut to generate the following, but here is the verbose means of creating a deep (three layers) feed forward neural network.

import { FeedForward, layer } from 'brian.js';
const net = new FeedForward({
  inputLayer: () => layer.input(settings)
  hiddenLayers: [
    input => layer.feedForward(settings, input),
    input => layer.feedForward(settings, input),
    input => layer.feedForward(settings, input)
  ],
  outputLayer: input => layer.output(settings, input)
});

net.train([
  {input: [0, 0], output: [0]},
  {input: [0, 1], output: [1]},
  {input: [1, 0], output: [1]},
  {input: [1, 1], output: [0]}
]);
net.run([0,0]); // -> outputs `[0]`

And the planned recurrent:

import { Recurrent, layer } from 'brian.js';
const net = new Recurrent({
  inputLayer: () => layer.input(settings)
  hiddenLayers: [
    (input, recurrentInput) => layer.recurrent(settings, input, recurrentInput),
    (input, recurrentInput) => layer.gru(settings, input, recurrentInput),
    (input, recurrentInput) => layer.lstm(settings, input, recurrentInput)
  ],
  outputLayer: (input, recurrentInput) => layer.output(settings, input, recurrentInput)
});

net.train([
  {input: [0, 0], output: [0]},
  {input: [0, 1], output: [1]},
  {input: [1, 0], output: [1]},
  {input: [1, 1], output: [0]}
]);
net.predict([0,0]); // -> outputs `[0]`

More to come.

All 5 comments

It is like you are in my head!: https://github.com/BrainJS/brain.js/issues/96#issuecomment-332374644

Same thing for General neural and deep nets.

new brain.NeuralNetowrk({
  inputLayer:
  hiddenLayers: [],
  outputLayer: 
});

This would be an invaluable addition to starters

This issue is really important to me, so I want to expound upon where the api is headed. And not only do I was to make sure the library is easy, it will be GPU accelerated, and enterprise ready.

The actual api for FeedForward nets is currently implemented as (for v2, not yet released):

const net = new FeedForward({
  inputLayer: 
  hiddenLayers: [],
  outputLayer:
});

And the "twin" recurrent api (planned, not yet built):

const net = new Recurrent({
  inputLayer: 
  hiddenLayers: [],
  outputLayer:
});

Note: See anything related between them?

Now, we can easily have some sort of shortcut to generate the following, but here is the verbose means of creating a deep (three layers) feed forward neural network.

import { FeedForward, layer } from 'brian.js';
const net = new FeedForward({
  inputLayer: () => layer.input(settings)
  hiddenLayers: [
    input => layer.feedForward(settings, input),
    input => layer.feedForward(settings, input),
    input => layer.feedForward(settings, input)
  ],
  outputLayer: input => layer.output(settings, input)
});

net.train([
  {input: [0, 0], output: [0]},
  {input: [0, 1], output: [1]},
  {input: [1, 0], output: [1]},
  {input: [1, 1], output: [0]}
]);
net.run([0,0]); // -> outputs `[0]`

And the planned recurrent:

import { Recurrent, layer } from 'brian.js';
const net = new Recurrent({
  inputLayer: () => layer.input(settings)
  hiddenLayers: [
    (input, recurrentInput) => layer.recurrent(settings, input, recurrentInput),
    (input, recurrentInput) => layer.gru(settings, input, recurrentInput),
    (input, recurrentInput) => layer.lstm(settings, input, recurrentInput)
  ],
  outputLayer: (input, recurrentInput) => layer.output(settings, input, recurrentInput)
});

net.train([
  {input: [0, 0], output: [0]},
  {input: [0, 1], output: [1]},
  {input: [1, 0], output: [1]},
  {input: [1, 1], output: [0]}
]);
net.predict([0,0]); // -> outputs `[0]`

More to come.

I found the scrimba course by @robertleeplummerjr (thank you!) was extremely helpful when learning brain.js. Updating the course and adding more examples of the new and improved features in V2 would be fantastic 馃檪

Of course, an easy-to-follow tutorial is only possible with a solid API foundation, like the one in the works 馃槈

Was this page helpful?
0 / 5 - 0 ratings

Related issues

omer54463 picture omer54463  路  6Comments

shopsoy picture shopsoy  路  3Comments

nezzard picture nezzard  路  5Comments

dan-ryan picture dan-ryan  路  4Comments

tyt34 picture tyt34  路  5Comments