[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-3875":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":17,"stars30d":18,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":19,"rankGlobal":10,"rankLanguage":10,"license":20,"archived":21,"fork":21,"defaultBranch":22,"hasWiki":23,"hasPages":21,"topics":24,"createdAt":10,"pushedAt":10,"updatedAt":37,"readmeContent":38,"aiSummary":39,"trendingCount":16,"starSnapshotCount":16,"syncStatus":40,"lastSyncTime":41,"discoverSource":42},3875,"brain.js","BrainJS\u002Fbrain.js","BrainJS","🤖 GPU accelerated Neural networks in JavaScript for Browsers and Node.js","https:\u002F\u002Fbrain.js.org",null,"TypeScript",14857,1076,239,83,0,1,9,44.1,"MIT License",false,"master",true,[25,26,27,28,29,30,31,32,33,34,35,36],"api","brain","browser","convolutional-neural-networks","easy-to-use","hacktoberfest","neural-network","node","nodejs","recurrent-neural-networks","stream","web","2026-06-12 02:00:55","\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Fcdn.rawgit.com\u002Fharthur-org\u002Fbrain.js\u002Fff595242\u002Flogo.svg\" alt=\"Logo\" width=200px\u002F>\n\u003C\u002Fp>\n\n# brain.js\n\nGPU accelerated Neural networks in JavaScript for Browsers and Node.js\n\n\u003Cp style=\"text-align: center\" align=\"center\">\n\n  \u003Ca href=\"https:\u002F\u002Fbrain.js.org\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fwebsite?up_message=brain.js.org&url=https%3A%2F%2Fbrain.js.org\" alt=\"GitHub\">\u003C\u002Fa>\n  [![npm](https:\u002F\u002Fimg.shields.io\u002Fnpm\u002Fdt\u002Fbrain.js.svg?style=flat-square)](https:\u002F\u002Fnpmjs.com\u002Fpackage\u002Fbrain.js) [![js-standard-style](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fcode%20style-standard-brightgreen.svg)](http:\u002F\u002Fstandardjs.com)\n  [![Backers on Open Collective](https:\u002F\u002Fopencollective.com\u002Fbrainjs\u002Fbackers\u002Fbadge.svg)](#backers)\n  [![Sponsors on Open Collective](https:\u002F\u002Fopencollective.com\u002Fbrainjs\u002Fsponsors\u002Fbadge.svg)](#sponsors)\n  [![Gitter](https:\u002F\u002Fbadges.gitter.im\u002FJoin%20Chat.svg)](https:\u002F\u002Fgitter.im\u002Fbrain-js\u002FLobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)\n  [![Slack](https:\u002F\u002Fslack.bri.im\u002Fbadge.svg)](https:\u002F\u002Fslack.bri.im)\n  ![CI](https:\u002F\u002Fgithub.com\u002FBrainJS\u002Fbrain.js\u002Fworkflows\u002FCI\u002Fbadge.svg)\n  [![codecov](https:\u002F\u002Fcodecov.io\u002Fgh\u002FBrainJS\u002Fbrain.js\u002Fbranch\u002Fmaster\u002Fgraph\u002Fbadge.svg?token=3SJIBJ1679)](https:\u002F\u002Fcodecov.io\u002Fgh\u002FBrainJS\u002Fbrain.js)\n  \u003Ca href=\"https:\u002F\u002Ftwitter.com\u002Fbrainjsfnd\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Ftwitter\u002Ffollow\u002Fbrainjsfnd?label=Twitter&style=social\" alt=\"Twitter\">\u003C\u002Fa>\n\n  [![NPM](https:\u002F\u002Fnodei.co\u002Fnpm\u002Fbrain.js.png?compact=true)](https:\u002F\u002Fnodei.co\u002Fnpm\u002Fbrain.js\u002F)\n\n\u003C\u002Fp>\n\n## About\n\n`brain.js` is a GPU accelerated library for [Neural Networks](http:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FArtificial_neural_network) written in JavaScript.\n\n:bulb: This is a continuation of the [**harthur\u002Fbrain**](https:\u002F\u002Fgithub.com\u002Fharthur\u002Fbrain), which is not maintained anymore. [More info](https:\u002F\u002Fgithub.com\u002Fharthur\u002Fbrain\u002Fissues\u002F72)\n\n## Table of Contents\n\n- [Installation and Usage](#Installation-and-Usage)\n  - [NPM](#NPM)\n  - [CDN](#CDN)\n  - [Download](#Download)\n  - [Installation note](#Installation-note)\n  - [Building from source](#Building-from-source)\n- [Examples](#examples)\n  - [More Examples](#more-examples)\n- [Training](#training)\n  - [Data format](#data-format)\n    - [For training with NeuralNetwork](#for-training-with-neuralnetwork)\n    - [For training with `RNNTimeStep`, `LSTMTimeStep` and `GRUTimeStep`](#for-training-with-rnntimestep-lstmtimestep-and-grutimestep)\n    - [For training with `RNN`, `LSTM` and `GRU`](#for-training-with-rnn-lstm-and-gru)\n    - [For training with `AE`](#for-training-with-ae)\n  - [Training Options](#training-options)\n  - [Async Training](#async-training)\n  - [Cross Validation](#cross-validation)\n  - [Train Stream](#streams)\n- [Methods](#methods)\n  - [train](#traintrainingdata---trainingstatus)\n  - [run](#runinput---prediction)\n  - [forecast](#forecastinput-count---predictions)\n- [Failing](#failing)\n- [JSON](#json)\n- [Standalone Function](#standalone-function)\n- [Options](#options)\n  - [activation](#activation)\n  - [hiddenLayers](#hiddenlayers)\n- [Streams](#streams)\n- [Utilities](#utilities)\n  - [`likely`](#likely)\n  - [`toSVG`](#toSVG)\n- [Neural Network Types](#neural-network-types)\n  - [Why different Neural Network Types?](#why-different-neural-network-types)\n\n## Installation and Usage\n\n### NPM\n\nIf you can install `brain.js` with [npm](http:\u002F\u002Fnpmjs.org):\n\n```bash\nnpm install brain.js\n```\n\n### CDN\n\n```html\n\u003Cscript src=\"\u002F\u002Funpkg.com\u002Fbrain.js\">\u003C\u002Fscript>\n```\n\n### Download\n\n[Download the latest brain.js for browser](https:\u002F\u002Funpkg.com\u002Fbrain.js)\n\n### Installation note\n\n`Brain.js` depends on a native module [`headless-gl`](https:\u002F\u002Fwww.npmjs.com\u002Fpackage\u002Fheadless-gl) for GPU support. In most cases installing `brain.js` from npm should just work. However, if you run into problems, this means prebuilt binaries are not able to download from GitHub repositories and you might need to build it yourself.\n\n#### Building from source\n\nPlease make sure the following dependencies are installed and up to date and then run:\n\n```bash\nnpm rebuild\n```\n\n##### System dependencies\n\n###### Mac OS X\n\n- [A supported version of Python](https:\u002F\u002Fdevguide.python.org\u002Fversions)\n- [XCode](https:\u002F\u002Fdeveloper.apple.com\u002Fxcode\u002F)\n\n###### Ubuntu\u002FDebian\n\n- [A supported version of Python](https:\u002F\u002Fdevguide.python.org\u002Fversions)\n- A GNU C++ environment (available via the `build-essential` package on `apt`)\n- [libxi-dev](http:\u002F\u002Fwww.x.org\u002Fwiki\u002F)\n- Working and up-to-date OpenGL drivers\n- [GLEW](http:\u002F\u002Fglew.sourceforge.net\u002F)\n- [pkg-config](https:\u002F\u002Fwww.freedesktop.org\u002Fwiki\u002FSoftware\u002Fpkg-config\u002F)\n\n```bash\nsudo apt-get install -y build-essential libglew-dev libglu1-mesa-dev libxi-dev pkg-config\n```\n\n###### Windows\n\n- [A supported version of Python](https:\u002F\u002Fdevguide.python.org\u002Fversions)  __See:__ https:\u002F\u002Fapps.microsoft.com\u002Fstore\u002Fsearch\u002Fpython\n- [Microsoft Visual Studio Build Tools 2022](https:\u002F\u002Fvisualstudio.microsoft.com\u002Fdownloads)\n- run in cmd: `npm config set msvs_version 2022`  __Note: This no longer works in modern versions of npm.__\n- run in cmd: `npm config set python python3`  __Note: This no longer works in modern versions of npm.__\n\n\\* If you are using `Build Tools 2017` then run `npm config set msvs_version 2017`  __Note: This no longer works in modern versions of npm.__\n\n## Examples\n\nHere's an example showcasing how to approximate the XOR function using `brain.js`:\nmore info on config [here](https:\u002F\u002Fgithub.com\u002FBrainJS\u002Fbrain.js\u002Fblob\u002Fdevelop\u002Fsrc\u002Fneural-network.js#L31).\n\n:bulb: [A fun and practical introduction to Brain.js](https:\u002F\u002Fscrimba.com\u002Fg\u002Fgneuralnetworks)\n\n```javascript\n\u002F\u002F provide optional config object (or undefined). Defaults shown.\nconst config = {\n  binaryThresh: 0.5,\n  hiddenLayers: [3], \u002F\u002F array of ints for the sizes of the hidden layers in the network\n  activation: 'sigmoid', \u002F\u002F supported activation types: ['sigmoid', 'relu', 'leaky-relu', 'tanh'],\n  leakyReluAlpha: 0.01, \u002F\u002F supported for activation type 'leaky-relu'\n};\n\n\u002F\u002F create a simple feed-forward neural network with backpropagation\nconst net = new brain.NeuralNetwork(config);\n\nnet.train([\n  { input: [0, 0], output: [0] },\n  { input: [0, 1], output: [1] },\n  { input: [1, 0], output: [1] },\n  { input: [1, 1], output: [0] },\n]);\n\nconst output = net.run([1, 0]); \u002F\u002F [0.987]\n```\n\nor\nmore info on config [here](https:\u002F\u002Fgithub.com\u002FBrainJS\u002Fbrain.js\u002Fblob\u002Fdevelop\u002Fsrc\u002Frecurrent\u002Frnn.js#L726).\n\n```javascript\n\u002F\u002F provide optional config object, defaults shown.\nconst config = {\n  inputSize: 20,\n  inputRange: 20,\n  hiddenLayers: [20, 20],\n  outputSize: 20,\n  learningRate: 0.01,\n  decayRate: 0.999,\n};\n\n\u002F\u002F create a simple recurrent neural network\nconst net = new brain.recurrent.RNN(config);\n\nnet.train([\n  { input: [0, 0], output: [0] },\n  { input: [0, 1], output: [1] },\n  { input: [1, 0], output: [1] },\n  { input: [1, 1], output: [0] },\n]);\n\nlet output = net.run([0, 0]); \u002F\u002F [0]\noutput = net.run([0, 1]); \u002F\u002F [1]\noutput = net.run([1, 0]); \u002F\u002F [1]\noutput = net.run([1, 1]); \u002F\u002F [0]\n```\n\nHowever, there is no reason to use a neural network to figure out XOR. (-: So, here is a more involved, realistic example:\n[Demo: training a neural network to recognize color contrast](https:\u002F\u002Fbrain.js.org\u002F).\n\n## More Examples\n\n[Brain.js Examples Repo](https:\u002F\u002Fgithub.com\u002FBrainJS\u002Fbrain.js-examples)\n\nYou can check out this fantastic screencast, which explains how to train a simple neural network using a real-world dataset: [How to create a neural network in the browser using Brain.js](https:\u002F\u002Fscrimba.com\u002Fc\u002Fc36zkcb).\n\n## Training\n\nUse `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()`. More training patterns will probably take longer to train, but will usually result in a network better at classifying new patterns.\n\n### Note\n\nTraining 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 into your website.\n\n### Data format\n\n#### For training with `NeuralNetwork`\n\nEach 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 contrast demo](https:\u002F\u002Fbrain.js.org\u002F) it looks something like this:\n\n```javascript\nconst net = new brain.NeuralNetwork();\n\nnet.train([\n  { input: { r: 0.03, g: 0.7, b: 0.5 }, output: { black: 1 } },\n  { input: { r: 0.16, g: 0.09, b: 0.2 }, output: { white: 1 } },\n  { input: { r: 0.5, g: 0.5, b: 1.0 }, output: { white: 1 } },\n]);\n\nconst output = net.run({ r: 1, g: 0.4, b: 0 }); \u002F\u002F { white: 0.99, black: 0.002 }\n```\n\nHere's another variation of the above example. (_Note_ that input objects do not need to be similar.)\n\n```javascript\nnet.train([\n  { input: { r: 0.03, g: 0.7 }, output: { black: 1 } },\n  { input: { r: 0.16, b: 0.2 }, output: { white: 1 } },\n  { input: { r: 0.5, g: 0.5, b: 1.0 }, output: { white: 1 } },\n]);\n\nconst output = net.run({ r: 1, g: 0.4, b: 0 }); \u002F\u002F { white: 0.81, black: 0.18 }\n```\n\n#### For training with `RNNTimeStep`, `LSTMTimeStep` and `GRUTimeStep`\n\nEach training pattern can either:\n\n- Be an array of numbers\n- Be an array of arrays of numbers\n\nExample using an array of numbers:\n\n```javascript\nconst net = new brain.recurrent.LSTMTimeStep();\n\nnet.train([[1, 2, 3]]);\n\nconst output = net.run([1, 2]); \u002F\u002F 3\n```\n\nExample using an array of arrays of numbers:\n\n```javascript\nconst net = new brain.recurrent.LSTMTimeStep({\n  inputSize: 2,\n  hiddenLayers: [10],\n  outputSize: 2,\n});\n\nnet.train([\n  [1, 3],\n  [2, 2],\n  [3, 1],\n]);\n\nconst output = net.run([\n  [1, 3],\n  [2, 2],\n]); \u002F\u002F [3, 1]\n```\n\n#### For training with `RNN`, `LSTM` and `GRU`\n\nEach training pattern can either:\n\n- Be an array of values\n- Be a string\n- Have an `input` and an `output`\n  - Either of which can have an array of values or a string\n\nCAUTION: When using an array of values, you can use ANY value, however, the values are represented in the neural network by a single input. So the more _distinct values_ has _the larger your input layer_. If you have a hundreds, thousands, or millions of floating point values _THIS IS NOT THE RIGHT CLASS FOR THE JOB_. Also, when deviating from strings, this gets into beta\n\nExample using direct strings:\nHello World Using Brainjs\n```javascript\n\n  const net = new brain.recurrent.LSTM();\n\n  net.train(['I am brainjs, Hello World!']);\n\n  const output = net.run('I am brainjs');\n  alert(output);\n```\n\n```javascript\nconst net = new brain.recurrent.LSTM();\n\nnet.train([\n  'doe, a deer, a female deer',\n  'ray, a drop of golden sun',\n  'me, a name I call myself',\n]);\n\nconst output = net.run('doe'); \u002F\u002F ', a deer, a female deer'\n```\n\nExample using strings with inputs and outputs:\n\n```javascript\nconst net = new brain.recurrent.LSTM();\n\nnet.train([\n  { input: 'I feel great about the world!', output: 'happy' },\n  { input: 'The world is a terrible place!', output: 'sad' },\n]);\n\nconst output = net.run('I feel great about the world!'); \u002F\u002F 'happy'\n```\n\n#### For training with `AE`\n\nEach training pattern can either:\n\n- Be an array of numbers\n- Be an array of arrays of numbers\n\nTraining an autoencoder to compress the values of a XOR calculation:\n\n```javascript\nconst net = new brain.AE(\n  {\n    hiddenLayers: [ 5, 2, 5 ]\n  }\n);\n\nnet.train([\n  [ 0, 0, 0 ],\n  [ 0, 1, 1 ],\n  [ 1, 0, 1 ],\n  [ 1, 1, 0 ]\n]);\n```\n\nEncoding\u002Fdecoding:\n\n```javascript\nconst input = [ 0, 1, 1 ];\n\nconst encoded = net.encode(input);\nconst decoded = net.decode(encoded);\n```\n\nDenoise noisy data:\n\n```javascript\nconst noisyData = [ 0, 1, 0 ];\n\nconst data = net.denoise(noisyData);\n```\n\nTest for anomalies in data samples:\n\n```javascript\nconst shouldBeFalse = net.includesAnomalies([0, 1, 1]);\nconst shouldBeTrue = net.includesAnomalies([0, 1, 0]);\n```\n\n### Training Options\n\n`train()` takes a hash of options as its second argument:\n\n```javascript\nnet.train(data, {\n  \u002F\u002F Defaults values --> expected validation\n  iterations: 20000, \u002F\u002F the maximum times to iterate the training data --> number greater than 0\n  errorThresh: 0.005, \u002F\u002F the acceptable error percentage from training data --> number between 0 and 1\n  log: false, \u002F\u002F true to use console.log, when a function is supplied it is used --> Either true or a function\n  logPeriod: 10, \u002F\u002F iterations between logging out --> number greater than 0\n  learningRate: 0.3, \u002F\u002F scales with delta to effect training rate --> number between 0 and 1\n  momentum: 0.1, \u002F\u002F scales with next layer's change value --> number between 0 and 1\n  callback: null, \u002F\u002F a periodic call back that can be triggered while training --> null or function\n  callbackPeriod: 10, \u002F\u002F the number of iterations through the training data between callback calls --> number greater than 0\n  timeout: number, \u002F\u002F the max number of milliseconds to train for --> number greater than 0. Default --> Infinity\n});\n```\n\nThe network will stop training whenever one of the two criteria is met: the training error has gone below the threshold (default `0.005`), or the max number of iterations (default `20000`) has been reached.\n\nBy default, training will not let you know how it's 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 the console. If you set `log` to a function, this function will be called with the updates instead of printing to the console.\nHowever, if you want to use the values of the updates in your own output, the `callback` can be set to a function to do so instead.\n\nThe 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 training results may be constrained to a local minimum and perform badly on new data.(_Overfitting_) The default learning rate is `0.3`.\n\nThe momentum is similar to learning rate, expecting a value from `0` to `1` as well, but it is multiplied against the next level's change value. The default value is `0.1`\n\nAny of these training options can be passed into the constructor or passed into the `updateTrainingOptions(opts)` method and they will be saved on the network and used during the training time. If you save your network to json, these training options are saved and restored as well (except for callback and log, callback will be forgotten and log will be restored using console.log).\n\nA boolean property called `invalidTrainOptsShouldThrow` is set to `true` by default. While the option is `true`, if you enter a training option that is outside the normal range, an error will be thrown with a message about the abnormal option. When the option is set to `false`, no error will be sent, but a message will still be sent to `console.warn` with the related information.\n\n### Async Training\n\n`trainAsync()` takes the same arguments as train (data and options). Instead of returning the results object from training, it returns a promise that when resolved will return the training results object.  Does NOT work with:\n* `brain.recurrent.RNN`\n* `brain.recurrent.GRU`\n* `brain.recurrent.LSTM`\n* `brain.recurrent.RNNTimeStep`\n* `brain.recurrent.GRUTimeStep`\n* `brain.recurrent.LSTMTimeStep`\n\n```javascript\nconst net = new brain.NeuralNetwork();\nnet\n  .trainAsync(data, options)\n  .then((res) => {\n    \u002F\u002F do something with my trained network\n  })\n  .catch(handleError);\n```\n\nWith multiple networks you can train in parallel like this:\n\n```javascript\nconst net = new brain.NeuralNetwork();\nconst net2 = new brain.NeuralNetwork();\n\nconst p1 = net.trainAsync(data, options);\nconst p2 = net2.trainAsync(data, options);\n\nPromise.all([p1, p2])\n  .then((values) => {\n    const res = values[0];\n    const res2 = values[1];\n    console.log(\n      `net trained in ${res.iterations} and net2 trained in ${res2.iterations}`\n    );\n    \u002F\u002F do something super cool with my 2 trained networks\n  })\n  .catch(handleError);\n```\n\n### Cross Validation\n\n[Cross Validation](\u003Chttps:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FCross-validation_(statistics)>) can provide a less fragile way of training on larger data sets. The brain.js api provides Cross Validation in this example:\n\n```js\nconst crossValidate = new brain.CrossValidate(() => new brain.NeuralNetwork(networkOptions));\ncrossValidate.train(data, trainingOptions, k); \u002F\u002Fnote k (or KFolds) is optional\nconst json = crossValidate.toJSON(); \u002F\u002F all stats in json as well as neural networks\nconst net = crossValidate.toNeuralNetwork(); \u002F\u002F get top performing net out of `crossValidate`\n\n\u002F\u002F optionally later\nconst json = crossValidate.toJSON();\nconst net = crossValidate.fromJSON(json);\n```\n\nUse `CrossValidate` with these classes:\n\n- `brain.NeuralNetwork`\n- `brain.RNNTimeStep`\n- `brain.LSTMTimeStep`\n- `brain.GRUTimeStep`\n\nAn example of using cross validate can be found in [cross-validate.ts](https:\u002F\u002Fgithub.com\u002FBrainJS\u002Fbrain.js-examples\u002Fblob\u002Fmain\u002Fsrc\u002Fcross-validate.ts)\n\n## Methods\n\n### `train(trainingData)` -> trainingStatus\n\nThe output of `train()` is a hash of information about how the training went:\n\n```javascript\n{\n  error: 0.0039139985510105032,  \u002F\u002F training error\n  iterations: 406                \u002F\u002F training iterations\n}\n```\n\n### `run(input)` -> prediction\n\nSupported on classes:\n\n- `brain.NeuralNetwork`\n- `brain.NeuralNetworkGPU` -> All the functionality of `brain.NeuralNetwork` but, ran on GPU (via gpu.js in WebGL2, WebGL1, or fallback to CPU)\n- `brain.recurrent.RNN`\n- `brain.recurrent.LSTM`\n- `brain.recurrent.GRU`\n- `brain.recurrent.RNNTimeStep`\n- `brain.recurrent.LSTMTimeStep`\n- `brain.recurrent.GRUTimeStep`\n\nExample:\n\n```js\n\u002F\u002F feed forward\nconst net = new brain.NeuralNetwork();\nnet.fromJSON(json);\nnet.run(input);\n\n\u002F\u002F time step\nconst net = new brain.LSTMTimeStep();\nnet.fromJSON(json);\nnet.run(input);\n\n\u002F\u002F recurrent\nconst net = new brain.LSTM();\nnet.fromJSON(json);\nnet.run(input);\n```\n\n### `forecast(input, count)` -> predictions\n\nAvailable with the following classes. Outputs a array of predictions. Predictions being a continuation of the inputs.\n\n- `brain.recurrent.RNNTimeStep`\n- `brain.recurrent.LSTMTimeStep`\n- `brain.recurrent.GRUTimeStep`\n\nExample:\n\n```js\nconst net = new brain.LSTMTimeStep();\nnet.fromJSON(json);\nnet.forecast(input, 3);\n```\n\n### `toJSON() -> json`\n\nSerialize neural network to json\n\n### `fromJSON(json)`\n\nDeserialize neural network from json\n\n## Failing\n\nIf the network failed to train, the error will be above the error threshold. This could happen if the training data is too noisy (most likely), the network does not have enough hidden layers or nodes to handle the complexity of the data, or it has not been trained for enough iterations.\n\nIf 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 given data.\n\n### RNN, LSTM, or GRU Output too short or too long\n\nThe instance of the net's property `maxPredictionLength` (default 100) can be set to adjust the output of the net;\n\nExample:\n\n```js\nconst net = new brain.recurrent.LSTM();\n\n\u002F\u002F later in code, after training on a few novels, write me a new one!\nnet.maxPredictionLength = 1000000000; \u002F\u002F Be careful!\nnet.run('Once upon a time');\n```\n\n## JSON\n\nSerialize or load in the state of a trained network with JSON:\n\n```javascript\nconst json = net.toJSON();\nnet.fromJSON(json);\n```\n\n## Standalone Function\n\nYou can also get a custom standalone function from a trained network that acts just like `run()`:\n\n```javascript\nconst run = net.toFunction();\nconst output = run({ r: 1, g: 0.4, b: 0 });\nconsole.log(run.toString()); \u002F\u002F copy and paste! no need to import brain.js\n```\n\n## Options\n\n`NeuralNetwork()` takes a hash of options:\n\n```javascript\nconst net = new brain.NeuralNetwork({\n  activation: 'sigmoid', \u002F\u002F activation function\n  hiddenLayers: [4],\n  learningRate: 0.6, \u002F\u002F global learning rate, useful when training using streams\n});\n```\n\n### activation\n\nThis parameter lets you specify which activation function your neural network should use. There are currently four supported activation functions, **sigmoid** being the default:\n\n- [sigmoid](https:\u002F\u002Fwww.wikiwand.com\u002Fen\u002FSigmoid_function)\n- [relu](\u003Chttps:\u002F\u002Fwww.wikiwand.com\u002Fen\u002FRectifier_(neural_networks)>)\n- [leaky-relu](\u003Chttps:\u002F\u002Fwww.wikiwand.com\u002Fen\u002FRectifier_(neural_networks)>)\n  - related option - 'leakyReluAlpha' optional number, defaults to 0.01\n- [tanh](https:\u002F\u002Ftheclevermachine.wordpress.com\u002Ftag\u002Ftanh-function\u002F)\n\nHere's a table (thanks, Wikipedia!) summarizing a plethora of activation functions — [Activation Function](https:\u002F\u002Fwww.wikiwand.com\u002Fen\u002FActivation_function)\n\n### hiddenLayers\n\nYou can use this to 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:\n\n```js\nhiddenLayers: [3, 4];\n```\n\nBy default `brain.js` uses one hidden layer with size proportionate to the size of the input array.\n\n## Streams\n\nUse https:\u002F\u002Fwww.npmjs.com\u002Fpackage\u002Ftrain-stream to stream data to a NeuralNetwork\n\n## Utilities\n\n### `likely`\n\n```js\nconst likely = require('brain\u002Flikely');\nconst key = likely(input, net);\n```\n\nLikely example see: [simple letter detection](https:\u002F\u002Fgithub.com\u002FBrainJS\u002Fbrain.js-examples\u002Fblob\u002Fmain\u002Fsrc\u002Fwhich-letter-simple.ts)\n\n### `toSVG`\n\n```js\n\u003Cscript src=\"..\u002F..\u002Fsrc\u002Futilities\u002Fsvg.js\">\u003C\u002Fscript>\n```\n\nRenders the network topology of a feedforward network\n\n```js\ndocument.getElementById('result').innerHTML = brain.utilities.toSVG(\n  network,\n  options\n);\n```\n\ntoSVG example see: [network rendering](https:\u002F\u002Fgithub.com\u002FBrainJS\u002Fbrain.js-examples\u002Fblob\u002Fmain\u002Fsrc\u002Frendering-svg\u002Findex.html)\n\nThe user interface used:\n![screenshot1](https:\u002F\u002Fuser-images.githubusercontent.com\u002F43925925\u002F48969024-e526ed80-f000-11e8-85bd-e10967cfaee2.png)\n\n## Neural Network Types\n\n- [`brain.NeuralNetwork`](src\u002Fneural-network.ts) - [Feedforward Neural Network](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FFeedforward_neural_network) with backpropagation\n- [`brain.NeuralNetworkGPU`](src\u002Fneural-network-gpu.ts) - [Feedforward Neural Network](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FFeedforward_neural_network) with backpropagation, GPU version\n- [`brain.AE`](src\u002Fautoencoder.ts) - [Autoencoder or \"AE\"](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FAutoencoder) with backpropogation and GPU support\n- [`brain.recurrent.RNNTimeStep`](src\u002Frecurrent\u002Frnn-time-step.ts) - [Time Step Recurrent Neural Network or \"RNN\"](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FRecurrent_neural_network)\n- [`brain.recurrent.LSTMTimeStep`](src\u002Frecurrent\u002Flstm-time-step.ts) - [Time Step Long Short Term Memory Neural Network or \"LSTM\"](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FLong_short-term_memory)\n- [`brain.recurrent.GRUTimeStep`](src\u002Frecurrent\u002Fgru-time-step.ts) - [Time Step Gated Recurrent Unit or \"GRU\"](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FGated_recurrent_unit)\n- [`brain.recurrent.RNN`](src\u002Frecurrent\u002Frnn.ts) - [Recurrent Neural Network or \"RNN\"](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FRecurrent_neural_network)\n- [`brain.recurrent.LSTM`](src\u002Frecurrent\u002Flstm.ts) - [Long Short Term Memory Neural Network or \"LSTM\"](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FLong_short-term_memory)\n- [`brain.recurrent.GRU`](src\u002Frecurrent\u002Fgru.ts) - [Gated Recurrent Unit or \"GRU\"](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FGated_recurrent_unit)\n- [`brain.FeedForward`](src\u002Ffeed-forward.ts) - [Highly Customizable Feedforward Neural Network](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FFeedforward_neural_network) with backpropagation\n- [`brain.Recurrent`](src\u002Frecurrent.ts) - [Highly Customizable Recurrent Neural Network](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FRecurrent_neural_network) with backpropagation\n\n### Why different Neural Network Types\n\nDifferent neural nets do different things well. For example:\n\n- A Feedforward Neural Network can classify simple things very well, but it has no memory of previous actions and has infinite variation of results.\n- A Time Step Recurrent Neural Network _remembers_, and can predict future values.\n- A Recurrent Neural Network _remembers_, and has a finite set of results.\n\n## Get Involved\n\n### W3C machine learning standardization process\n\nIf you are a developer or if you just care about how ML API should look like - please take a part and join W3C community and share your opinions or simply support opinions you like or agree with.\n\nBrain.js is a widely adopted open source machine learning library in the javascript world. There are several reasons for it, but most notable is **simplicity of usage while not sacrificing performance**.\nWe would like to keep it also simple to learn, simple to use and performant when it comes to W3C standard. We think that current brain.js API is quite close to what we could expect to become a standard.\nAnd since supporting doesn't require much effort and still can make a huge difference feel free to join W3C community group and support us with brain.js like API.\n\nGet involved into W3C machine learning ongoing standardization process [here](https:\u002F\u002Fwww.w3.org\u002Fcommunity\u002Fwebmachinelearning\u002F).\nYou can also join our open discussion about standardization [here](https:\u002F\u002Fgithub.com\u002FBrainJS\u002Fbrain.js\u002Fissues\u002F337).\n\n## Issues\n\nIf you have an issue, either a bug or a feature you think would benefit your project let us know and we will do our best.\n\nCreate issues [here](https:\u002F\u002Fgithub.com\u002FBrainJS\u002Fbrain.js\u002Fissues) and follow the template.\n\n### brain.js.org\n\nSource for `brain.js.org` is available at [Brain.js.org Repository](https:\u002F\u002Fgithub.com\u002FBrainJS\u002Fbrain.js.org). Built using awesome `vue.js` & `bulma`. Contributions are always welcome.\n\n## Contributors\n\nThis project exists thanks to all the people who contribute. [[Contribute](\u002F.github\u002FCONTRIBUTING.md)].\n\u003Ca href=\"https:\u002F\u002Fgithub.com\u002FBrainJS\u002Fbrain.js\u002Fgraphs\u002Fcontributors\">\u003Cimg src=\"https:\u002F\u002Fopencollective.com\u002Fbrainjs\u002Fcontributors.svg?width=890&button=false\" \u002F>\u003C\u002Fa>\n\n## Backers\n\nThank you to all our backers! 🙏 [[Become a backer](https:\u002F\u002Fopencollective.com\u002Fbrainjs#backer)]\n\n\u003Ca href=\"https:\u002F\u002Fopencollective.com\u002Fbrainjs#backers\" target=\"_blank\">\u003Cimg src=\"https:\u002F\u002Fopencollective.com\u002Fbrainjs\u002Fbackers.svg?width=890\">\u003C\u002Fa>\n\n## Sponsors\n\nSupport this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https:\u002F\u002Fopencollective.com\u002Fbrainjs#sponsor)]\n\n\u003Ca href=\"https:\u002F\u002Fopencollective.com\u002Fbrainjs\u002Fsponsor\u002F0\u002Fwebsite\" target=\"_blank\">\u003Cimg src=\"https:\u002F\u002Fopencollective.com\u002Fbrainjs\u002Fsponsor\u002F0\u002Favatar.svg\">\u003C\u002Fa>\n\u003Ca href=\"https:\u002F\u002Fopencollective.com\u002Fbrainjs\u002Fsponsor\u002F1\u002Fwebsite\" target=\"_blank\">\u003Cimg src=\"https:\u002F\u002Fopencollective.com\u002Fbrainjs\u002Fsponsor\u002F1\u002Favatar.svg\">\u003C\u002Fa>\n\u003Ca href=\"https:\u002F\u002Fopencollective.com\u002Fbrainjs\u002Fsponsor\u002F2\u002Fwebsite\" target=\"_blank\">\u003Cimg src=\"https:\u002F\u002Fopencollective.com\u002Fbrainjs\u002Fsponsor\u002F2\u002Favatar.svg\">\u003C\u002Fa>\n\u003Ca href=\"https:\u002F\u002Fopencollective.com\u002Fbrainjs\u002Fsponsor\u002F3\u002Fwebsite\" target=\"_blank\">\u003Cimg src=\"https:\u002F\u002Fopencollective.com\u002Fbrainjs\u002Fsponsor\u002F3\u002Favatar.svg\">\u003C\u002Fa>\n\u003Ca href=\"https:\u002F\u002Fopencollective.com\u002Fbrainjs\u002Fsponsor\u002F4\u002Fwebsite\" target=\"_blank\">\u003Cimg src=\"https:\u002F\u002Fopencollective.com\u002Fbrainjs\u002Fsponsor\u002F4\u002Favatar.svg\">\u003C\u002Fa>\n\u003Ca href=\"https:\u002F\u002Fopencollective.com\u002Fbrainjs\u002Fsponsor\u002F5\u002Fwebsite\" target=\"_blank\">\u003Cimg src=\"https:\u002F\u002Fopencollective.com\u002Fbrainjs\u002Fsponsor\u002F5\u002Favatar.svg\">\u003C\u002Fa>\n\u003Ca href=\"https:\u002F\u002Fopencollective.com\u002Fbrainjs\u002Fsponsor\u002F6\u002Fwebsite\" target=\"_blank\">\u003Cimg src=\"https:\u002F\u002Fopencollective.com\u002Fbrainjs\u002Fsponsor\u002F6\u002Favatar.svg\">\u003C\u002Fa>\n\u003Ca href=\"https:\u002F\u002Fopencollective.com\u002Fbrainjs\u002Fsponsor\u002F7\u002Fwebsite\" target=\"_blank\">\u003Cimg src=\"https:\u002F\u002Fopencollective.com\u002Fbrainjs\u002Fsponsor\u002F7\u002Favatar.svg\">\u003C\u002Fa>\n\u003Ca href=\"https:\u002F\u002Fopencollective.com\u002Fbrainjs\u002Fsponsor\u002F8\u002Fwebsite\" target=\"_blank\">\u003Cimg src=\"https:\u002F\u002Fopencollective.com\u002Fbrainjs\u002Fsponsor\u002F8\u002Favatar.svg\">\u003C\u002Fa>\n\u003Ca href=\"https:\u002F\u002Fopencollective.com\u002Fbrainjs\u002Fsponsor\u002F9\u002Fwebsite\" target=\"_blank\">\u003Cimg src=\"https:\u002F\u002Fopencollective.com\u002Fbrainjs\u002Fsponsor\u002F9\u002Favatar.svg\">\u003C\u002Fa>\n","brain.js 是一个用于浏览器和 Node.js 的 JavaScript 神经网络库，支持 GPU 加速。它提供了易于使用的 API 来创建、训练和运行神经网络模型，包括卷积神经网络（CNN）和循环神经网络（RNN）。该库使用 TypeScript 编写，具有良好的代码规范，并且在多种环境下都能保持高性能。brain.js 适用于需要快速原型设计或部署机器学习模型的前端应用及后端服务中，特别适合那些希望利用现有 JavaScript 技能集来构建智能应用的开发者。",2,"2026-06-11 02:56:51","top_language"]