Chapter 2 of 0–21
The task as a dataset
12,769 questions, 30 % of them for training, encoded as three tokens.
The question as a function
A function is a rule that gives exactly one output for each input. The rule the network must learn is
There are 113 choices for a and 113 for b, so there are 113 × 113 = 12,769 possible questions — few enough that we can check the network on every single one.
Examples, labels, and the training/test split
A dataset is a collection of examples: each example is an input together with its correct output, called its label. Here the example “(100, 50)” has label 37.
The paper's setup shows the network only a random 30 % of the questions while it learns [1]. Those form the training set: 3,830 questions. The remaining 8,939 questions form the test set: they are never used to adjust the network, only to check it.
Which inputs are used for training
All 113 × 113 inputs (a = row, b = column): yellow = training pair, purple = test pair.
Loading…
How to read it
<p class="fig-meta">
<a href="../chapters/02-task-as-data.html">Learn step by step →</a>
· Source: <a class="cite" href="../references.html#paperrepo" title="progress-measures-paper code">[6]</a> gen_train_test
· Computed by <code>task.paper_split</code> (<a href="https://github.com/BurnyCoder/visualizing-grokking-modular-addition">code</a>)
</p>
The split is made by shuffling all 12,769 pairs with a fixed random seed and taking the first 30 % (0.3 × 12,769 = 3,830.7, rounded down) [6]. Hover the picture: each cell is one question (a = row, b = column); yellow cells are training questions.
Is (100, 50) a training question? In the paper's split it is a test question — the network never sees its answer during training. (By contrast (5, 71) is a training question.) That is why (100, 50) is our running example throughout the site: when the trained network gets it right, it is not because it saw it.
Two ways to get training questions right
A network can answer its training questions correctly in two very different ways:
- memorization: store each of the 3,830 question–answer pairs separately, like a lookup table. This says nothing about the other 8,939 questions.
- generalization: capture the rule itself, so that unseen questions are answered correctly too.
The test set tells the two apart: memorisation scores ~0 % on it (about 1 in 113 right by luck), generalisation scores ~100 %.
Questions as token sequences
The network reads its input as a short sequence of symbols called tokens, each written as an integer id. The question “100 + 50 =” becomes the three tokens
where ids 0–112 stand for the numbers and the extra id 113 stands for “=” [3]. The set of all tokens the network knows is its vocabulary — 114 tokens here. The position of a token is its place in the sequence: position 0 holds a, position 1 holds b, position 2 holds “=”.
Note that the “+” is never shown: every input is just “a b =”, and the network has to discover that the task is addition from the examples alone.
The network outputs a score for each of 114 tokens (including “=”), but only the 113 number tokens are possible answers. Like the paper's analysis code, our analyses drop the “=” output [6]; training uses all 114, exactly as the paper's training code did.