-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataset.py
More file actions
36 lines (28 loc) · 1.27 KB
/
Copy pathdataset.py
File metadata and controls
36 lines (28 loc) · 1.27 KB
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
import os
import json
from datasets import load_dataset
# Define the base paths
base_dir = "/dev/shm/tmp/grpo_test/rl/grpo/data"
train_dir = os.path.join(base_dir, "train")
test_dir = os.path.join(base_dir, "test")
# Create directories (equivalent to the 'mkdir -p' shell commands)
os.makedirs(train_dir, exist_ok=True)
os.makedirs(test_dir, exist_ok=True)
print("Downloading GSM8K dataset...")
# --- Process Train Split ---
dataset_train = load_dataset('openai/gsm8k', 'main', split='train')
train_data = [{'question': item['question'], 'answer': item['answer']} for item in dataset_train]
# Save directly to final destination (equivalent to the 'mv' command)
train_path = os.path.join(train_dir, "dataset.json")
with open(train_path, 'w') as f:
json.dump(train_data, f)
print(f"Train data saved to: {train_path}")
# --- Process Test Split ---
dataset_test = load_dataset('openai/gsm8k', 'main', split='test')
test_data = [{'question': item['question'], 'answer': item['answer']} for item in dataset_test]
# Save directly to final destination (equivalent to the 'mv' command)
test_path = os.path.join(test_dir, "dataset.json")
with open(test_path, 'w') as f:
json.dump(test_data, f)
print(f"Test data saved to: {test_path}")
print('GSM8K dataset downloaded and organized successfully.')