Day 2 Quest
Training Golem: One Gradient Step
Quest: How does the furnace know which way to nudge a weight?
Today Craft Lab became a real adventure.
Franklin can walk the overworld with WASD (or the on-screen joystick), find the Training Golem, and help it learn.
Yesterday Bolt could guess. Today he learns how to change a weight so the guess gets better.
If I make the power bigger, does the Golem get closer?
Craft Lab World Β· Day 2 quest
CRAFT LAB WORLD
Desktop: WASD / arrows. Touch: joystick. Walk to the Training Golem.
Franklin Track
The Golem wants POWER 10.
His brain uses one rule:
prediction = input Γ weight
The input (signal) is stuck at 2. Only the weight can change.
- Walk to the Training Golem.
- Press + / β on the power weight.
- Watch the bar. Too low? Raise the weight. Too high? Lower it.
- When error is about zero: you found the good direction by feel.
- Then hit AUTO TRAIN. The Golem does the same idea automatically, step by step.
That automatic nudge is called gradient descent.
Dad Track
Squared-error loss for one example:
prediction = input * weight
error = prediction - target
loss = errorΒ²
gradient = d(loss)/d(weight) = 2 * error * input
weight := weight - learning_rate * gradient
Pencil check with our defaults (input=2, weight=0.5, target=10, lr=0.05):
| Quantity | Value |
|---|---|
| prediction | 1.0 |
| error | β9.0 |
| gradient | β36 |
| new weight | 2.3 |
About a dozen more steps and prediction sits on the target. No PyTorch. Roughly fifteen lines of Python.
Franklin's Question
Is the gradient like a sign that says "go this way"?
Yes. The sign of the gradient tells the furnace which way to nudge. The learning rate says how big the nudge is.
Could Franklin explain it back?
"A weight is how much the computer cares. The gradient tells it which way to change the care so the mistake gets smaller."
Scientific method (tiny)
- QUESTION β Does AUTO TRAIN reach the target from a bad starting weight?
- HYPOTHESIS β Yes, if learning rate is small enough.
- EXPERIMENT β Run 14 gradient steps from weight 0.5.
- CONTROL β Same input (2) and target (10).
- MEASUREMENT β Absolute error
|prediction β target|. - RESULT β Error falls toward zero (watch the quest bar).
- CONCLUSION β Gradient descent works on this toy problem.
- NEXT QUESTION β What if learning rate is huge? (EXP-001 later.)
Item crafted
Item crafted!
Learning Crystal
Glows brighter as error shrinks. Proof that one weight can learn by walking downhill.
- Gradient Sight I
- Learning Rate I
Achievement Get!
First Gradient
The command block
day02_gradient.py"""
Day 2: one gradient update by hand (squared error).
prediction = input * weight
error = prediction - target
gradient = 2 * error * input
weight = weight - learning_rate * gradient
Pencil check with defaults:
input=2, weight=0.5, target=10, lr=0.05
prediction = 1.0
error = -9.0
gradient = 2 * (-9) * 2 = -36
new weight = 0.5 - 0.05 * (-36) = 0.5 + 1.8 = 2.3
"""
INPUT = 2.0
WEIGHT = 0.5
TARGET = 10.0
LR = 0.05
prediction = INPUT * WEIGHT
error = prediction - TARGET
gradient = 2 * error * INPUT
new_weight = WEIGHT - LR * gradient
print(f"prediction = {prediction}")
print(f"error = {error}")
print(f"gradient = {gradient}")
print(f"new weight = {new_weight}")
print("\nAuto train (12 steps):")
w = WEIGHT
for step in range(1, 13):
pred = INPUT * w
err = pred - TARGET
grad = 2 * err * INPUT
w = w - LR * grad
bar = "#" * min(10, int(round(pred))) + "." * max(0, 10 - int(round(pred)))
print(f"Step {step:2d} [{bar}] pred={pred:.2f} w={w:.4f}")
python3 content/lab/days/day-002/day02_gradient.pyNo packages. Reproduce the first update with pencil and paper, then let Python check you.
Dad's Lab Notes (tap to open)
- Wanted to learn
- Understand one furnace tick: loss, gradient, learning rate, weight update.
- Learned
- Gradient descent is walking downhill on error. prediction = input Γ weight; gradient = 2 Γ error Γ input; weight -= lr Γ gradient. Manual feel first, then AUTO TRAIN.
- Built
- Playable Craft Lab world (WASD + joystick), Training Golem quest, ~15-line gradient script, Learning Crystal item, Redstone Heart golem part.
- Confused me
- Why multiply by input again in the gradient? (Chain rule: prediction depends on weight through input.)
- Failed
- Nothing broken. A huge learning rate would overshoot; we kept lr=0.05 on purpose.
- Taught Franklin
- Franklin trained by feel (+/β weight), then watched AUTO TRAIN. His words: gradient is the sign that says which way to change the care.
- Tomorrow
- Apply the same update many times to the full play-outside neuron, not just one toy weight.
Tomorrow
Day 3: train the neuron ourselves step-by-step. Multiple furnace ticks, still no framework.
