Besley’s Lab
← All labs

Interactive notebook

A Net Learns XOR

The moment a hidden layer invents the feature that makes the problem linear.

Not linearly separable — needs the hidden layer.

The network

x1x2h1h2ŷinputshidden (tanh)output (σ)

Edge thickness = |weight|. Red is positive, blue negative.

What it computes

A color map of the network's output probability across both inputs.

Loss

epoch 0loss 0.7794accuracy 50%

Truth table

Current predictions for every input pair
x₁ x₂targetpredictedresult
0 000.641
0 110.745
1 010.619
1 100.732

Press Run. Watch the hidden-layer weights first: nothing much happens, then suddenly everything does.

XOR is the classic proof that one layer isn’t enough: no single straight line separates (0,1) and (1,0) from (0,0) and (1,1). The two hidden units each learn a line, and the output unit combines them — which is why the finished decision surface has a corner in it. Try a few different random inits: some runs solve it in a few hundred epochs, some stall for thousands, and that variance is a real property of training, not a bug in the demo.