File size: 6,105 Bytes
ec9605e
 
df2dcff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ec9605e
df2dcff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
license: apache-2.0
task_categories:
  - text-generation
tags:
  - arithmetic
  - compositional-generalization
  - length-generalization
  - synthetic
size_categories:
  - 10K<n<100K
configs:
  - config_name: study1
    field: data
    data_files:
      - split: train
        path: study1/train.json
      - split: validation
        path: study1/val.json
      - split: test
        path: study1/test.json
      - split: ood_ops4
        path: study1/ood_ops4.json
      - split: ood_ops5
        path: study1/ood_ops5.json
      - split: ood_ops6
        path: study1/ood_ops6.json
      - split: ood_ops7
        path: study1/ood_ops7.json
  - config_name: study2
    field: data
    data_files:
      - split: train
        path: study2/train.json
      - split: validation
        path: study2/val.json
      - split: test
        path: study2/test.json
      - split: ood
        path: study2/ood.json
---

# Compositional Reasoning on Arithmetic: Datasets (v2)

These are synthetic arithmetic datasets for testing whether sequence-to-sequence models generalize to longer expressions (Study 1) and more deeply nested ones (Study 2). They were used in the paper *Partial Competence and Limited Transfer: Comparing LSTM and Transformer Generalization on Arithmetic Expressions* (arXiv ID pending).

Each example is a fully parenthesized integer expression paired with its value:

```
input:  (((15 - 3) + 10) + (17 * 20))
output: 362
```

- **Code and generator:** https://github.com/bcode0127-debug/Compositional-Reasoning-Arithmetic (`data/generate_controlled.py`)
- **Trained models:** [Ajay0728/Compositional-reasoning-arithmetic](https://huggingface.co/Ajay0728/Compositional-reasoning-arithmetic)

## Studies and splits

**Study 1: length generalization.** Models train on 2–3 operations and are tested on 4–7.

| Split | File | Size | Expressions |
|---|---|---|---|
| train | `study1/train.json` | 8,000 | 2 ops depth 2, 3 ops depth 2, 3 ops depth 3 chain (one third each) |
| validation | `study1/val.json` | 1,000 | same mix as train |
| test | `study1/test.json` | 1,000 | same mix as train |
| ood_ops4 | `study1/ood_ops4.json` | 1,000 | 4 ops, depth 3, balanced |
| ood_ops5 | `study1/ood_ops5.json` | 1,000 | 5 ops, depth 3, balanced |
| ood_ops6 | `study1/ood_ops6.json` | 1,000 | 6 ops, depth 3, balanced |
| ood_ops7 | `study1/ood_ops7.json` | 1,000 | 7 ops, depth 3, balanced |

**Study 2: depth generalization.** The number of operations stays at 3 while nesting depth goes from 2 to 3.

| Split | File | Size | Expressions |
|---|---|---|---|
| train | `study2/train.json` | 8,000 | 3 ops, depth 2, balanced |
| validation | `study2/val.json` | 1,000 | 3 ops, depth 2, balanced |
| test | `study2/test.json` | 1,000 | 3 ops, depth 2, balanced |
| ood | `study2/ood.json` | 1,000 | 3 ops, depth 3, chain |

Each split was generated with its own random seed. The test splits were generated after the models were trained, from generator commit `f636492`, so they were never used for model selection. Every other split comes from commit `f504457`.

## Usage

```python
from datasets import load_dataset

s1 = load_dataset("Ajay0728/Compositional-reasoning-arithmetic-datasets", "study1")
print(s1["train"][0]["input"], "->", s1["train"][0]["output"])
ood7 = load_dataset("Ajay0728/Compositional-reasoning-arithmetic-datasets", "study1", split="ood_ops7")
```

You can also download the raw JSON files directly. Each file is a JSON object with the examples under `"data"` and the generation metadata in the other top-level keys.

## Fields

Each example has these fields:

| Field | Type | Description |
|---|---|---|
| `input` | string | Model input: the fully parenthesized expression, with spaces around operators |
| `output` | string | Target: the integer result as a string |
| `expression` | string | Same as `input` |
| `result` | int | Integer value of the expression |
| `num_operations` | int | Number of binary operators |
| `depth` | int | Depth of the expression tree |
| `intermediate_max` | int | Largest absolute intermediate value during evaluation |
| `operator_counts` | dict | Count of each of `+ - * /` |
| `seed_id` | int | Index of the generator seed this example came from |

Each file also has these top-level metadata keys:

- `study`, `split`, `seed`, `generator_commit`, `timestamp`
- `buckets`: the operation count, depth, tree shape and rejection rate for each group of expressions
- `operator_distribution_actual`: how often each operator actually appears

## How the data was generated

Each expression is built as a random binary expression tree with a target operation count, depth, and shape. A shape is either *balanced* or *chain*, where a chain nests to one side only. Candidates are rejected unless:

- every division is exact (integer result, no remainder, no division by zero)
- the final result satisfies |result| ≤ 10,000

All inputs are at most 51 characters long. Outputs are at most 6 characters (e.g. `-10000`).

**Operator balance:** division is rare in every split, about 3–5% of operators, because the exact-division requirement rejects most division candidates. The other three operators make up roughly 28–35% each. Results broken down by operator, especially for division, should account for these small counts.

## Integrity

`CHECKSUMS.txt` lists the SHA-256 hash of each file. Its paths start with `datasets_v2/`, so to verify, put the files in a folder named `datasets_v2` and run `shasum -a 256 -c CHECKSUMS.txt` from that folder's parent.

## Superseded version

An earlier version of these datasets, `datasets/` in the GitHub repo, was used with an evaluation path that silently cut inputs to 20 characters. Results from that version are retired. This v2 release is the one used for every number reported in the paper.

## Citation

```bibtex
@misc{jamanjyothi2026partial,
  title  = {Partial Competence and Limited Transfer: Comparing LSTM and Transformer
            Generalization on Arithmetic Expressions},
  author = {Jamanjyothi, Ajay},
  year   = {2026},
  note   = {arXiv preprint (ID pending)}
}
```