{"id":28372302,"url":"https://github.com/brainjs/train-stream","last_synced_at":"2025-08-23T15:19:39.965Z","repository":{"id":57378885,"uuid":"468881141","full_name":"BrainJS/train-stream","owner":"BrainJS","description":"A node train stream for brain.js","archived":false,"fork":false,"pushed_at":"2023-03-22T17:14:53.000Z","size":249,"stargazers_count":4,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-02T15:46:48.551Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BrainJS.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-03-11T19:49:36.000Z","updated_at":"2024-04-09T02:27:59.000Z","dependencies_parsed_at":"2023-02-01T09:30:30.239Z","dependency_job_id":"c1a0f277-9b11-4429-a310-2d7ead346f6b","html_url":"https://github.com/BrainJS/train-stream","commit_stats":{"total_commits":7,"total_committers":1,"mean_commits":7.0,"dds":0.0,"last_synced_commit":"630a4ce3db6919f5192fec8f0e7d88f726527609"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/BrainJS/train-stream","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrainJS%2Ftrain-stream","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrainJS%2Ftrain-stream/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrainJS%2Ftrain-stream/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrainJS%2Ftrain-stream/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BrainJS","download_url":"https://codeload.github.com/BrainJS/train-stream/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrainJS%2Ftrain-stream/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271754354,"owners_count":24815185,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-29T13:43:19.651Z","updated_at":"2025-08-23T15:19:39.956Z","avatar_url":"https://github.com/BrainJS.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# brain.js train-stream\nA node train stream for brain.js\n\n## Usage\n\nStreams are a very powerful tool in node for massive data spread across processes and are provided via the brain.js api in the following way:\n\n### Use with brain.js' NeuralNetwork class\n```typescript\nimport { NeuralNetwork } from 'brain.js';\nimport { TrainStream } from 'train-stream';\n\nconst net = new NeuralNetwork();\nconst trainStream = new TrainStream({\n  neuralNetwork: net,\n  floodCallback: () =\u003e {\n    readInputs(trainStream, data);\n  },\n  doneTrainingCallback: (stats) =\u003e {\n    // network is done training!  What next?\n  },\n});\n\n// kick it off\nreadInputs(trainStream, data);\n\nfunction readInputs(stream, data) {\n  for (let i = 0; i \u003c data.length; i++) {\n    stream.write(data[i]);\n  }\n  // let it know we've reached the end of the inputs\n  stream.endInputs();\n}\n```\n\n### Use with brain.js' RNN/LSTM class\n```typescript\nimport { recurrent, utilities } from 'brain.js';\nimport { TrainStream } from 'train-stream';\nconst { LSTM } = recurrent;\n\nconst neuralNetwork = new LSTM({\n  hiddenLayers: [10],\n  dataFormatter: new utilities.DataFormatter(), // You'll need to setup a dataformatter\n});\nconst trainStream = new TrainStream({\n  neuralNetwork,\n  floodCallback: () =\u003e {\n    trainStream.write(myData);\n    trainStream.endInputs();\n  },\n  doneTrainingCallback: (stats) =\u003e {\n    // network is done training!  What next?\n  },\n});\n\n```\n\nAn example of using train stream can be found in [examples/stream-example.ts](examples/stream-example.ts)\n\n## API\nThe network now has a [WriteStream](http://nodejs.org/api/stream.html#stream_class_stream_writable). You can train the network by using `pipe()` to send the training data to the network.\n\n### Initialization\n\nTo train the network using a stream you must first initialize the stream `new TrainStream({ neuralNetwork, floodCallback, doneTrainingCallback })` which takes the following options:\n\n- `neuralNetwork` - the instance of neural network from brain.js used with the stream.  Examples are `NeuralNetwork`, `LSTMTimeStep`, or `LSTM`.\n- `floodCallback` - the callback function to re-populate the stream. This gets called on every training iteration.\n- `doneTrainingCallback(info: { error: number, iterations: number})` - 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.\n\n### Transform\n\nUse a [Transform](http://nodejs.org/api/stream.html#stream_class_stream_transform) to coerce the data into the correct format. You might also use a Transform stream to normalize your data on the fly.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrainjs%2Ftrain-stream","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrainjs%2Ftrain-stream","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrainjs%2Ftrain-stream/lists"}