CatBrain
GPU accelerated neural networks made simple for Javascript, influenced by Brain.js.
Setup
Install through npm:
npm install catbrain
Note: Be sure to have Python (and VS build tools if you are on Windows) already installed or else gpu.js and its deps can not be installed. If things break, try an older Python version and point to that version specifically:
export npm_config_python=/path/to/executable/python
or if you are on Windows:
set NODE_GYP_FORCE_PYTHON=/path/to/executable/python.exe
If the issue still persists, try other Node/Python/VS versions (Node18, Python 3.9, and VS2022 should work fine) and check gpu.js installation requirements.
Tutorial
Here is how to create, train, and run a neural net using CatBrain. All the options and config are shown as comments.
const { CatBrain } = require("catbrain");
const neuralNetwork = new CatBrain({
layers: [2, 3, 1],
learningRate: 0.02,
decayRate: 0.9999,
shuffle: true,
momentum: 0.2,
dampening: 0.2,
nesterov: true,
activation: "relu",
outputActivation: "sigmoid",
leakyReluAlpha: 0.01,
reluClip: 5,
weightInit: "heNormal",
});
neuralNetwork.train(
100000,
[
{ inputs: [0, 0], outputs: [0] },
{ inputs: [0, 1], outputs: [1] },
{ inputs: [1, 0], outputs: [1] },
{ inputs: [1, 1], outputs: [0] }
]
);
console.log(neuralNetwork.feedForward([1, 0]));
Examples
There are several demos available in ./examples
:
Todos
Currently what I have in mind are:
- Option to configure each layer independently to do more than just MLPs.
- Proper GPU acceleration, possibly with CUDA/ROCm and Node C++ bindings.
- More GD opimizers or different optimization algos.
- More pre-built neural network architectures.
- Code refactoring, test cases, and optimization.
- Minor utilities for convenience.
- More activation functions.
Copyrights and License
Copyrights © 2025 Nguyen Phu Minh.
This project is licensed under the GPL 3.0 License.