Skip to content
latent

How a neural network becomes a matmul

One tiny network drawn as neurons and weights, then as the matmuls that compute it.

Neural networks are drawn as neurons joined by weights, but computed as matrix multiplications. Here is one tiny network drawn both ways, so you can watch one become the other.

It reads three characters and scores the next one, like the model in Andrej Karpathy’s makemore, only smaller: 6 characters (. a e l n o), 2 numbers per character, 4 hidden neurons and a batch of 10 examples from ella and noel. Softmax and the loss work exactly as in Training a bigram model, so they are left out here.

Training examples from ella, noel · . marks a word boundary

View

A tiny network and the matmuls that compute itNetwork view: 6 embedded inputs connect through 24 weights to 4 tanh neurons, which connect through 24 more weights to 6 output logits. Matmul view: the same weights as W1 (6 by 4) and W2 (4 by 6); the batch X (10 by 6) times W1 plus b1, through tanh, gives H (10 by 4), and H times W2 plus b2 gives the logits Z (10 by 6).

Loading discussion…