A minimal scalar-valued autograd engine with neural network primitives, built for learning purposes. Inspired by micrograd.
pip install learngradValue— scalar with automatic differentiation via backpropMLP— multi-layer perceptron built on top ofValue- Optimizers —
SGD,SGDMomentum,RMSProp,Adam
from learngrad.engine import Value
from learngrad.nn import MLP
from learngrad.optimizers import Adam
# Autograd
x = Value(2.0)
y = x ** 2 + x * 3
y.backward()
print(x.grad) # dy/dx = 2x + 3 = 7.0
# Neural net
model = MLP(2, [4, 4, 1])
opt = Adam(model.parameters(), lr=1e-3)
x = [Value(1.0), Value(0.5)]
out = model(x)
out.backward()
opt.step()notebooks/demo.ipynb walks through a full training example:
- Binary classification on the
make_circlesdataset - MLP with hinge loss and L2 regularization
- Mini-batch training loop with Adam
- Train/val accuracy tracking
- Decision boundary visualization
Reaches ~94% val accuracy in 100 epochs.
- Python >= 3.10
- numpy
pip install -e ".[test]"
pytestEvery operation's backward pass is checked against a finite-difference gradient, and each optimizer is checked to fit a simple linear model.