Page 3 of 8~112 min topic

Neural nets by building

Build the first working single-neuron trainer

Page 3 implements the shortest complete path for the single-neuron logic-gate trainer with inspectable intermediate values.

~14 min this pageImplementation

1Learn the idea

Read

Implement the minimal working path

Build only what the claim requires: after training, AND (or OR) inputs map to the expected 0/1 outputs. Prefer boring, deterministic code over frameworks you cannot yet explain. Run the path twice; identical output on this fixture is a feature, not a lack of creativity.

Read

Run the working path

import math
samples=[((0,0),0),((0,1),1),((1,0),1),((1,1),1)]; w=[0.,0.]; b=0.
for _ in range(2000):
 for x,y in samples:
  p=1/(1+math.exp(-(w[0]*x[0]+w[1]*x[1]+b))); e=p-y
  w=[w[j]-.2*e*x[j] for j in range(2)]; b-=.2*e
print([round(v,2) for v in w],round(b,2))

Expected evidence: two positive weights and a negative bias. Read each printed intermediate as part of the argument that the path works—not as decoration.

Read

Trace one input end to end

Narrate the journey from raw input to result for a single example from AND gate truth table. If you cannot name an intermediate, the implementation is still too opaque for this lab. Only after this path is solid should you generalize data sources or UI.

Read

Lab notebook: intermediates worth printing

While implementing the single-neuron trainer, print or log at least three intermediates that map to the claim (after training, AND (or OR) inputs map to the expected 0/1 outputs). Good intermediates are values a teammate could recompute with a calculator or diff. Bad intermediates are framework traces you cannot explain.

Re-run with AND gate truth table twice. If the second run differs, either the path is nondeterministic (document the seed) or you have hidden global state—both are lab bugs until named.

Read

Worked judgment

Stop adding features once the path supports learn weights for a linearly separable gate by gradient steps you can print. Extra UI, extra tools, or extra models belong in later chapters. The mastery bar for this page is simply: a deterministic end-to-end path with intermediates.

Read

Why this stage matters for the single-neuron trainer

At the implementation stage for neural-nets-by-building, the job is narrower than finishing a product demo. You are creating one progressive evidence piece about AND gate truth table that later pages inherit without redefining success. Keep that fixture small enough to inspect by hand, keep outputs copy-pasteable as text, and refuse to narrate this baseline as if it were a production SLA: untrained weight predictions on the gate table.

For this page specifically, success looks like a deterministic path with printed intermediates while still centering the user decision to learn weights for a linearly separable gate by gradient steps you can print. If you cannot point to a file, command, or assertion that proves that for the single-neuron trainer, stay on this page instead of advancing.

Glossary: deep learning · Glossary: gradient descent

Previous · Next

Go deeper

Before you start

Why this matters

Without running code, predict the final output for fixture AND gate truth table. Name one intermediate value that would prove the prediction. Then answer: what could look successful while actually being wrong at this stage for the single-neuron trainer?

Check your understanding

Page assessment

Answer from memory. Completion is saved from this evidence, not from opening the next page.

1. Can you narrate every intermediate value?
2. Is the fixture deterministic and independently inspectable?
3. Did you avoid framework behavior you cannot explain yet?
4. Does the output still support the decision: learn weights for a linearly separable gate by gradient steps you can print?

All responses are required.