The neural network that mixed up digits: it answered with a file number
In 2004, in my second year at the University of Latvia, we had a course on neural networks. The assignment was to build something with a neural network, and I wrote a digit classifier. In C++ Builder and from scratch: my own neuron class, my own network, training by backpropagation.
I drew the digits myself, in 7×7 text files: X for filled, a dot for empty. This is what the five looked like:
XXXXXXX
X......
X......
XXXXXXX
......X
......X
XXXXXXX
Each digit sat in a file named after it, 0, 1, 2…, and other ways of drawing it in files 0a, 0b, 2a and so on.
I didn’t wire the network up any old way, but in layers that meant something. The input was 49 pixels. In the first hidden layer each neuron looks at its own pixel and its four neighbours in a cross. In the second come “line” neurons: each one sees a whole row or a whole column of the picture. Then a layer where every neuron is connected to every other, and at the output ten neurons, one per digit. A sigmoid, backpropagation with momentum, a learning rate that slowly goes down, and fifteen hundred epochs. At the end the program took the file test, printed the values of all ten outputs and gave its verdict: “I think it is …”, followed by “Sure” or “Not sure” with a confidence percentage.
And that’s where things got strange. I draw a five, the network says “four”. I draw another digit, and the answer is off again. The answers weren’t random; they looked shifted. The teacher looked at the code, at how the network was built and trained, and said: “Looks all correct.” And gave me a 10, the top mark, for the course.
The next day it dawned on me. The network wasn’t giving me a digit but a file number: the position of the sample in the list it had learned from. If some files are taken out of the list, or it has extra variants like 0a and 0b, the number and the digit drift apart. You can see it in the sources that survived: for every sample the program prints Pattern: N, where N is its place in the list. In one of the versions the file with the one was commented out, and the five stood in the list at number 4.
The network worked correctly. I was reading its answer wrong.
More than twenty years later I rebuilt those sources and checked. In the version where the one is commented out, the five really is printed under the heading Pattern: 4, even though the network’s “5” output is 0.96 and the rest are close to zero. The final version recognises all ten digits it learned from correctly. On drawings it hadn’t seen, though, it sometimes slips: it takes a different three for an eight.
What I took from it: a model can work while the system around it doesn’t, if the mistake is in how the answer is read. Before fixing the model, check what exactly you print and how you understand it.