live · trainable · in your browser

What is a neural network?

This is not a diagram — it's a real 2-4-4-1 network running in JavaScript. Slide the inputs and watch activations flow left to right (glow = value, strut thickness = weight, orange = positive, blue = negative). Then hit Train and watch gradient descent learn XOR in front of you.

Output ŷ
drag to orbit · pinch / scroll to zoom

Feed the network

Train it — real gradient descent

MSE loss · 0 epochs
x₁x₂targetpredictionverdict

Neurons & weights

A neuron is embarrassingly simple: it multiplies each input by a weight, adds a bias, then squashes the result through an activation function:

a = f( w₁x₁ + w₂x₂ + … + b )

Weights are the network's memory — everything it "knows" lives in these numbers. This little network has just 37 parameters (weights + biases). GPT-class models have hundreds of billions, but the neuron math is the same.

Activation functions

Without a nonlinearity, stacked layers collapse into one big linear function — no curve-fitting power. The classics:

σ(z) = 1 / (1 + e⁻ᶻ) → (0, 1)
tanh(z) = (eᶻ−e⁻ᶻ)/(eᶻ+e⁻ᶻ) → (−1, 1)
ReLU(z) = max(0, z)

ReLU dominates deep learning because its gradient doesn't vanish for positive z — try it above and compare how fast the loss falls (you may need a lower η; ReLU can be twitchy on tiny nets).

Training = backpropagation

Each Train step does exactly this, no magic: 1) forward pass on all 4 XOR examples; 2) measure error with mean-squared-error loss L = ½(ŷ−y)²; 3) use the chain rule to compute ∂L/∂w for every weight — walking the error backwards layer by layer; 4) nudge every weight downhill:

w ← w − η · ∂L/∂w

XOR is the famous test case: it's not linearly separable, so a network needs a hidden layer to solve it — the 1969 observation that stalled neural nets until backprop revived them in 1986.

Enjoy this tool? Build your own with Super