← Lesson
A Tiny Neural Net
Joeven
Run
Reset
Python loads on first run
def dot(a, b): return sum(x * y for x, y in zip(a, b)) def matvec(W, x): return [dot(row, x) for row in W] def relu(xs): return [max(0.0, v) for v in xs] # Hand-set weights that fire only when both inputs are large W1 = [ [1.0, 0.0], [0.0, 1.0], ] b1 = [-0.5, -0.5] W2 = [[1.0, 1.0]] b2 = [-0.5] def forward(x): h = relu([z + b for z, b in zip(matvec(W1, x), b1)]) y = [z + b for z, b in zip(matvec(W2, h), b2)] return h, y[0] for x in ([0.0, 0.0], [1.0, 0.0], [0.0, 1.0], [1.0, 1.0]): h, y = forward(x) print("x", x, "hidden", h, "y", y, "fire" if y > 0 else "quiet")
Run to execute this in your browser. Nothing is sent to a server.