Opening the Black Box
I open up an AI model to give you a sense of how models work. It first memorises answers to addition problems, before having an "aha!" moment and teaches itself trigonometry.
If you ask ChatGPT or Claude to justify its answer, it will return a long, plausible explanation. But you (and its creators) have no way of knowing whether that explanation is correct. At its core, these models are neural networks. They consist of billions of numbers, or “weights,” none of which are set by hand. Rather, the network is trained on examples. And after each example, its weights shift slightly so its answer gets better.
In that sense, it learns well at its job. But nobody knows what any of its weights mean, hence why we think of AI as a “black box.” You can see its input and output, but not how the one gives rise to the other.
I decided to take a look inside one of these networks, a small one that I could examine, and to my surprise, it had taught itself trigonometry. The concept of reverse-engineering what a network has learned, as I did here, is called mechanistic interpretability.
Time Flies When You’re Doing Sums
My task was arithmetic on a clock. On a clock, 4 hours after 9 o’clock is 1 o’clock because after 12, we start over (see Figure 1). My clock had 113 hours, so 100 + 20 = 120 becomes 7. Neel Nanda and his colleagues describe this idea in a paper from 2023.
Figure 1: 9 o’clock plus 4 hours is 1 o’clock, because the clock wraps round (12 is written as 0). Image: Spindled, Wikimedia Commons (GFDL).
In all, there are 12,769 (113*113) possible questions. I used 30% of them to train my network, then tested it on the rest. To answer the test questions, it would need to pick up addition on it’s own.
My network is a transformer, like the one used in ChatGPT and Claude, however it’s much smaller, with only about 227,000 weights, compared with GPT-3’s 175 billion.
One Sum, Four Steps, No Shortcuts
To get a sense of what the network does, let’s follow one question through it: 50 + 100. On the 113-hour clock, 150 becomes 37, which, in this case, is our answer. Here’s how the network arrives at it. Our question is three symbols: 50, 100 and “=”.
Step 1: describe each symbol. A network can’t do much with the label “50” nor “=” since computers work best with numbers, so it replaces each symbol with a list of 128 numbers capturing that symbol. You could think of this as describing a color by how much red, blue and green is in it. Here we have 128 “ingredients.” No one writes this list. It starts out random, but over time the network adjusts it. (This list is known as the embedding.)
Figure 2: the same idea for words, from an older model called Word2vec. Each word becomes a list of numbers, shown here as coloured cells (just four instead of 128). Similar words get similar lists. Image: Jay Alammar, T
Step 2: gather. Our answer is going to be at the symbol “=”, but right now its list tells us nothing about 50 or 100. So the network takes information from the other two symbols and incorporates it into its own list. (This is called attention.) Now the list for “=” contains information about both 50 and 100, however it still needs to add them.
Figure 3: attention in a translation model reading “The animal didn’t cross the street because it was too tired”. To work out what “it” means, the word looks back at the others; the darker the line, the more it copies. M
Step 3: calculate. That’s where 512 little calculators (neurons) come in. Each one does a very simple calculation. It takes the 128 numbers in its list, multiplies each by a weight, adds them up, and then passes that result along (if it’s positive). None of them could do the addition, but collectively they could. This is why the specific weights matter, because when calibrated correctly, it could result in “regular addition” of the inputs.
Figure 4: one neuron. Its inputs (x) are multiplied by weights (w), added up (Σ), and passed on only if the total is big enough (φ). Image: Chrislb, Wikimedia Commons (CC BY-SA 3.0).
Step 4: score. Finally, from the numbers in the “=” list we can produce a score for each possible answer between 0 and 112. The answer with the highest score is our answer, and if the network has done a good job, it will be 37.
All of these numbers started out random. Through training they all changed so that the answers came out correctly. But no one knows how, in step 3, the neurons added 50 and 100. And that’s what the rest of this article explores.
Figure 5: the whole process for 50 + 100, step by step.
Cramming First, Clicking Later
After 1,000 rounds of training, the network answered all the questions it had seen, but only 2.7% of the hidden questions. That’s only slightly better than random guessing. In effect, it had learned the answers, rather than the topic, from the mark scheme. I carried on training. For thousands of rounds, performance stayed the same. Then, at about round 5,300, its performance on hidden questions jumped to over 99%. This is known as “grokking.”
Figure 6: accuracy during training on questions the network has seen (blue) and hidden questions (orange). Hidden-question accuracy stays low for thousands of rounds, then suddenly jumps.
Weight decay (a setting that slightly reduces every weight in the network every round) drives this. It’s as if there was a tax on large weights. To answer thousands of questions, the network needed large weights. But a method would require small ones. Over time, then, the tax would drive the network toward a method. But none of this showed up in its performance. To see it, I had to look inside the network.
Inside the Box
At face value, the 128-number descriptions in step 1 look like nonsense. But I wondered whether, as we go from 0 to 112, they went up and down in some wavelike pattern. To check this, I applied the kind of math used to break down a sound into its notes (a Fourier transform). Before training, there was no pattern. After training, nearly all of them fell into three waves.
Figure 7: how strongly the network uses each possible wave, before training (left) and after (right).
Each wave has a sine and a cosine. If we think of each number as a point on the plane defined by these two, they traced out a circle:
Figure 8: each dot is one of the numbers 0 to 112. The orange line joins 0, 1, 2, 3 and 4 in order.
The network had built its own clock face. Adding two numbers on a circle is the same as adding their angles. Turn one angle, then the other, and you get the answer. And that’s just what we wanted when we went past 113: it carries right back round.
Now, all four steps begin to make sense. In step 1, we put each number on the circle. In step 2, we put the two numbers together with an “=”. In step 3, the neurons added the two angles, using a trigonometry identity: cos(x + y) = cos x cos y − sin x sin y. In step 4, they picked the number at this new angle. None of this was programmed into them.
Wave Goodbye to Doubt
A picture is only a hypothesis. If the network depends on those three waves, then removing them would break it. And removing other waves shouldn’t. With only those three waves left, it got 99.98% of the right answer.
Figure 9: accuracy on every question after each edit.
When just those three were removed, it got 0.95% of the right answer. When three other waves were taken out, there was no change. In other words, the clock is in the waves.
A Secret Early Bird
I looked at copies of the network at various points during training to see if it had picked up the clock.
Figure 10: confidence of the clock alone (green), questions the memorised answers alone get right (blue), and the real score on hidden questions (orange).
Over time, hidden within the answers it memorized, the network developed a clock. By round 3,750 it was essentially there. But the network answered only 21% of the hidden questions, overwhelmed by the answers it had memorized.
Do Real Models Add Up?
Real models are much more difficult to decode, but researchers are starting to get there. Anthropic asked Claude to add 36 + 59. One of its methods said “about 92.” Another said the last digit of the answer must be 5. But when asked how it arrived at 95, Claude said it carried over a 1 (as students learn in school). This was not what it actually did.
Why It All Adds Up
When we ask an AI to explain its reasoning, it may well respond in a way that sounds plausible but isn’t true.
My network did the right thing, but scored very poorly.
More troubling, though, is the case of a model whose reasoning would be unacceptable to us if we could see it, but which nevertheless scores perfectly. It’s not enough to ask for explanation. We need to see inside the model.
References
- Power et al. (2022), Grokking: Generalization Beyond Overfitting on Small Algorithmic Datasets
- Nanda et al. (2023), Progress measures for grokking via mechanistic interpretability
- Elhage et al. (2022), Toy Models of Superposition
- Templeton et al. (2024), Scaling Monosemanticity
- Lindsey et al. (2025), On the Biology of a Large Language Model
Reader discussion
Join the conversation.
0 contributionsCreate a free reader account to comment, like and save articles.
No comments yet. Start the discussion.