← back to jackcoldrick.com
inside-the-machine — project detail
Inside the Machine icon: two columns of glowing neurons joined by pink and cyan connections

Side projectInside the Machine

A real neural network, small enough to watch. Press TRAIN and you see a guess travel forward, come out wrong, and the error travel backwards to fix the weights it passed through. Then you ask it to write. Built for people who have never written a line of code and want to know how models like ChatGPT actually learn.

Inside the Machine after 1,685 training steps: five training sentences all ticked on the left, two never-seen sentences below them with a note that the model is 98% sure of a wrong answer, the network diagram in the middle, and a loss graph on the right where a purple line dips to a ring and then climbs.
After 1,685 steps. Every training sentence is ticked. Below them are two it never trains on: it pieces together “tree” for a cat that flew, and is 98% sure of “tree” for a bird flying over water, which is wrong. On the graph, the purple line is its error on those unseen sentences. It bottoms out at the ring, then climbs while training keeps improving: the model has started memorising.

What it is

A language model does one thing: given some words, guess the next one. This is that, at the smallest size that still works. It learns five short sentences, 20 words in all, with 315 numbers it adjusts as it goes. That is small enough to draw every connection on screen and let you watch each one change.

It opens with a short lesson — one sentence, one button — then hands you the controls and a goal: get every sentence right. From there it shows the things people usually only read about. The gap between memorising and learning. Where training data comes from when nobody labels it. Why a model can sound certain about something it has wrong. And the steps that turn a next-word guesser into a chatbot.

Nothing on screen is a scripted animation. Every probability, error and weight change is computed live, from the network you are looking at.

How it's built

The model is the 2003 neural language model of Bengio et al. — the design modern language models descend from. It reads the last four words in order, turns each into a short list of numbers, and passes them through two hidden layers to a probability for every word it knows. Training is real gradient descent with real backpropagation, written by hand in plain JavaScript.

That the maths is real is not a matter of trust. The test suite checks every gradient the network computes against a numerical estimate and fails if they disagree by more than one part in a hundred thousand. There are 56 checks in all, running in Node with no dependencies.

Everything teaching-related is measured rather than assumed:

  • The best possible score is calculated, not hoped for. After “the”, five different words are all correct, so 86% is a perfect score on this data. The app computes that ceiling and draws it, so a plateau reads as arrival rather than failure.
  • Memorising is detected, not staged. The never-seen sentences were chosen by training across several random starts. On every one, their error falls for about 150 steps and then climbs, and the app only calls it memorising once that rise has lasted and training is still improving.
  • Training stops when learning does. AUTO watches the loss and stops itself when it flattens, saying whether the model finished or got stuck.
Inside the Machine in ASK mode: the prompt “the cat sat on the” on the left with the model’s vocabulary as clickable chips and a temperature slider, the network highlighting the output neuron for “mat”, and the inspector on the right explaining that output probability of 76.4%.
ASK mode. The prompt runs forward through the network you trained and every word it knows gets a probability — here “mat” leads. It picks one, adds it to the prompt, and goes again. Click any neuron and the inspector explains what it is and shows its raw numbers.

Features

  • One training step, slowed right down. Six phases you can watch: the guess going forward, the prediction, the error, the error travelling backwards, the weights moving, and the better guess that results.
  • A test it never studies for. Two sentences it is scored on but never trained on, with their own line on the loss graph. When that line climbs while the other falls, the screen says what it means.
  • Where the answers come from. A sentence is taken apart word by word: cover the next word and that is the question, uncover it and that is the answer. Five sentences become 28 questions nobody had to write, which is why a model can learn from the whole internet.
  • Why it makes things up. Shown on the screen rather than explained. A card notes when the model is confidently wrong, and ASK points out when several words fit and it simply picked one.
  • From this to a chatbot. The three stages that turn this kind of model into an assistant — reading, practising on example conversations, and learning which replies people prefer — with your own trained model shown live in the first.
  • Teach it something new. Add your own sentence. New words need new numbers, so the network grows to hold them and keeps everything it already knew.
  • A lesson first, then the controls. The first minute is one sentence and one button. Everything else arrives once you have seen a single step work.

The stack

Model
A 315-parameter neural language model in plain JavaScript modules — forward pass, backpropagation and gradient descent written by hand
Rendering
HTML canvas, with every drawing position, colour and duration owned by one module each, and colour contrast measured by the tests
Tests
56 headless checks in Node, including a numerical gradient check of every weight
Dependencies
None. No framework, no build step
Hosting
Vercel, deploying on every push

A detail I like

Train it for as long as you like and accuracy stops at 86%, which reads as broken. It isn't. Five sentences start with “the”, so after that one word five different answers are all right, and no model can pick all five. Rather than apologise for it, the app works out the best score any model could reach on the data, draws it on the graph as a green line, and lets the curve arrive there. Real language is full of the same thing, which is why a real model's error never reaches zero either.