Update agieval.py
Browse files- agieval.py +81 -46
agieval.py
CHANGED
|
@@ -16,6 +16,7 @@
|
|
| 16 |
import datasets
|
| 17 |
import json
|
| 18 |
import ast
|
|
|
|
| 19 |
|
| 20 |
_CITATION = """\
|
| 21 |
@ARTICLE{10174688,
|
|
@@ -65,6 +66,9 @@ _URLS = {
|
|
| 65 |
'math_agieval': {
|
| 66 |
"test": HEAD+'math.jsonl'
|
| 67 |
},
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
}
|
| 70 |
|
|
@@ -197,59 +201,90 @@ class AgiEval(datasets.GeneratorBasedBuilder):
|
|
| 197 |
_urls = _URLS[self.config.name]
|
| 198 |
urls = {
|
| 199 |
"test": _urls["test"],
|
|
|
|
| 200 |
}
|
| 201 |
data_dir = dl_manager.download_and_extract(urls)
|
| 202 |
-
|
| 203 |
datasets.SplitGenerator(
|
| 204 |
name=datasets.Split.TEST,
|
| 205 |
gen_kwargs={"filepath": data_dir["test"], "split": "test"},
|
| 206 |
),
|
| 207 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
|
| 209 |
def _generate_examples(self, filepath, split):
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
|
|
|
|
| 16 |
import datasets
|
| 17 |
import json
|
| 18 |
import ast
|
| 19 |
+
import csv
|
| 20 |
|
| 21 |
_CITATION = """\
|
| 22 |
@ARTICLE{10174688,
|
|
|
|
| 66 |
'math_agieval': {
|
| 67 |
"test": HEAD+'math.jsonl'
|
| 68 |
},
|
| 69 |
+
'few_shot': {
|
| 70 |
+
'few_shot': HEAD+'https://raw.githubusercontent.com/microsoft/AGIEval/main/data/few_shot_prompts.csv'
|
| 71 |
+
}
|
| 72 |
|
| 73 |
}
|
| 74 |
|
|
|
|
| 201 |
_urls = _URLS[self.config.name]
|
| 202 |
urls = {
|
| 203 |
"test": _urls["test"],
|
| 204 |
+
"few_shot": _URLS["few_shot"]["few_shot"],
|
| 205 |
}
|
| 206 |
data_dir = dl_manager.download_and_extract(urls)
|
| 207 |
+
splits = [
|
| 208 |
datasets.SplitGenerator(
|
| 209 |
name=datasets.Split.TEST,
|
| 210 |
gen_kwargs={"filepath": data_dir["test"], "split": "test"},
|
| 211 |
),
|
| 212 |
]
|
| 213 |
+
splits.append(datasets.SplitGenerator(
|
| 214 |
+
name="few_shot",
|
| 215 |
+
gen_kwargs={"filepath": data_dir["few_shot"], "split": "few_shot"},
|
| 216 |
+
))
|
| 217 |
+
|
| 218 |
+
return splits
|
| 219 |
|
| 220 |
def _generate_examples(self, filepath, split):
|
| 221 |
+
if split == "few_shot":
|
| 222 |
+
with open(filepath, mode="r", encoding="utf-8") as csv_file:
|
| 223 |
+
reader = csv.DictReader(csv_file)
|
| 224 |
+
|
| 225 |
+
# Extract data for the current dataset configuration
|
| 226 |
+
for key, row in enumerate(reader):
|
| 227 |
+
data_str = row[self.config.name]
|
| 228 |
+
|
| 229 |
+
# Skip if there's no data for this key (can happen due to alternating samples and explanations)
|
| 230 |
+
if pd.isnull(data_str):
|
| 231 |
+
continue
|
| 232 |
+
|
| 233 |
+
# Convert the string representation into a dictionary
|
| 234 |
+
data = json.loads(data_str.replace("'", "\""))
|
| 235 |
+
|
| 236 |
+
# Depending on the dataset, yield the correct format
|
| 237 |
+
if self.config.name in ["aqua_rat", "sat_math", "sat_en"]:
|
| 238 |
+
yield key, {
|
| 239 |
+
"question": data["question"],
|
| 240 |
+
"options": data["options"],
|
| 241 |
+
"label": data.get("label", None),
|
| 242 |
+
"solution": data.get("solution", None)
|
| 243 |
+
}
|
| 244 |
+
else:
|
| 245 |
+
with open(filepath, encoding="utf-8") as f:
|
| 246 |
+
for key, row in enumerate(f):
|
| 247 |
+
data = json.loads(row)
|
| 248 |
+
|
| 249 |
+
if self.config.name in ["aqua_rat","sat_math"]:
|
| 250 |
+
yield key, {
|
| 251 |
+
"question": data["question"],
|
| 252 |
+
"options": data["options"],
|
| 253 |
+
"label": data["label"],
|
| 254 |
+
"solution": data["other"]["solution"],
|
| 255 |
+
}
|
| 256 |
+
elif self.config.name == "logiqa":
|
| 257 |
+
yield key, {
|
| 258 |
+
"passage": data["passage"],
|
| 259 |
+
"question": data["question"],
|
| 260 |
+
"options": data["options"],
|
| 261 |
+
"label": data["label"],
|
| 262 |
+
}
|
| 263 |
+
elif self.config.name == "math_agieval":
|
| 264 |
+
if not data.get("level"):
|
| 265 |
+
data["level"] = data['other']['level']
|
| 266 |
+
if not data.get("type"):
|
| 267 |
+
data["type"] = data['other']['type']
|
| 268 |
+
yield key, {
|
| 269 |
+
"question": data["question"],
|
| 270 |
+
"answer": data["answer"],
|
| 271 |
+
"solution": data["other"]["solution"],
|
| 272 |
+
"level": data["level"],
|
| 273 |
+
"type": data["type"]
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
elif self.config.name == "sat_en":
|
| 277 |
+
yield key, {
|
| 278 |
+
"passage": data["passage"],
|
| 279 |
+
"question": data["question"],
|
| 280 |
+
"options": data["options"],
|
| 281 |
+
"label": data["label"],
|
| 282 |
+
"solution": data["other"]["solution"],
|
| 283 |
+
}
|
| 284 |
+
elif self.config.name in ['lsat_lr', 'lsat_rc', 'lsat_ar']:
|
| 285 |
+
yield key, {
|
| 286 |
+
"question": data["question"],
|
| 287 |
+
"options": data["options"],
|
| 288 |
+
"label": data["label"],
|
| 289 |
+
}
|
| 290 |
|