Zero-dependency neural network framework
One dependency-free source tree for the browser and Node.js. Core operators are checked against numerical gradients.
Most JavaScript deep-learning libraries are wrappers around TensorFlow.js, ONNX, or a native backend. You cannot easily inspect backpropagation, set a breakpoint inside a gradient, or understand the full path without installing a large dependency tree.
axon takes the opposite approach: keep the machinery small enough to read.
Most frameworks trust a passing training run. axon compares analytical gradients against numerical gradients directly.
// Validate an operator while you implement it const r = checkGradient(() => myOp(a, b).sum(), [a, b]); if (!r.passed) throw new Error(r.report);
This caught three silent numerical bugs: a matmul weight gradient that only accumulated the first output column, an optimizer momentum buffer overrun, and an incorrect mse reduction axis. Forward passes looked fine in every case.
The goal is not merely “no runtime error.” It is reproducible convergence.
| Dataset | Accuracy | Loss | Time |
|---|---|---|---|
| XOR (4 samples) | 100.0% | 0.0002 | 6 ms |
| Spiral (300 samples) | 100.0% | 0.0248 | 223 ms |
| Gaussian blobs (400 samples) | 100.0% | 0.0004 | 9 ms |
Linear regression recovers w = 2.511 and b = -1.2115 against targets of 2.5 and -1.2.
Pure CPU, no SIMD, no multithreading, and no WASM. Measured on Node v24 arm64; numbers vary by machine.
| Operation | Throughput |
|---|---|
matmul 512×512 | 2.36 GFLOP/s |
matmul 1024×1024 | 2.30 GFLOP/s |
| MLP 784→128→10 step (batch 32) | 7.8 ms |
Float64Array, but the math is scalar JavaScript with no operator fusion.
Use axon to understand training systems, not to train ResNet.
npm install github:wulier-arch/axon
Or clone the repository. There are no dependencies, and src/ is the complete library.
git clone https://github.com/wulier-arch/axon.git
cd axon && npm test
For smaller training examples, open the XOR classifier or linear regression. Both pages load src/ directly without a bundler.
Train a neural network in 11 lines:
import { Linear, Sequential, Adam, Trainer, crossEntropy, accuracy, makeSpiral } from "axon-net"; const { x, y } = makeSpiral({ samples: 300 }); const model = new Sequential() .add(new Linear(2, 32, { activation: "relu", seed: 1 })) .add(new Linear(32, 2, { seed: 2 })); const trainer = new Trainer({ model, optimizer: new Adam({ lr: 0.01 }), lossFn: crossEntropy, metricFn: accuracy, epochs: 400, batchSize: 32, }); trainer.fit(x, y, y); console.log(trainer.history.at(-1)); // { epoch: 399, loss: 0.0248, metric: 1 }
Arithmetic, matmul, softmax, reshape, N-dimensional transpose, single-image and batched conv2d via im2col + GEMM, and pooling.
A topological backward pass with graph-node tracking, so composed operations keep their full gradient chain.
Linear, Dropout, LayerNorm, Embedding, MultiHeadAttention, TransformerBlock, Sequential, SGD, Momentum, Adam, AdamW, RMSProp, and schedulers.
Stable softmax and crossEntropy, clamped binary cross-entropy, and explicit guards against NaN losses.
Shipped: layers and Sequential, optimizers, losses, and training loops (v0.2.0); browser demo (v0.2.1); LayerNorm, Embedding, MultiHeadAttention, and TransformerBlock (v0.3.0); XOR and linear-regression browser examples plus JSON model serialization and loading (v0.3.1). Batched conv2d is complete with 114 passing tests and will ship in the next version.