Grokking › A Worked Example: Tracing the Algorithm Circuit
Language AI HandbookAll chapters Grokking › A Worked Example: Tracing the Algorithm CircuitOne section · Sections in this chapter5 / 13 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
To make the circuit formation hypothesis concrete, let us trace through step by step what happens when the network learns to compute using the circular embedding.
Step 1: Embedding the operands. Assume the network has learned the circular embedding for . We need to find the angles for 5 and 7. The angular spacing between consecutive numbers is radians. We compute each angle by multiplying this spacing by the number:
Step 2: Computing the embedded vectors. Each number maps to a pair on the unit circle:
Step 3: Adding the angles. The attention mechanism combines these embeddings by adding their angles. This is the geometric analog of modular addition:
Step 4: Converting back to a token. The output layer maps this angle back to a token index by finding which number 0 through 16 corresponds to angle 4.433 radians. Since , this maps to token 12, which is the correct answer.
Step 5: Verifying the result. We can verify directly: , and , so . The circular computation produces the right answer.
This angle corresponds to number 12 on the unit circle, which is the correct answer. The output layer maps this angular position back to the token 12. The entire computation requires only a few dozen parameters to stand for: the circular embedding layer, the attention weights that implement angular addition, and the output layer that maps back to token indices.
By contrast, the memorization solution for this single example requires storing that the input (5, 7) maps to output 12. With 9409 total input pairs, full memorization of a 50% training split requires storing roughly 4700 such associations. Even with compact representations, this is inherently more parameter-intensive than the algorithmic solution, which applies the same rotation operation to every input. This quantitative difference in compactness is what weight decay exploits. Each step of optimization penalizes large parameters, and the memorization circuit requires larger or more numerous parameters than the algorithm circuit. Over thousands of training steps, this penalty accumulates, making the memorization circuit increasingly costly relative to the algorithm circuit. Eventually, the algorithm circuit wins out and generalization emerges.
Worked example with a wraparound case. Now let us trace a case where the sum exceeds the modulus, to see how the circular representation handles it. Consider . The ordinary sum is 21, and , so the correct answer is 4.
In the circular representation:
The term is a full rotation around the circle, which brings us back to where we started. The remaining corresponds to position 4 on the circle. The circular representation handles the wraparound automatically, without any special casing. The memorization solution, by contrast, must have separately memorized that maps to 4. If this particular pair was in the test set and not the training set, the memorization solution would fail. The circular representation succeeds on any pair because the wraparound is implicit in the geometry.