Happy or not? Teach a neural network to read faces

100 inputs (a 10×10 picture) → 8 hidden neurons → 1 output, the same kind of network as Pick Activity and Tic-Tac-Toe. This time there are no rules and no perfect player to copy. You make the training data: pick the faces you think are happy, and the network learns your definition. Then we test it on faces it has never seen. New in this one: a second model, convolutional, that slides a few tiny filters across the picture instead of wiring every pixel to every neuron.

1 · Pick the happy faces

Press every face you'd call happy. Everything you pick becomes a training example labeled happy; faces you skip become not happy. Pick a handful, not all of them: some happy faces must stay unpicked so we have unseen ones to test on. Arrow keys move between faces, Space or Enter picks.

0 picked

2 · Split the data, then train

Finish step 1 first. When you press Done picking, the faces are split into a training set (what the network learns from) and a test set (faces it never sees until the exam).

3 · The exam: faces it has never seen

Finish steps 1 and 2. Every face here is one the network was not trained on, so this is the real measure of whether it learned “happy” or just memorized your picks.

4 · Draw a face, see what it thinks

Click or drag to paint pixels. This face is only for testing: it never goes into the training set. Arrow keys move, Space toggles. The arrows under the grid slide the whole drawing so you can see how position changes the verdict; nothing is lost off the edge.

not shifted

Network says

—

Try it: start from a random happy face and erase one corner of the mouth. Draw a mouth with no eyes. Draw just the eyes. Scribble. Where does your definition of happy and the network's come apart?

Where the training faces live: the generator puts eyes around rows 3–4 and the mouth on rows 7–9, and slides faces left or right but never up or down. Draw a smile two rows higher and the network has never seen a mouth on those pixels. A plain fully connected network has no idea that the same shape in a different place is the same thing: every pixel is a separate input. Turn up shifted copies in step 2 and retrain to see how much, and how little, that helps this model. Then switch to Convolutional and retrain: one small filter slid across the whole picture, so a mouth corner is a mouth corner wherever it is, and with shifted copies it handles most positions.

Things to notice: the network can score 100% on the training faces and still miss on the exam. If you only picked faces with big grins, narrow smiles may fail. Junk gets a confident answer either way. Draw a smile two rows too high and the fully connected model fails, with or without shifted copies; the convolutional model usually handles it, and with copies shifted up to 3 it handles most positions. And the Show the network picture tells you which pixels each hidden neuron is watching: usually the mouth corners.

Inside the network, right now