baber commited on
Commit
5afa273
1 Parent(s): 52f1b88

Update agieval.py

Browse files
Files changed (1) hide show
  1. 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
- return [
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
- with open(filepath, encoding="utf-8") as f:
211
- for key, row in enumerate(f):
212
- data = json.loads(row)
213
-
214
- if self.config.name in ["aqua_rat","sat_math"]:
215
- yield key, {
216
- "question": data["question"],
217
- "options": data["options"],
218
- "label": data["label"],
219
- "solution": data["other"]["solution"],
220
- }
221
- elif self.config.name == "logiqa":
222
- yield key, {
223
- "passage": data["passage"],
224
- "question": data["question"],
225
- "options": data["options"],
226
- "label": data["label"],
227
- }
228
- elif self.config.name == "math_agieval":
229
- if not data.get("level"):
230
- data["level"] = data['other']['level']
231
- if not data.get("type"):
232
- data["type"] = data['other']['type']
233
- yield key, {
234
- "question": data["question"],
235
- "answer": data["answer"],
236
- "solution": data["other"]["solution"],
237
- "level": data["level"],
238
- "type": data["type"]
239
- }
240
-
241
- elif self.config.name == "sat_en":
242
- yield key, {
243
- "passage": data["passage"],
244
- "question": data["question"],
245
- "options": data["options"],
246
- "label": data["label"],
247
- "solution": data["other"]["solution"],
248
- }
249
- elif self.config.name in ['lsat_lr', 'lsat_rc', 'lsat_ar']:
250
- yield key, {
251
- "question": data["question"],
252
- "options": data["options"],
253
- "label": data["label"],
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