BeginnerCoder

Lesson 25 — Ultimate: tiny neural net

Boss level: a neural network that solves XOR

A neural network stacks layers. Each neuron computes a weighted sum of its inputs plus a bias, then applies an activation function. ReLU is the most common: relu(z) = max(0, z). Computing the output from the inputs is the forward pass.

XOR ("one or the other, not both") is famous because no single straight line can separate it — a hidden layer is needed. With these hand-picked weights: h1 = relu(x1 + x2), h2 = relu(x1 + x2 − 1), output = h1 − 2 × h2.

relu(-0.5)   # 0
relu(1.5)    # 1.5

Why it matters: every deep-learning model, up to large language models, is this forward pass — just with billions of weights that were learned instead of hand-picked.

Want it another way?
Task

Finish forward(): compute h1 and h2 with relu, then out = h1 - 2 * h2. The table should match XOR.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.

Keep going with AI / ML Foundations

Ready for more? Optional paid resources that pick up where this lesson leaves off.

Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.