gitmyhub

brain.js

TypeScript ★ 15k updated 1y ago

🤖 GPU accelerated Neural networks in JavaScript for Browsers and Node.js

brain.js is a JavaScript neural network library for Node and the browser, with feed-forward, RNN, LSTM, and GRU types and optional GPU acceleration.

JavaScriptTypeScriptNode.jsWebGLheadless-glsetup: easycomplexity 2/5

brain.js is a JavaScript library for building and training neural networks, the kind of model that learns patterns from example data. It can run in a normal Node.js server or directly in a web browser, and it can use the graphics card on the machine to speed things up where one is available. The project is a continuation of an older library called harthur/brain that is no longer maintained.

The README emphasises that you do not need to leave the JavaScript world to use it. You install it with npm install brain.js, or drop in a script tag from a CDN like unpkg, and you have access to several network types: feed-forward NeuralNetwork, recurrent RNN, LSTM, GRU, time-step variants of those for sequence forecasting, and autoencoders.

A short XOR example in the README shows the basic shape of the API. You create a network with a config object that sets things like the number of hidden layer neurons and the activation function, then call net.train with an array of input and output pairs, and net.run to get a prediction for a new input.

For GPU acceleration the library depends on a native module called headless-gl. The README explains that prebuilt binaries usually work, but if they fail to download you may need to build from source, which on Linux means installing build-essential, GLEW, libxi-dev, and pkg-config.

The full README is longer than what was shown.

Where it fits