• Stars
    star
    1,507
  • Rank 29,887 (Top 0.7 %)
  • Language
    JavaScript
  • Created almost 9 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A neural network library built in JavaScript

Mind Logo

CircleCI

A flexible neural network library for Node.js and the browser. Check out a live demo of a movie recommendation engine built with Mind.

Features

  • Vectorized - uses a matrix implementation to process training data
  • Configurable - allows you to customize the network topology
  • Pluggable - download/upload minds that have already learned

Installation

$ yarn add node-mind

Usage

const Mind = require('node-mind');

/**
 * Letters.
 *
 * - Imagine these # and . represent black and white pixels.
 */

const a = character(
  '.#####.' +
  '#.....#' +
  '#.....#' +
  '#######' +
  '#.....#' +
  '#.....#' +
  '#.....#'
)

const b = character(
  '######.' +
  '#.....#' +
  '#.....#' +
  '######.' +
  '#.....#' +
  '#.....#' +
  '######.'
)

const c = character(
  '#######' +
  '#......' +
  '#......' +
  '#......' +
  '#......' +
  '#......' +
  '#######'
)

/**
 * Learn the letters A through C.
 */

const mind = new Mind({ activator: 'sigmoid' })
  .learn([
    { input: a, output: map('a') },
    { input: b, output: map('b') },
    { input: c, output: map('c') }
  ])

/**
 * Predict the letter C, even with a pixel off.
 */

const result = mind.predict(character(
  '#######' +
  '#......' +
  '#......' +
  '#......' +
  '#......' +
  '##.....' +
  '#######'
))

console.log(result) // ~ 0.5

/**
 * Turn the # into 1s and . into 0s.
 */

function character(string) {
  return string
    .trim()
    .split('')
    .map(integer)

  function integer(symbol) {
    if ('#' === symbol) return 1
    if ('.' === symbol) return 0
  }
}

/**
 * Map letter to a number.
 */

function map(letter) {
  if (letter === 'a') return [ 0.1 ]
  if (letter === 'b') return [ 0.3 ]
  if (letter === 'c') return [ 0.5 ]
  return 0
}

Plugins

Use plugins created by the Mind community to configure pre-trained networks that can go straight to making predictions.

Here's a cool example of the way you could use a hypothetical mind-ocr plugin:

const Mind = require('node-mind')
const ocr = require('mind-ocr')

const mind = Mind()
  .upload(ocr)
  .predict(
    '.#####.' +
    '#.....#' +
    '#.....#' +
    '#######' +
    '#.....#' +
    '#.....#' +
    '#.....#'
  )

To create a plugin, simply call download on your trained mind:

const Mind = require('node-mind')

const mind = Mind()
  .learn([
    { input: [0, 0], output: [ 0 ] },
    { input: [0, 1], output: [ 1 ] },
    { input: [1, 0], output: [ 1 ] },
    { input: [1, 1], output: [ 0 ] }
  ]);

const xor = mind.download()

Here's a list of available plugins:

API

Mind(options)

Create a new instance of Mind that can learn to make predictions.

The available options are:

  • activator: the activation function to use, sigmoid or htan
  • learningRate: the speed at which the network will learn
  • hiddenUnits: the number of units in the hidden layer/s
  • iterations: the number of iterations to run
  • hiddenLayers: the number of hidden layers

.learn()

Learn from training data:

mind.learn([
  { input: [0, 0], output: [ 0 ] },
  { input: [0, 1], output: [ 1 ] },
  { input: [1, 0], output: [ 1 ] },
  { input: [1, 1], output: [ 0 ] }
])

.predict()

Make a prediction:

mind.predict([0, 1])

.download()

Download a mind:

const xor = mind.download()

.upload()

Upload a mind:

mind.upload(xor)

.on()

Listen for the 'data' event, which is fired with each iteration:

mind.on('data', (iteration, errors, results) => {
  // ...
})

Releasing / Publishing

CircleCI will handle publishing to npm. To cut a new release, just do:

$ git changelog --tag <version>
$ vim package.json # enter <version>
$ git release <version>

Where <version> follows the semver spec.

Note

If you're interested in learning more, I wrote a blog post on how to build your own neural network:

Also, here are some fantastic libraries you can check out:

License

MIT


stevenmiller888.github.io Β Β·Β  GitHub @stevenmiller888 Β Β·Β  Twitter @stevenmiller888

More Repositories

1

intruder

Wi-Fi network cracking in Node.js
JavaScript
290
star
2

go-mind

A neural network library built in Go
Go
168
star
3

matter

A tiny collection of UI components.
JavaScript
133
star
4

ts-mysql-parser

A standalone, grammar-complete MySQL parser.
TypeScript
67
star
5

matter-react

React-ified version of Matter
JavaScript
44
star
6

gity

Git wrapper for Node
JavaScript
43
star
7

ts-mysql-analyzer

A MySQL query analyzer.
TypeScript
23
star
8

git-auto

Git workflow automation
JavaScript
17
star
9

scanner

A cross-platform scanner for wireless networks
JavaScript
13
star
10

superboost

A chrome extension that superboosts your visibility on OkCupid
JavaScript
12
star
11

ts-mysql-autocomplete

An autocomplete engine for MySQL queries.
TypeScript
11
star
12

black-scholes

A Black-Scholes implementation
JavaScript
10
star
13

keku

A template for Koa + Deku applications
JavaScript
10
star
14

matrix

A tiny matrix library
JavaScript
9
star
15

fault

A tool for generating fault tree analyses
JavaScript
7
star
16

component-path

Generate the absolute CSS path to a DOM element
JavaScript
7
star
17

23andme

A JavaScript client for communicating with the 23andMe API.
JavaScript
7
star
18

ts-mysql-schema

A schema extractor for MySQL.
TypeScript
7
star
19

koa-analytics

Analytics for Koa
JavaScript
6
star
20

mind-xor

An XOR plugin for Mind
JavaScript
4
star
21

sniffer

A cross-platform network sniffer
JavaScript
4
star
22

node-mapreduce

A map-reduce algorithm for Node
JavaScript
3
star
23

deku-math

A Deku component for mathematical notation
CSS
3
star
24

deku-performance

Performance monitoring component
JavaScript
2
star
25

bash-summary

Monitor your tools
Shell
2
star
26

sample

Generate a random sample
JavaScript
2
star
27

sigmoid

The sigmoid function
JavaScript
2
star
28

deku-chart

Chart component for Deku
JavaScript
2
star
29

koa-stats

Gather stats for your Koa app
JavaScript
1
star
30

ts-mysql-uri

Parse a MySQL connection URI.
TypeScript
1
star
31

htan

Hyperbolic tangent function
JavaScript
1
star
32

deku-animation

A Deku animation component.
JavaScript
1
star
33

mind-currency

A currency transform for Mind
JavaScript
1
star
34

focus

A chrome extension to countdown the years until your death
JavaScript
1
star
35

khaos-deku-component

Build Deku components quickly
Makefile
1
star