Skip to content
Zogle

← Articles

Research

Neural Networks From Zero: Two Tiny Examples, Every Step Explained

Two tiny neural networks worked by hand: one neuron learning y = 2x, and a 2-2-1 network doing one full forward and backward pass. Every number is shown.

By Shashank R AlurUpdated 5 min read

On this page

Problem

Most neural network explanations either stay abstract or jump straight to huge models. This article does the opposite. We take two tiny networks and compute every single number by hand, so you can see exactly what "learning" means.

  • Example 1: one neuron learns the rule y = 2x.
  • Example 2: a small network does one full forward and backward pass.

Theory

A neural network is a function with adjustable numbers (weights). Training is a loop of four steps:

  1. Forward: put an input in, get a prediction out.
  2. Loss: measure how wrong the prediction is.
  3. Backward: work out how much each weight contributed to the error (the gradient).
  4. Update: nudge each weight in the direction that reduces the error.

The update rule is one line:

wnew=wold−lr⋅∂L∂ww_{new} = w_{old} - \text{lr} \cdot \frac{\partial L}{\partial w}

lr (learning rate) controls the step size. The gradient tells us which direction reduces the loss, and why that direction is correct: the gradient is the slope of the loss, so moving against the slope goes downhill.

Architecture

Example 1: one weight, no bias, no activation.

text
x ──(× w)──> ŷ        loss = (ŷ − y)²

Example 2: 2 inputs → 2 hidden neurons → 1 output, with sigmoid everywhere.

text
x1 ─┬─> h1 ─┐
    │       ├─> ŷ
x2 ─┴─> h2 ─┘

Sigmoid squashes any number into 0–1: σ(z)=11+e−z\sigma(z) = \frac{1}{1+e^{-z}}, and its slope is σ(z) (1−σ(z))\sigma(z)\,(1-\sigma(z)).

Implementation

Example 1: learning y = 2x

Data: x = 1, y = 2. Start with w = 0, lr = 0.1.

The gradient is ∂L∂w=2(y^−y) x\frac{\partial L}{\partial w} = 2(\hat y - y)\,x.

Stepwŷ = w·xerror (ŷ − y)gradientnew w
10.0000.000−2.000−4.0000.400
20.4000.400−1.600−3.2000.720
30.7200.720−1.280−2.5600.976
40.9760.976−1.024−2.0481.181

Each step cuts the error by 20% (it gets multiplied by 1 − 2·lr·x² = 0.8). That's why w creeps toward 2 and never overshoots. A bigger lr would cut faster, but at lr = 1.0 the factor becomes −1 and the weight would bounce back and forth forever.

Example 2: one full pass through a 2-2-1 network

Input x = (1, 0), target y = 1. Starting weights (biases are 0 to keep it readable):

  • Hidden: w11 = 0.5, w12 = −0.3 (for h1), w21 = 0.8, w22 = 0.2 (for h2)
  • Output: v1 = 0.6, v2 = −0.4

Forward

  • z1 = 0.5·1 + (−0.3)·0 = 0.5 → h1 = σ(0.5) = 0.6225
  • z2 = 0.8·1 + 0.2·0 = 0.8 → h2 = σ(0.8) = 0.6900
  • z = 0.6·0.6225 + (−0.4)·0.6900 = 0.0975 → ŷ = σ(0.0975) = 0.5244
  • Loss = ½(ŷ − y)² = ½(−0.4756)² = 0.1131

Backward (chain rule, going from the output back to the inputs)

  • Output delta: (ŷ − y) · ŷ(1−ŷ) = −0.4756 · 0.2494 = −0.1186
  • Output weight gradients: v1: −0.1186 · 0.6225 = −0.0738, v2: −0.1186 · 0.6900 = −0.0818
  • Hidden deltas (send the output delta back through v, then through the sigmoid slope):
    • h1: −0.1186 · 0.6 · 0.2350 = −0.0167
    • h2: −0.1186 · (−0.4) · 0.2139 = +0.0101
  • Hidden weight gradients = hidden delta × input. Since x2 = 0, the weights w12 and w22 get gradient 0. An input of zero can't have caused any of the error.

Update (lr = 0.5)

  • v1: 0.6 → 0.637, v2: −0.4 → −0.359
  • w11: 0.5 → 0.508, w21: 0.8 → 0.795

Forward again with the new weights: ŷ = 0.5375, loss = 0.1069.

The loss dropped from 0.1131 to 0.1069 after a single update, and the prediction moved toward the target of 1.

Experiments

We ran both examples as code and compared them with the hand calculations. Example 1 was trained for 20 steps. Example 2 was trained for one step by hand, then for 2000 steps in code.

python
import numpy as np

# Example 1
w, lr = 0.0, 0.1
for step in range(20):
    pred = w * 1
    grad = 2 * (pred - 2) * 1
    w -= lr * grad
print(round(w, 4))

# Example 2
sig = lambda z: 1 / (1 + np.exp(-z))
x, y = np.array([1., 0.]), 1.
W = np.array([[0.5, -0.3], [0.8, 0.2]])
v = np.array([0.6, -0.4])

for step in range(2000):
    h = sig(W @ x)
    yhat = sig(v @ h)
    d_out = (yhat - y) * yhat * (1 - yhat)
    d_hid = d_out * v * h * (1 - h)
    v -= 0.5 * d_out * h
    W -= 0.5 * np.outer(d_hid, x)
print(round(yhat, 4))

Results

  • Example 1: w goes 0 → 0.4 → 0.72 → 0.976 → 1.181 …, and reaches about 1.99 after 20 steps.
  • Example 2: the hand calculation matches the code. After one update, loss goes 0.1131 → 0.1069.
  • Example 2, 2000 steps: ŷ gets very close to 1.

Lessons Learned

  • Learning is only "measure the error, nudge the weights." There's no magic step beyond that.
  • Gradients tell you who to blame. A weight attached to a zero input gets zero gradient.
  • Backprop is the chain rule applied layer by layer, reusing each layer's delta for the layer before it.
  • Learning rate matters. Too small is slow, too large overshoots. Try changing lr in the code and watch what happens.
  • Next step: add more training examples, which lets the same network learn XOR.

Results & Reproducibility

  • Python 3, NumPy only. No GPU needed; runs in well under a second.
  • Check: Example 1 should print about 1.99. Example 2's first-step loss should be 0.1131, then 0.1069.
  • All numbers in the article were computed by hand and cross-checked with the code.

Tags: neural networks, backpropagation, gradient descent, fundamentals, from scratch

Written by

Shashank R Alur

AI engineer exploring the foundations of machine learning, language models, and high-performance AI systems.

Cite this article

Shashank R Alur. "Neural Networks From Zero: Two Tiny Examples, Every Step Explained." Zogle, Oct 2026. https://zogle.org/research/neural-networks-from-zero-two-tiny-examples-every-step-explained

@article{alur2026neural,
  author = {Shashank R Alur},
  title = {Neural Networks From Zero: Two Tiny Examples, Every Step Explained},
  journal = {Zogle},
  year = {2026},
  url = {https://zogle.org/research/neural-networks-from-zero-two-tiny-examples-every-step-explained}
}

Keep reading