Update agieval.py
Browse filesadded few_shot split
- agieval.py +63 -21
agieval.py
CHANGED
@@ -16,6 +16,7 @@
|
|
16 |
import datasets
|
17 |
import json
|
18 |
import ast
|
|
|
19 |
import csv
|
20 |
|
21 |
_CITATION = """\
|
@@ -169,6 +170,7 @@ class AgiEval(datasets.GeneratorBasedBuilder):
|
|
169 |
"question": datasets.Value("string"),
|
170 |
"options": datasets.features.Sequence(datasets.Value("string")),
|
171 |
"label": datasets.ClassLabel(num_classes=4, names=["A", "B", "C", "D"]),
|
|
|
172 |
}
|
173 |
)
|
174 |
elif self.config.name == "math_agieval":
|
@@ -185,6 +187,7 @@ class AgiEval(datasets.GeneratorBasedBuilder):
|
|
185 |
{"question": datasets.Value("string"),
|
186 |
"options": datasets.features.Sequence(datasets.Value("string")),
|
187 |
"label": datasets.ClassLabel(num_classes=5, names=["A", "B", "C", "D", "E"]),
|
|
|
188 |
}
|
189 |
)
|
190 |
|
@@ -218,30 +221,68 @@ class AgiEval(datasets.GeneratorBasedBuilder):
|
|
218 |
return splits
|
219 |
|
220 |
def _generate_examples(self, filepath, split):
|
|
|
|
|
|
|
|
|
|
|
221 |
if split == "few_shot":
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
239 |
yield key, {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
240 |
"question": data["question"],
|
241 |
"options": data["options"],
|
242 |
-
"label": data
|
243 |
-
"solution":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
244 |
}
|
|
|
|
|
245 |
else:
|
246 |
with open(filepath, encoding="utf-8") as f:
|
247 |
for key, row in enumerate(f):
|
@@ -260,6 +301,7 @@ class AgiEval(datasets.GeneratorBasedBuilder):
|
|
260 |
"question": data["question"],
|
261 |
"options": data["options"],
|
262 |
"label": data["label"],
|
|
|
263 |
}
|
264 |
elif self.config.name == "math_agieval":
|
265 |
if not data.get("level"):
|
@@ -271,7 +313,7 @@ class AgiEval(datasets.GeneratorBasedBuilder):
|
|
271 |
"answer": data["answer"],
|
272 |
"solution": data["other"]["solution"],
|
273 |
"level": data["level"],
|
274 |
-
"type": data["type"]
|
275 |
}
|
276 |
|
277 |
elif self.config.name == "sat_en":
|
@@ -287,5 +329,5 @@ class AgiEval(datasets.GeneratorBasedBuilder):
|
|
287 |
"question": data["question"],
|
288 |
"options": data["options"],
|
289 |
"label": data["label"],
|
|
|
290 |
}
|
291 |
-
|
|
|
16 |
import datasets
|
17 |
import json
|
18 |
import ast
|
19 |
+
import pandas as pd
|
20 |
import csv
|
21 |
|
22 |
_CITATION = """\
|
|
|
170 |
"question": datasets.Value("string"),
|
171 |
"options": datasets.features.Sequence(datasets.Value("string")),
|
172 |
"label": datasets.ClassLabel(num_classes=4, names=["A", "B", "C", "D"]),
|
173 |
+
"solution": datasets.Value("string"),
|
174 |
}
|
175 |
)
|
176 |
elif self.config.name == "math_agieval":
|
|
|
187 |
{"question": datasets.Value("string"),
|
188 |
"options": datasets.features.Sequence(datasets.Value("string")),
|
189 |
"label": datasets.ClassLabel(num_classes=5, names=["A", "B", "C", "D", "E"]),
|
190 |
+
"solution": datasets.Value("string"),
|
191 |
}
|
192 |
)
|
193 |
|
|
|
221 |
return splits
|
222 |
|
223 |
def _generate_examples(self, filepath, split):
|
224 |
+
# Mapping for column names in CSV to dataset names
|
225 |
+
names = {'aqua_rat': 'aqua-rat', 'sat_en': 'sat-en', 'sat_math': 'sat-math',
|
226 |
+
'lsat_ar': 'lsat-ar', 'lsat_lr': 'lsat-lr', 'lsat_rc': 'lsat-rc',
|
227 |
+
'logiqa': 'logiqa-en', 'math_agieval': 'math'}
|
228 |
+
|
229 |
if split == "few_shot":
|
230 |
+
# Load the data from the CSV
|
231 |
+
df = pd.read_csv(filepath, keep_default_na=False)
|
232 |
+
|
233 |
+
# Extract samples and explanations
|
234 |
+
samples = df[df.index % 2 == 0].reset_index(drop=True)
|
235 |
+
explanations = df[df.index % 2 != 0].reset_index(drop=True)
|
236 |
+
|
237 |
+
for key in range(samples.shape[0]):
|
238 |
+
try:
|
239 |
+
data = ast.literal_eval(samples[names[self.config.name]][key])
|
240 |
+
explanation_row = explanations[names[self.config.name]][key]
|
241 |
+
if self.config.name in ["aqua_rat", "sat_math"]:
|
242 |
+
yield key, {
|
243 |
+
"question": data["question"],
|
244 |
+
"options": data["options"],
|
245 |
+
"label": data["label"],
|
246 |
+
"solution": str(explanation_row),
|
247 |
+
}
|
248 |
+
elif self.config.name == "logiqa":
|
249 |
+
yield key, {
|
250 |
+
"passage": data["passage"],
|
251 |
+
"question": data["question"],
|
252 |
+
"options": data["options"],
|
253 |
+
"label": data["label"],
|
254 |
+
"solution": str(explanation_row),
|
255 |
+
}
|
256 |
+
elif self.config.name == "math_agieval":
|
257 |
+
if not data.get("level"):
|
258 |
+
data["level"] = data['other']['level']
|
259 |
+
if not data.get("type"):
|
260 |
+
data["type"] = data['other']['type']
|
261 |
yield key, {
|
262 |
+
"question": data["question"],
|
263 |
+
"answer": data["answer"],
|
264 |
+
"level": data["level"],
|
265 |
+
"type": data["type"],
|
266 |
+
"solution": str(explanation_row),
|
267 |
+
}
|
268 |
+
|
269 |
+
elif self.config.name == "sat_en":
|
270 |
+
yield key, {
|
271 |
+
"passage": data["passage"],
|
272 |
"question": data["question"],
|
273 |
"options": data["options"],
|
274 |
+
"label": data["label"],
|
275 |
+
"solution": str(explanation_row),
|
276 |
+
}
|
277 |
+
elif self.config.name in ['lsat_lr', 'lsat_rc', 'lsat_ar']:
|
278 |
+
yield key, {
|
279 |
+
"question": data["question"],
|
280 |
+
"options": data["options"],
|
281 |
+
"label": data["label"],
|
282 |
+
"solution": str(explanation_row),
|
283 |
}
|
284 |
+
except:
|
285 |
+
pass
|
286 |
else:
|
287 |
with open(filepath, encoding="utf-8") as f:
|
288 |
for key, row in enumerate(f):
|
|
|
301 |
"question": data["question"],
|
302 |
"options": data["options"],
|
303 |
"label": data["label"],
|
304 |
+
"solution": data["label"],
|
305 |
}
|
306 |
elif self.config.name == "math_agieval":
|
307 |
if not data.get("level"):
|
|
|
313 |
"answer": data["answer"],
|
314 |
"solution": data["other"]["solution"],
|
315 |
"level": data["level"],
|
316 |
+
"type": data["type"],
|
317 |
}
|
318 |
|
319 |
elif self.config.name == "sat_en":
|
|
|
329 |
"question": data["question"],
|
330 |
"options": data["options"],
|
331 |
"label": data["label"],
|
332 |
+
"solution": data["label"],
|
333 |
}
|
|