forked from Gen-Verse/LatentMAS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.py
More file actions
223 lines (185 loc) · 7.2 KB
/
data.py
File metadata and controls
223 lines (185 loc) · 7.2 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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
from typing import Dict, Iterable, Optional
from datasets import load_dataset
from utils import extract_gold, normalize_answer
def load_gsm8k(split: str = "test", cache_dir: Optional[str] = None) -> Iterable[Dict]:
ds = load_dataset("gsm8k", "main", split=split, cache_dir=cache_dir)
for item in ds:
question = item["question"].strip()
solution = item["answer"]
gold = normalize_answer(extract_gold(solution))
yield {
"question": question,
"solution": solution,
"gold": gold,
}
def load_aime2025(split: str = "train", cache_dir: Optional[str] = None) -> Iterable[Dict]:
ds = load_dataset("yentinglin/aime_2025", split=split, cache_dir=cache_dir)
for item in ds:
problem = item["problem"].strip()
answer = str(item["answer"]).strip()
gold = normalize_answer(answer)
yield {
"question": problem,
"solution": answer,
"gold": gold,
}
def load_aime2024(split: str = "train", cache_dir: Optional[str] = None) -> Iterable[Dict]:
ds = load_dataset("HuggingFaceH4/aime_2024", split=split, cache_dir=cache_dir)
for item in ds:
problem = item["problem"].strip()
answer = str(item["answer"]).strip()
gold = normalize_answer(answer)
yield {
"question": problem,
"solution": answer,
"gold": gold,
}
def load_gpqa_diamond(split: str = "test", cache_dir: Optional[str] = None) -> Iterable[Dict]:
ds = load_dataset("fingertap/GPQA-Diamond", split=split, cache_dir=cache_dir)
for item in ds:
question = item["question"].strip()
answer = item["answer"].strip()
gold = normalize_answer(answer)
yield {
"question": question,
"solution": answer,
"gold": gold,
}
def load_arc_easy(split: str = "test", cache_dir: Optional[str] = None) -> Iterable[Dict]:
ds = load_dataset("allenai/ai2_arc", "ARC-Easy", split=split, cache_dir=cache_dir)
for item in ds:
stem = item["question"].strip()
choices = item["choices"]
labels = choices["label"]
texts = choices["text"]
label_map = {"1": "a", "2": "b", "3": "c", "4": "d"}
def map_label(l: str) -> str:
s = str(l).strip()
if s in label_map:
return label_map[s]
return s.lower()
# Map choices
formatted_choices = {}
mapped_order = []
for label, text in zip(labels, texts):
mlabel = map_label(label)
formatted_choices[mlabel] = text.strip()
mapped_order.append(mlabel)
ordered_lines = [f"{lab}: {formatted_choices[lab]}" for lab in mapped_order]
question = stem + "\n" + "\n".join(ordered_lines)
# Map answers
raw_answer = item.get("answerKey", "").strip()
mapped_answer = map_label(raw_answer) if raw_answer else ""
gold = normalize_answer(mapped_answer)
yield {
"question": question,
"solution": mapped_answer,
"gold": gold,
}
def load_arc_challenge(split: str = "test", cache_dir: Optional[str] = None) -> Iterable[Dict]:
ds = load_dataset("allenai/ai2_arc", "ARC-Challenge", split=split, cache_dir=cache_dir)
for item in ds:
stem = item["question"].strip()
choices = item["choices"]
labels = choices["label"]
texts = choices["text"]
label_map = {"1": "a", "2": "b", "3": "c", "4": "d"}
def map_label(l: str) -> str:
s = str(l).strip()
if s in label_map:
return label_map[s]
return s.lower()
formatted_choices = {}
mapped_order = []
for label, text in zip(labels, texts):
mlabel = map_label(label)
formatted_choices[mlabel] = text.strip()
mapped_order.append(mlabel)
ordered_lines = [f"{lab}: {formatted_choices[lab]}" for lab in mapped_order]
question = stem + "\n" + "\n".join(ordered_lines)
raw_answer = item.get("answerKey", "").strip()
mapped_answer = map_label(raw_answer) if raw_answer else ""
gold = normalize_answer(mapped_answer)
yield {
"question": question,
"solution": mapped_answer,
"gold": gold,
}
def load_winogrande(
split: str = "validation",
subset: str = "winogrande_debiased",
cache_dir: Optional[str] = None,
) -> Iterable[Dict]:
ds = load_dataset("allenai/winogrande", subset, split=split, cache_dir=cache_dir)
for item in ds:
ask_str = 'Pickout proper choice that fits the _ in the following sentence:'
sentence = item["sentence"].strip()
option1 = str(item["option1"]).strip()
option2 = str(item["option2"]).strip()
question = f"{ask_str}\n{sentence}\n1: {option1}\n2: {option2}"
answer = str(item["answer"])
gold = normalize_answer(answer)
yield {
"question": question,
"solution": answer,
"gold": gold,
}
def load_mbppplus(
split: str = "test",
subset: str = None,
cache_dir: Optional[str] = None,
) -> Iterable[Dict]:
ds = load_dataset("evalplus/mbppplus", subset, split=split, cache_dir=cache_dir)
for item in ds:
question = f"""Please provide a self-contained Python script that solves the following problem in a markdown code block:\n```python\nYOUR_PYTHON_CODE\n```:
{item["prompt"]}
Your answer will be tested on test cases like:
{item["test_list"][0]}
{item["test_list"][1]}
{item["test_list"][2]}
"""
answer = str(item["test"])
gold = answer
yield {
"question": question,
"solution": answer,
"gold": gold,
}
def load_humanevalplus(
split: str = "test",
subset: str = None,
cache_dir: Optional[str] = None,
) -> Iterable[Dict]:
ds = load_dataset("evalplus/humanevalplus", subset, split=split, cache_dir=cache_dir)
for item in ds:
question = f"""Please provide a self-contained Python script that solves the following problem in a markdown code block:\n```python\nYOUR_PYTHON_CODE\n```:
{item["prompt"]}
"""
raw_answer = str(item["test"])
answer = raw_answer.replace('candidate', item['entry_point'])
answer += f'\n\ncheck({item["entry_point"]})'
gold = answer
yield {
"question": question,
"solution": answer,
"gold": gold,
}
# qa data from https://github.com/lupantech/AgentFlow/tree/main
from typing import Iterable, Dict, Optional
from datasets import load_dataset
def load_medqa(split=None, subset=None, cache_dir=None):
ds = load_dataset("json", data_files="./data/medqa.json", split='train')
for item in ds:
question = item["query"]
raw_answer = str(item["answer"])
choice_map = {"0":"A", "1":"B", "2":"C", "3":"D"}
for idx, op in enumerate(item['options']):
if raw_answer in op:
answer = choice_map[str(idx)].lower()
break
gold = normalize_answer(answer)
yield {
"question": question,
"solution": answer,
"gold": gold,
}