Neural-Engine: a neural network from first principles
A neural network and autograd engine in about 200 lines of plain Python, with no libraries. It learns XOR, and it ships with lessons, gradient checks and an interactive guide so you can watch backpropagation happen.
- ~200lines of Python
- 0dependencies
- 2runnable lessons
- XORlearned from scratch
Open the interactive guide (opens in new tab) · Source on GitHub (opens in new tab)
Why build it
Frameworks like PyTorch hide the part that matters most: how a network actually learns. Neural-Engine rebuilds that part with nothing but Python, so every number can be traced from the input to the loss and back.
How it works
- A
Valuegraph: every arithmetic operation records its inputs, so the engine can walk the graph backwards and apply the chain rule. That’s automatic differentiation. - Neuron → Layer → MLP: a neuron weighs its inputs, adds a bias and squashes the result with
tanh. Layers of neurons stack into a multi-layer perceptron. - Training loop: forward pass, loss, backward pass, then gradient descent, the update at the heart of all training:
weight = weight - learning_rate * gradient
Learning path
python3 lessons/01_what_is_a_gradient.py
python3 lessons/02_backprop_by_hand.py
python3 test_engine.py # gradient checks: prove it works
python3 train.py # learn XOR
The interactive guide
The guide is a single page where you drag sliders on a neuron, roll a ball down a loss curve, try learning rates from “too small” to “blows up”, step through backpropagation and watch a network learn XOR live.
What it shows
I build production AI systems on top of LLM APIs, and I want to understand what is underneath them. This project is the foundation: gradients, backpropagation and optimisation, written so someone else can learn them too.