File size: 1,979 Bytes
f2522dd
 
 
 
 
 
 
 
 
13498db
f2522dd
cb652ee
 
13498db
cb652ee
f2522dd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cb652ee
f2522dd
 
cb652ee
 
f2522dd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

# Arithmetic Puzzles Dataset

A collection of arithmetic puzzles with heavy use of variable assignment. Current LLMs struggle with variable indirection/multi-hop reasoning, this should be a tough test for them.

Inputs are a list of strings representing variable assignments (`c=a+b`), and the output is the integer answer.

Outputs are filtered to be between [-100, 100], and self-reference/looped dependencies are forbidden.

Splits are named like:

- `train_N` 8k total examples of puzzles with N variables
- `test_N` 2k more examples with N variables

Train/test leakage is prevented: all training examples are filtered out of the test set.

Conceptually the data looks like this:

```python
Input:

  a=1
  b=2
  c=a+b
  solve(c)=

Output:
  3
```

In actuality it looks like this:

```python
{
    "input": ['var_0=1', 'var_1=2', 'var_2=a+b', 'solve(var_2)='],
    "output": 3
}
```


### Loading the Dataset

```python
from datasets import load_dataset

# Load the entire dataset
dataset = load_dataset("neurallambda/arithmetic_dataset")

# Load specific splits
train_small = load_dataset("neurallambda/arithmetic_dataset", split="train_10")
test_small = load_dataset("neurallambda/arithmetic_dataset", split="test_10")
```

### Preparing Inputs

To prepare the inputs as concatenated strings, you can do this:

```python
def prepare_input(example):
    return {
        "input_text": "
".join(example["input"]),
        "output": example["output"]
    }

# Apply the preparation to a specific split
train_small_prepared = train_small.map(prepare_input)

# Example of using the prepared dataset
for example in train_small_prepared.select(range(5)):  # Show first 5 examples
    print("Input:", example["input_text"])
    print("Output:", example["output"])
    print()
```

This will produce output similar to:

```
Input: var_0=5
var_1=2
var_2=-2 + -8
var_3=3
var_4=4
var_5=var_2
var_6=var_3 * 10
var_7=var_2 - var_0
var_8=var_1
var_9=-2 - 9
solve(var_3)=
Output: 3
```