Cette page est affichée en anglais. Une traduction française est en cours.
ConfigsJul 2, 2026·3 min de lecture

Brain.js — GPU-Accelerated Neural Networks in JavaScript

A JavaScript library for building and training neural networks in the browser and Node.js with optional GPU acceleration via headless-gl.

Prêt pour agents

Staging sûr pour cet actif

Cet actif est d'abord staged. Le prompt copié demande à l'agent d'inspecter les fichiers staged avant d'activer scripts, config MCP ou config globale.

Stage only · 17/100Policy : staging
Surface agent
Tout agent MCP/CLI
Type
Script
Installation
Stage only
Confiance
Confiance : Established
Point d'entrée
Brain.js
Commande de staging sûr
npx -y tokrepo@latest install 83222af5-75ce-11f1-9bc6-00163e2b0d79 --target codex

Stage les fichiers d'abord; l'activation exige la revue du README et du plan staged.

Introduction

Brain.js is a lightweight JavaScript library for neural networks that runs in both the browser and Node.js. It focuses on simplicity, letting developers train feedforward, recurrent, and LSTM networks with just a few lines of code and no ML background required.

What Brain.js Does

  • Trains feedforward, recurrent, LSTM, and GRU neural networks in JavaScript
  • Accelerates training with GPU.js for WebGL-based parallel computation
  • Serializes trained models to JSON for storage and later reuse
  • Supports time-series prediction, pattern recognition, and text classification
  • Runs entirely client-side with no server dependency for inference

Architecture Overview

Brain.js provides a set of network classes: NeuralNetwork for feedforward, RNNTimeStep and LSTMTimeStep for sequential data, and recurrent variants for text. Training runs a configurable backpropagation loop with learning rate, momentum, and error threshold parameters. GPU acceleration is opt-in via the NeuralNetworkGPU class which offloads matrix operations to WebGL shaders through GPU.js.

Self-Hosting & Configuration

  • Install via npm for Node.js or include via CDN for browser usage
  • Choose the network type matching your data: feedforward for classification, LSTM for sequences
  • Configure training options like iterations, error threshold, learning rate, and log interval
  • Export trained models with toJSON and reload them with fromJSON
  • For GPU acceleration in Node.js install gpu.js as a peer dependency

Key Features

  • Simple API that requires no knowledge of linear algebra or ML theory
  • GPU acceleration via WebGL for faster training on supported environments
  • JSON model serialization for saving, sharing, and deploying trained networks
  • Multiple network architectures including LSTM and GRU for sequence tasks
  • Runs in browsers and Node.js with the same API

Comparison with Similar Tools

  • TensorFlow.js — full ML framework with broader model support; Brain.js is simpler for basic networks
  • Synaptic — similar concept but unmaintained; Brain.js is actively developed
  • ConvNetJS — focused on CNNs and archived; Brain.js covers RNNs and LSTMs
  • ml5.js — higher-level wrapper over TensorFlow.js; Brain.js is a standalone lightweight library
  • ONNX Runtime Web — inference-only; Brain.js supports both training and inference

FAQ

Q: What tasks is Brain.js good for? A: Pattern recognition, simple classification, time-series prediction, and text categorization with small to medium datasets.

Q: Can I use it for image recognition? A: It lacks convolutional layers, so for images consider TensorFlow.js or ONNX Runtime instead.

Q: Does GPU acceleration work in all browsers? A: It requires WebGL support. Most modern desktop and mobile browsers support it.

Q: How large can my training data be? A: Brain.js works best with small to medium datasets. For large-scale training, consider server-side frameworks.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires