In 1958 Frank Rosenblatt showed off the perceptron, a machine that learned from examples. It was a big deal. Then people noticed a tiny problem it could not solve, and that problem had only four rows.
Here is the whole perceptron in NumPy. It is the first thing you build in my book.
def perceptron(X, y, epochs=20): """Learn a line that separates two classes. Labels must be -1 or +1.""" w, b = np.zeros(X.shape[1]), 0.0 for _ in range(epochs): mistakes = 0 for xi, yi in zip(X, y): if yi * (xi @ w + b) <= 0: # wrong side of the line w += yi * xi # nudge the line toward xi b += yi mistakes += 1 if mistakes == 0: break return w, b That's it. Look at each example. If it's on the wrong side of the line, nudge the line toward it. Repeat until nothing is wrong.
Give it AND:
AND = (np.array([[0, 0], [0, 1], [1, 0], [1, 1]]), np.array([-1, -1, -1, 1])) After training (100 epochs max) it lands on weights [3, 2] and bias -4, and gets 4 out of 4 right. One straight line splits "both on" from everything else.
Now give it XOR, which is "on when exactly one input is on":
XOR = (np.array([[0, 0], [0, 1], [1, 0], [1, 1]]), np.array([-1, 1, 1, -1])) It ends with weights [0, 0] and bias 0, and gets 2 out of 4 right. That's a coin flip.
It isn't a bug. Draw the four points. The two "on" points sit on one diagonal, the two "off" points on the other. No single straight line can put both diagonals on different sides. The perceptron can only draw one line, so it keeps nudging forever and goes nowhere.
The fix turned out to be layers: stack a few of these units, add a bend (a nonlinearity) between them, and you can carve the plane into shapes, not just halves. But to train layers you need to know how much each weight is to blame for the error, which is backpropagation. That took years to catch on, and it's the reason the next chapters exist.
Why I like starting here: every big model today is still, at the bottom, weighted sums and nudges. If you've seen a single line fail on four points, attention and transformers feel a lot less like magic.
All the code is free and tested on GitHub: https://github.com/AlwyAbdullah/the-whole-machine
It comes from my book The Whole Machine, which goes from this perceptron all the way to agents: https://leanpub.com/thewholemachine/c/devto
I wrote this post with help from an AI assistant. The code and numbers come from my book's repo, where each one is checked by a test.
