Datasets:
File size: 6,154 Bytes
43ce032 ea0c361 d768336 43ce032 ea0c361 43ce032 ea0c361 43ce032 584221e 43ce032 740f627 43ce032 584221e 740f627 43ce032 584221e 43ce032 584221e 43ce032 740f627 584221e 740f627 584221e 740f627 584221e 740f627 584221e 740f627 584221e 43ce032 740f627 43ce032 584221e 740f627 43ce032 740f627 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | ---
configs:
- config_name: add_6digit
data_files:
- path: add_6digit/train.parquet
split: train
- path: add_6digit/val.parquet
split: validation
- path: add_6digit/eval_stratified.parquet
split: test
- config_name: add_sub_6digit
data_files:
- path: add_sub_6digit/train.parquet
split: train
- path: add_sub_6digit/val.parquet
split: validation
- path: add_sub_6digit/eval_stratified.parquet
split: test
- config_name: add_handcrafted
data_files:
- path: add_handcrafted/test.parquet
split: test
- config_name: sub_handcrafted
data_files:
- path: sub_handcrafted/test.parquet
split: test
language:
- en
license: apache-2.0
size_categories:
- 1M<n<10M
tags:
- arithmetic
- interpretability
- sorl
- mechanistic-interpretability
- addition
- subtraction
- quirke
task_categories:
- text-generation
---
# Arithmetic SoRL Data
Training and evaluation data for the **SoRL Arithmetic Interpretability Study**.
Small transformers trained on integer addition/subtraction, with
[SoRL](https://github.com/fangyuan-ksgk/mod_gpt) to externalize carry/borrow circuits
as explicit abstraction tokens.
**Reference:** Quirke et al., ["Understanding Addition and Subtraction in Transformers"](https://arxiv.org/abs/2402.02619) (2024).
Paper: [arXiv:2402.02619](https://arxiv.org/abs/2402.02619) — see Table 8 for complexity classification and Section 3 for sub-task definitions.
## Dataset Structure
| Subfolder | Operations | Train | Val | Eval (stratified) |
|---|---|---|---|---|
| `add_6digit` | addition only | 500K | 10K | ~2950 (250 per S0-S6, C3-C6 + 200 random) |
| `add_sub_6digit` | add + sub | 500K | 10K | ~5400 (250 per split + 400 random) |
| `add_handcrafted` | addition only | — | — | 108 |
| `sub_handcrafted` | subtraction only | — | — | 68 |
### Eval Splits
All eval sets use seed=42 for reproducibility. Every model is evaluated on identical examples.
| Split Type | Splits | Examples/split | Description |
|---|---|---|---|
| Quirke cascades (add) | S0-S6 | 250 | Carry cascade depth 0-6 |
| Hot carry chains | C3-C6 | 250 | Carry cascades with varied answer digits (not just 0s) |
| Quirke cascades (sub) | M0-M5 | 250 | Borrow cascade depth 0-5 (M6 is impossible for 6-digit) |
| Hot borrow chains | B3-B5 | 250 | Borrow cascades with varied answer digits (not just 9s) |
| Random | add_random, sub_random | 200 | Uniform random |
**Note:** M6 (borrow cascade of length 6) is impossible for 6-digit subtraction — it would require 7 digit positions.
## Columns
| Column | Type | Description |
|---|---|---|
| `tokens` | list[int] | Full sequence (21 tokens for 6-digit, Qwen3 tokenizer) |
| `labels` | list[str] | Per-answer-digit sub-task label (SA, SC, SS, UC, US for add; MD, MB, ME, UB, UD for sub) |
| `op` | str | `"add"` or `"sub"` |
| `complexity` | str | Quirke complexity: `S0`-`S6` (add) or `M0`-`M5` (sub) |
| `cascade_depth` | int | Max carry/borrow cascade length |
| `x_digits` | list[int] | First operand (MSB first) |
| `y_digits` | list[int] | Second operand (MSB first) |
| `z_digits` | list[int] | Answer (MSB first, n_digits+1) |
The `eval_stratified` split has an additional `eval_category` column.
## Sub-task Labels ([Quirke et al. 2024](https://arxiv.org/abs/2402.02619))
Each answer digit requires a specific arithmetic operation. These labels follow Quirke et al. Section 3.
### Addition
| Label | Name | Condition | Role |
|---|---|---|---|
| SA | Base Add | `Dn + D'n < 9`, no carry | Simplest case |
| SC | Make Carry | `Dn + D'n >= 10` | Generates carry |
| SS | Sum is 9 | `Dn + D'n == 9` | Propagates carry if one arrives |
| UC | Use Carry | carry_in=1, sum != 9 | Consumes incoming carry |
| US | Use Sum-9 | carry_in=1, sum == 9 | Cascade: hardest case |
### Subtraction (x >= y)
| Label | Name | Condition | Role |
|---|---|---|---|
| MD | Base Diff | `Dn > D'n`, no borrow | Simplest case |
| MB | Make Borrow | `Dn < D'n` | Generates borrow |
| ME | Equal digits | `Dn == D'n` | Propagates borrow if one arrives |
| UB | Use Borrow | borrow_in=1, `Dn != D'n` | Consumes incoming borrow |
| UD | Use Equal | borrow_in=1, `Dn == D'n` | Cascade: hardest case |
## Complexity Classification ([Quirke Table 8](https://arxiv.org/abs/2402.02619))
Complexity = length of longest carry/borrow cascade chain.
Example: `555555+444448=1000003` is **S6** — the carry from D0 cascades through
5 consecutive sum-9 positions.
```
S0: no carries ~10%
S1: isolated carries ~50%
S2: cascade of 2 ~26%
S3: cascade of 3 ~9%
S4: cascade of 4 ~3%
S5: cascade of 5 ~1%
S6: cascade of 6 <0.5%
```
## Data Enrichment
**Addition:** Following Quirke et al., 60% of batches have 40% of digit positions forced to sum-to-9, increasing carry cascade frequency so the model sees enough S4-S6 cases.
**Subtraction:** 40% of digit positions are forced equal (`Dn == D'n`), creating borrow propagation cascades (ME/UD). Without this, M3-M5 borrow cascades are extremely rare (M3=0.7%, M4=0.04% in unmodified data). With enrichment: M3=3.0%, M4=0.8%.
## Usage
```python
from datasets import load_dataset
ds = load_dataset("thoughtworks/arithmetic-sorl-data", data_dir="add_6digit")
print(ds["train"][0])
# {'tokens': [...], 'labels': ['SA', 'UC', 'US', ...],
# 'complexity': 'S3', 'cascade_depth': 3, ...}
# Stratified eval
eval_ds = load_dataset("thoughtworks/arithmetic-sorl-data",
data_dir="add_6digit", data_files="eval_stratified.parquet")
# Addition + subtraction
ds_mixed = load_dataset("thoughtworks/arithmetic-sorl-data", data_dir="add_sub_6digit")
```
## Related
- **Reference paper:** Quirke et al., ["Understanding Addition and Subtraction in Transformers"](https://arxiv.org/abs/2402.02619) (2024)
- **Model checkpoints:** [thoughtworks/arithmetic-sorl](https://huggingface.co/thoughtworks/arithmetic-sorl)
- **Dashboard:** [thoughtworks/arithmetic-sorl-dashboard](https://huggingface.co/spaces/thoughtworks/arithmetic-sorl-dashboard)
- **Code:** [mod_gpt/arithmetic/](https://github.com/fangyuan-ksgk/mod_gpt/tree/amir/arithmetic/arithmetic)
|