Nerve
A single-header ANSI C library that runs transformer inference, sentence embeddings and on-device learning with no external dependencies at all.
- Status
- Active development
- Role
- Sole author
- Built with
- C, WebAssembly, TypeScript
- Licence
- Apache-2.0
- DOI
- 10.5281/zenodo.20432307
- Source
- github.com/fkkarakurt/Nerve
- Updated
Nerve is an AI stack in one C file. It depends on nothing but the C standard library and
libm.
gcc -O2 main.c -o main -lm
That is the whole build. No package manager step, no BLAS to locate, no version matrix to reconcile — which is the point.
What is documented, and what is in the repositoryPermalink to “What is documented, and what is in the repository”
These are worth separating, because only one of them has a permanent identifier attached.
The technical reference manual (version 1.0, May 2026) documents the neural network core: forward propagation, backpropagation and mean-squared-error loss; SGD with momentum and Adam; Xavier/Glorot and He initialisation; four activation functions; L2 regularisation and dropout. It is archived on Zenodo under CC-BY-4.0 and is the citable description of the library.
The repository has gone further than the manual. It adds transformer inference — with RMSNorm, rotary position embeddings (RoPE), grouped query attention (GQA) and int8 quantisation — sentence embeddings through a MiniLM-style BERT encoder of around 22 MB, and a WebAssembly build distributed as a JavaScript/TypeScript npm package. The README reports TinyLlama-1.1B running on a 2017 laptop CPU, a 65 KB WebAssembly module, and personalised fine-tuning steps in roughly 40 ms.
If you are citing Nerve, cite the manual and state the version. If you are relying on the transformer path, read the source: it is ahead of the document.
Reference resultsPermalink to “Reference results”
From the documented core, on standard small benchmarks:
| Task | Network | Result |
|---|---|---|
| MNIST | 784-128-10 | ~97% |
| Iris | — | 96.7% test accuracy |
| Three-class spiral | — | 98.3% |
On optimiser behaviour, Adam converges about 10× faster than SGD on XOR, and about 18.7× on a four-class identity task.
DeterminismPermalink to “Determinism”
Randomness comes from a xoshiro128** generator carried inside the library rather than
from the platform. Two runs of the same program with the same seed produce the same
weights on any target, including WebAssembly.
This is the same requirement that drives everything else here and in
KATAI 2D: a result that cannot be reproduced is not a result. It is
why the library carries its own generator instead of calling rand(), and why the
numerical path avoids anything whose ordering is left to the runtime.
Design positionPermalink to “Design position”
The library is written to be read. It trades peak throughput for a code path an engineer can follow end to end — small enough to read in an afternoon, correct enough for real work. Where a choice existed between a faster kernel and a legible one, the legible one is in the file.
That trade is defensible for the same reason it is defensible in engineering software generally: a program nobody can follow is a program nobody can check.
Licence, source and citationPermalink to “Licence, source and citation”
The software is Apache-2.0; the manual is CC-BY-4.0. Source at github.com/fkkarakurt/Nerve.
Küçükkarakurt, F. (2026). Nerve: Technical Reference Manual — A Zero-Dependency Single-Header Multilayer Perceptron Library for ANSI C (Version 1.0). Zenodo. https://doi.org/10.5281/zenodo.20432307