MacMind is a single-layer, single-head transformer implemented entirely in HyperTalk. It has token embeddings, positional encoding, scaled dot-product self-attention, a residual connection, cross-entropy loss, full back propagation, and stochastic gradient descent. There are 1,216 parameters across six weight matrices. There is no feed-forward block or layer norm, because at this scale attention and a residual are enough.
It runs in HyperCard 2.1. The reference machine is a Macintosh SE/30 under System 7.6.1. It should run on any 68000 Mac from System 7 through Mac OS 9, and in Basilisk II, SheepShaver, or Mini vMac. It also runs in the browser at hcsimulator.com.
The training task is the bit-reversal permutation, the opening step of the Fast Fourier Transform (FFT). The model doesn't know the rule. It learns from random examples. After training, the attention map shows the butterfly routing pattern Cooley and Tukey published in 1965. A 16 MHz 68030 rediscovers the structure of the FFT through gradient descent.
The process that trained MacMind is the same process that trained every large language model: forward pass, loss, backward pass, weight update, repeat. MacMind has 1,216 parameters. GPT-4 has roughly a trillion. The math is the same, only the scale is different.
That is the point of this project, to see if the mathematics of AI that are shaping the world around us are knowable. In HyperCard you can option-click any button and read the actual math. It's HyperCard and HyperTalk, so there's no compiled code, external libraries.
The build logs cover the rest: matrix math in a language with no arrays, backprop derived by hand, a 32KB script editor limit, and Apple's SANE doing every multiply in 80-bit extended precision.
Source, pre-trained stack, blank trainable stack, and a Python/NumPy reference implementation are availble for download: github.com/SeanFDZ/macmind (MIT).
Sean
Tim
Jovan
Bruce Land
Nick Bild