FIG. 02 · Live

Neural Network Autograd Lab

A real scalar autograd engine, written in TypeScript, drives both modes. Every number on screen is computed by reverse-mode differentiation and checked against finite differences.

  • autograd
  • MLP
  • tanh
  • SGD

All computation happens on this device. Text you type is never uploaded.

Inputs and parameters

FIG. 02.1
o
—
Loss L
—
Gradient check
— —

Computational graph

FIG. 02.2

Each node shows its value (top) and the gradient of the loss with respect to it (bottom).

Chain rule, step by step

FIG. 02.3

Forward pass

    Backward pass

      Update (gradient descent)

        Loss after each step

        FIG. 02.4

        How it works

        Methodology

        1. Every arithmetic operation creates a Value node that remembers its inputs and a small closure describing its local derivative.
        2. Calling backward() sorts the graph topologically, seeds the output gradient with 1 and walks the nodes in reverse, applying the chain rule once per edge.
        3. The playground trains a multilayer perceptron with full-batch gradient descent on mean squared error, with labels of +1 and −1 and a tanh output.
        4. A live gradient check compares every analytic gradient with a central finite difference; the unit tests require agreement within 1e−5 for every operation and every network size.

        The engine follows the design of Andrej Karpathy’s micrograd (MIT licence).