
Training Neural Networks
by marimo team
A notebook that trains a tiny neural network with Andrej Karpathy's micrograd
About this notebook
This notebook trains a small neural network with Andrej Karpathy's micrograd library, which implements automatic differentiation with plain Python scalar operations. The data comes from scikit-learn's make_moons function: 100 two-dimensional points in two interleaved half-moons, labeled +1 or -1. A matplotlib scatter plot shows the points, and the network must learn a nonlinear boundary that separates the two classes. The notebook adapts Karpathy's own micrograd demo.
Sliders control the number of layers (one or two), the size of each layer, and the number of gradient steps. The notebook waits until you click the Train button, then builds a micrograd MLP with your settings and trains it while a marimo progress bar shows each step. When training ends, a contour plot draws the learned decision boundary over the data points, so you can compare architectures by eye.
Training minimizes an SVM max-margin loss with L2 regularization and uses plain stochastic gradient descent with a decaying learning rate. The notebook runs in WebAssembly: when it detects Pyodide, it installs micrograd with micropip, so the whole thing executes in your browser.











