|
| 1 | +# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import argparse |
| 16 | +import json |
| 17 | +from pathlib import Path |
| 18 | + |
| 19 | + |
| 20 | +def format_grid(grid): |
| 21 | + return "\n".join([" ".join(map(str, row)) for row in grid]) |
| 22 | + |
| 23 | + |
| 24 | +def create_arc_prompt(task_data, task_id, version=1): |
| 25 | + prompt = f"You are solving ARC-AGI{'-' + str(version) if version != 1 else ''} task {task_id}.\n\n" |
| 26 | + prompt += "Here are the training examples that demonstrate the pattern:\n\n" |
| 27 | + |
| 28 | + for i, example in enumerate(task_data["train"]): |
| 29 | + prompt += f"Example {i + 1}:\n" |
| 30 | + prompt += "Input:\n" |
| 31 | + prompt += format_grid(example["input"]) |
| 32 | + prompt += "\n\nOutput:\n" |
| 33 | + prompt += format_grid(example["output"]) |
| 34 | + prompt += "\n\n" |
| 35 | + |
| 36 | + test_input = task_data["test"][0]["input"] |
| 37 | + prompt += "Now solve this test case following the same pattern:\n" |
| 38 | + prompt += "Test Input:\n" |
| 39 | + prompt += format_grid(test_input) |
| 40 | + prompt += ( |
| 41 | + "\n\nProvide your solution as a 2D array inside \\boxed{} in this exact format: \\boxed{[[row1],[row2],...]}" |
| 42 | + ) |
| 43 | + prompt += "\nFor example: \\boxed{[[1,2,3],[4,5,6],[7,8,9]]}" |
| 44 | + |
| 45 | + return prompt |
| 46 | + |
| 47 | + |
| 48 | +def create_dataset(version=1): |
| 49 | + data_base = f"../../ARC-AGI{'-' + str(version) if version != 1 else ''}" |
| 50 | + training_dir = Path(f"{data_base}/data/training") |
| 51 | + evaluation_dir = Path(f"{data_base}/data/evaluation") |
| 52 | + |
| 53 | + Path("data").mkdir(exist_ok=True) |
| 54 | + |
| 55 | + training_dataset = [] |
| 56 | + print(f"Processing {len(list(training_dir.glob('*.json')))} training tasks...") # 400 tasks |
| 57 | + |
| 58 | + for task_file in sorted(training_dir.glob("*.json")): |
| 59 | + task_id = task_file.stem |
| 60 | + |
| 61 | + with open(task_file) as f: |
| 62 | + task_data = json.load(f) |
| 63 | + |
| 64 | + prompt = create_arc_prompt(task_data, task_id, version) |
| 65 | + expected_output = task_data["test"][0]["output"] |
| 66 | + test_input = task_data["test"][0]["input"] |
| 67 | + |
| 68 | + entry = { |
| 69 | + "responses_create_params": {"input": [{"role": "user", "content": prompt}]}, |
| 70 | + "train": task_data["train"], |
| 71 | + "test_input": test_input, |
| 72 | + "expected_output": expected_output, |
| 73 | + "task_id": task_id, |
| 74 | + } |
| 75 | + |
| 76 | + training_dataset.append(entry) |
| 77 | + |
| 78 | + training_output_file = Path(f"data/arc_agi_{version}_training.jsonl") |
| 79 | + with open(training_output_file, "w") as f: |
| 80 | + for entry in training_dataset: |
| 81 | + f.write(json.dumps(entry) + "\n") |
| 82 | + |
| 83 | + print(f"Created training dataset with {len(training_dataset)} tasks at {training_output_file}") |
| 84 | + |
| 85 | + evaluation_dataset = [] |
| 86 | + print(f"Processing {len(list(evaluation_dir.glob('*.json')))} evaluation tasks...") # 400 tasks |
| 87 | + |
| 88 | + for task_file in sorted(evaluation_dir.glob("*.json")): |
| 89 | + task_id = task_file.stem |
| 90 | + |
| 91 | + with open(task_file) as f: |
| 92 | + task_data = json.load(f) |
| 93 | + |
| 94 | + prompt = create_arc_prompt(task_data, task_id, version) |
| 95 | + expected_output = task_data["test"][0]["output"] |
| 96 | + test_input = task_data["test"][0]["input"] |
| 97 | + |
| 98 | + entry = { |
| 99 | + "responses_create_params": {"input": [{"role": "user", "content": prompt}]}, |
| 100 | + "train": task_data["train"], |
| 101 | + "test_input": test_input, |
| 102 | + "expected_output": expected_output, |
| 103 | + "task_id": task_id, |
| 104 | + } |
| 105 | + |
| 106 | + evaluation_dataset.append(entry) |
| 107 | + |
| 108 | + evaluation_output_file = Path(f"data/arc_agi_{version}_evaluation.jsonl") |
| 109 | + with open(evaluation_output_file, "w") as f: |
| 110 | + for entry in evaluation_dataset: |
| 111 | + f.write(json.dumps(entry) + "\n") |
| 112 | + |
| 113 | + print(f"Created evaluation dataset with {len(evaluation_dataset)} tasks at {evaluation_output_file}") |
| 114 | + |
| 115 | + example_output_file = Path(f"data/example_{version}.jsonl") |
| 116 | + with open(example_output_file, "w") as f: |
| 117 | + for entry in evaluation_dataset[:5]: |
| 118 | + f.write(json.dumps(entry) + "\n") |
| 119 | + |
| 120 | + print(f"Created example dataset with 5 tasks at {example_output_file}") |
| 121 | + |
| 122 | + |
| 123 | +if __name__ == "__main__": |
| 124 | + parser = argparse.ArgumentParser(description="Create ARC-AGI dataset") |
| 125 | + parser.add_argument("--version", type=int, default=1, choices=[1, 2], help="ARC-AGI version (1 or 2)") |
| 126 | + args = parser.parse_args() |
| 127 | + |
| 128 | + create_dataset(version=args.version) |
0 commit comments