The Math Behind a Tiny Classifier
Sixteen pixels, three shapes, one dot product.
A picture is just a vector.
We encode each 4×4 image as a sixteen-dimensional vector,
$$\mathbf{x} \;\in\; \{-1, +1\}^{16},$$reading the grid row by row. We let $x_i = +1$ when pixel $i$ is on, and $x_i = -1$ when it is off. Each of the three shapes lives in the same space as a fixed template:
$$\mathbf{w}_\triangle, \quad \mathbf{w}_\square, \quad \mathbf{w}_\circ \;\in\; \{-1,+1\}^{16}.$$These are the network's only memory of what triangles, squares, and circles look like — three points scattered somewhere on a 16-dimensional hypercube.
How well does an input match a template?
We take the inner product:
$$s_k(\mathbf{x}) \;=\; \langle \mathbf{x},\, \mathbf{w}_k \rangle \;=\; \sum_{i=1}^{16} x_i\,(w_k)_i.$$That is the whole model. No nonlinearity, no hidden layer, no bias. Each individual term in the sum is either $+1$ or $-1$,
$$x_i (w_k)_i \;=\; \begin{cases} +1 & \text{pixel } i \text{ agrees with the template,} \\ -1 & \text{pixel } i \text{ disagrees.} \end{cases}$$So the score is simply (agreements) minus (disagreements), an integer ranging from $-16$ to $+16$. A perfect match scores $+16$; the bitwise opposite scores $-16$.
The dot product is Hamming distance in disguise.
Let $d_H(\mathbf{x}, \mathbf{w})$ count the pixels at which $\mathbf{x}$ and $\mathbf{w}$ disagree. A short calculation gives
$$s_k(\mathbf{x}) \;=\; 16 \;-\; 2\,d_H(\mathbf{x},\, \mathbf{w}_k).$$Maximizing the dot product is the same as minimizing the Hamming distance. The "neural" classifier is — secretly — a nearest-neighbour classifier on the hypercube.
This is reassuring. The model is doing exactly what we'd hope it was doing: comparing your drawing to each prototype and picking the one closest to it.
And then we argmax.
The predicted class is whichever template wins the most agreements:
$$\hat{y}(\mathbf{x}) \;=\; \underset{k\,\in\,\{\triangle,\,\square,\,\circ\}}{\arg\max}\; s_k(\mathbf{x}).$$The boundary between two classes — the set of inputs on which the model is honestly torn — is given by the equation $s_i(\mathbf{x}) = s_j(\mathbf{x})$, which rearranges to
$$\langle \mathbf{x},\; \mathbf{w}_i - \mathbf{w}_j \rangle \;=\; 0.$$A hyperplane through the origin, orthogonal to the difference of the two templates. Our three templates carve $\mathbb{R}^{16}$ into three convex regions, separated by three such hyperplanes meeting at a shared axis.
One product does all the work.
If we stack the three templates as the rows of a matrix,
$$W \;=\; \begin{bmatrix} \,\rule[0.5ex]{1.4em}{0.5pt}\; \mathbf{w}_\triangle^{\!\top}\; \rule[0.5ex]{1.4em}{0.5pt}\, \\ \,\rule[0.5ex]{1.4em}{0.5pt}\; \mathbf{w}_\square^{\!\top}\; \rule[0.5ex]{1.4em}{0.5pt}\, \\ \,\rule[0.5ex]{1.4em}{0.5pt}\; \mathbf{w}_\circ^{\!\top}\; \rule[0.5ex]{1.4em}{0.5pt}\, \end{bmatrix} \;\in\; \mathbb{R}^{3 \times 16},$$then all three scores fall out of a single matrix–vector multiplication:
$$\mathbf{s} \;=\; W\mathbf{x}, \qquad \hat{y} \;=\; \arg\max_k s_k.$$That is the complete classifier. Three rows, sixteen columns, one product, one $\arg\max$.
From scores to probabilities.
When we want a confidence and not merely a winner, we feed the scores through the softmax,
$$p_k \;=\; \frac{e^{\,s_k}}{\displaystyle \sum_{j} e^{\,s_j}},$$which preserves the ranking but converts gaps into exponential preference. A two-point lead becomes a factor of $e^{2} \approx 7.4$ in odds; a six-point lead, more than four hundredfold.
Where the templates come from.
In the Visualizer the three templates are drawn by hand. In a real classifier nobody does this — the templates are learned.
Given training data $\mathcal{D} = \{(\mathbf{x}^{(n)},\, y^{(n)})\}_{n=1}^{N}$, define a loss measuring how often the model is wrong (cross-entropy is the usual choice),
$$\mathcal{L}(W) \;=\; -\sum_{n=1}^{N} \log p_{\,y^{(n)}}\!\bigl(\mathbf{x}^{(n)}\bigr),$$and descend it:
$$W \;\leftarrow\; W \;-\; \eta\, \nabla_{\!W}\, \mathcal{L}.$$The templates that emerge from this process will not look like clean drawings of shapes. They look like soft, ghostly averages — each pixel of $\mathbf{w}_k$ positive in regions where class $k$ tends to be lit, negative where it tends to be dark, and near zero in places that don't matter. But the math underneath is exactly the math above.
One line of arithmetic.
The entire classifier — input encoding, template comparison, decision rule, even the probabilistic interpretation — fits in a single expression:
$$\hat{y}(\mathbf{x}) \;=\; \arg\max_{k}\; \bigl\langle \mathbf{x},\, \mathbf{w}_k \bigr\rangle.$$Everything that comes after in modern deep learning — hidden layers, nonlinearities, convolutions, attention — is a way of bending the same idea around harder data. The skeleton is always this: project the input onto each class's direction, and take the largest.