kimvu commited on
Commit
cb6fe6b
·
1 Parent(s): 242aff5

Update agieval.py

Browse files
Files changed (1) hide show
  1. agieval.py +563 -236
agieval.py CHANGED
@@ -1,8 +1,432 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import datasets
2
  import json
3
  import ast
4
  import pandas as pd
5
  import csv
 
6
  _CITATION = """\
7
  @ARTICLE{10174688,
8
  author={Liu, Hanmeng and Liu, Jian and Cui, Leyang and Teng, Zhiyang and Duan, Nan and Zhou, Ming and Zhang, Yue},
@@ -14,6 +438,7 @@ _CITATION = """\
14
  pages={1-16},
15
  doi={10.1109/TASLP.2023.3293046}}
16
  """
 
17
  _DESCRIPTION = """\
18
  The dataset is an amendment and re-annotation of LogiQA in 2020, a large-scale logical reasoning reading comprehension dataset adapted from the Chinese Civil Service Examination. We increase the data size, refine the texts with manual translation by professionals, and improve the quality by removing items with distinctive cultural features like Chinese idioms. Furthermore, we conduct a fine-grained annotation on the dataset and turn it into a two-way natural language inference (NLI) task, resulting in 35k premise-hypothesis pairs with gold labels, making it the first large-scale NLI dataset for complex logical reasoning
19
  """
@@ -23,123 +448,92 @@ _HOMEPAGE = "https://github.com/csitfun/LogiQA2.0/tree/main"
23
  _LICENSE = (
24
  "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License"
25
  )
26
- english_qa_datasets = ["lsat-ar", "lsat-lr", "lsat-rc", "logiqa-en", "sat-math", "sat-en", "aqua-rat",
27
- "sat-en-without-passage", "gaokao-english"]
28
- chinese_qa_datasets = ["logiqa-zh", "jec-qa-kd", "jec-qa-ca", "gaokao-chinese", "gaokao-geography", "gaokao-history",
29
- "gaokao-biology", "gaokao-chemistry", "gaokao-physics", "gaokao-mathqa"]
30
- english_cloze_datasets = ["math"]
31
- chinese_cloze_datasets = ["gaokao-mathcloze"]
32
- all_lst = english_qa_datasets + chinese_qa_datasets + english_cloze_datasets + chinese_cloze_datasets
33
  HEAD= 'https://raw.githubusercontent.com/microsoft/AGIEval/main/data/v1/'
 
34
  _URLS = {
35
- e: {
36
- "test": HEAD+e+'.jsonl',
37
- } for e in all_lst
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
  }
40
- _URLS['few_shot'] ={'few_shot':'https://raw.githubusercontent.com/microsoft/AGIEval/main/data/few_shot_prompts.csv'}
41
 
42
  class AgiEval(datasets.GeneratorBasedBuilder):
43
  """TODO: Short description of my dataset."""
44
-
45
-
 
 
46
  BUILDER_CONFIGS = [
47
  datasets.BuilderConfig(
48
- name= e,
49
- version=datasets.Version("2.0.1"),
50
  description="",
51
- ) for e in all_lst
52
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  ]
54
  DEFAULT_CONFIG_NAME = "aqua_rat"
55
 
56
  def _info(self):
57
- # features = datasets.Features(
58
- # {
59
- # "question": datasets.Value("string"),
60
- # "options": datasets.features.Sequence(datasets.Value("string")),
61
- # "label": datasets.ClassLabel(num_classes=5, names=["A", "B", "C", "D", "E"]),
62
- # "solution": datasets.Value("string"),
63
- # }
64
- # )
65
- # if self.config.name == "aqua_rat":
66
- # features = datasets.Features(
67
- # {
68
- # "question": datasets.Value("string"),
69
- # "options": datasets.features.Sequence(datasets.Value("string")),
70
- # "label": datasets.ClassLabel(num_classes=5, names=["A", "B", "C", "D", "E"]),
71
- # "solution": datasets.Value("string"),
72
- # }
73
- # )
74
- # elif self.config.name in ["sat_en", "sat_math", "sat-en-without-passage"]:
75
- # features = datasets.Features(
76
- # {"passage": datasets.Value("string"),
77
- # "question": datasets.Value("string"),
78
- # "options": datasets.features.Sequence(datasets.Value("string")),
79
- # "label": datasets.ClassLabel(num_classes=4, names=["A", "B", "C", "D"]),
80
- # "solution": datasets.Value("string"),
81
- # }
82
- # )
83
- # elif self.config.name in ['logiqa-en', 'logiqa-zh']:
84
- # # remove solution from other
85
- # features = datasets.Features(
86
- # {"passage": datasets.Value("string"),
87
- # "question": datasets.Value("string"),
88
- # "options": datasets.features.Sequence(datasets.Value("string")),
89
- # "label": datasets.ClassLabel(num_classes=4, names=["A", "B", "C", "D"]),
90
- # "solution": datasets.Value("string"),
91
- # }
92
- # )
93
- # elif self.config.name == 'math':
94
- # features = datasets.Features(
95
- # {
96
- # "passage": datasets.Value("string"),
97
- # "question": datasets.Value("string"),
98
- # "answer": datasets.Value("string"),
99
- # "solution": datasets.Value("string"),
100
- # "level": datasets.Value("int32"),
101
- # "type": datasets.Value("string"),
102
- # }
103
- # )
104
- # elif self.config.name == 'gaokao-mathcloze':
105
- # features = datasets.Features(
106
- # {
107
- # "passage": datasets.Value("string"),
108
- # "question": datasets.Value("string"),
109
- # "answer": datasets.Value("string"),
110
- # "solution": datasets.Value("string"),
111
- # }
112
- # )
113
- # elif self.config.name in ['lsat_lr', 'lsat_rc', 'lsat_ar']:
114
- # features = datasets.Features(
115
- # {
116
- # "passage": datasets.Value("string"),
117
- # "question": datasets.Value("string"),
118
- # "options": datasets.features.Sequence(datasets.Value("string")),
119
- # "label": datasets.ClassLabel(num_classes=5, names=["A", "B", "C", "D", "E"]),
120
- # "solution": datasets.Value("string"),
121
- # }
122
- # )
123
- # elif self.config.name in ['gaokao-mathqa', 'gaokao-chinese', 'gaokao-history', 'gaokao-geography', 'gaokao-biology', 'gaokao-chemistry', 'gaokao-english']:
124
- # features = datasets.Features(
125
- # {
126
- # "passage": datasets.Value("string"),
127
- # "question": datasets.Value("string"),
128
- # "options": datasets.features.Sequence(datasets.Value("string")),
129
- # "label": datasets.ClassLabel(num_classes=4, names=["A", "B", "C", "D"]),
130
- # "solution": datasets.Value("string"),
131
- # }
132
- # )
133
- # elif self.config.name in ['gaokao-physics', 'jec-qa-ca', 'jec-qa-kd']:
134
- # features = datasets.Features(
135
- # {
136
- # "passage": datasets.Value("string"),
137
- # "question": datasets.Value("string"),
138
- # "options": datasets.features.Sequence(datasets.Value("string")),
139
- # "label": datasets.features.Sequence(datasets.Value("string")),
140
- # "solution": datasets.Value("string"),
141
- # }
142
- # )
143
  if self.config.name == "aqua_rat":
144
  features = datasets.Features(
145
  {
@@ -195,7 +589,7 @@ class AgiEval(datasets.GeneratorBasedBuilder):
195
  }
196
  )
197
 
198
-
199
  return datasets.DatasetInfo(
200
  description=_DESCRIPTION,
201
  features=features,
@@ -237,132 +631,77 @@ class AgiEval(datasets.GeneratorBasedBuilder):
237
  # Extract samples and explanations
238
  samples = df[df.index % 2 == 0].reset_index(drop=True)
239
  explanations = df[df.index % 2 != 0].reset_index(drop=True)
 
240
  for key in range(samples.shape[0]):
241
  try:
242
  data = ast.literal_eval(samples[names[self.config.name]][key])
243
  explanation_row = explanations[names[self.config.name]][key]
244
- if self.config.name == "aqua_rat":
245
- features = datasets.Features(
246
- {
247
- "passage": data["passage"],
248
- "question": data["question"],
249
- "options": data["options"],
250
- "label": data["label"],
251
- "solution": str(explanation_row),
252
- }
253
- )
254
- elif self.config.name in ["sat_en", "sat_math", "sat-en-without-passage"]:
255
- features = datasets.Features(
256
- {
257
- "passage": data["passage"],
258
- "question": data["question"],
259
- "options": data["options"],
260
- "label": data["label"],
261
- "solution": str(explanation_row),
262
- }
263
- )
264
- elif self.config.name in ['logiqa-en', 'logiqa-zh']:
265
- # remove solution from other
266
- features = datasets.Features(
267
- {
268
- "passage": data["passage"],
269
  "question": data["question"],
270
  "options": data["options"],
271
  "label": data["label"],
272
  "solution": str(explanation_row),
273
  }
274
- )
275
- elif self.config.name == 'math':
276
- features = datasets.Features(
277
- {
278
- "passage": data["passage"],
279
- "question": data["question"],
280
- "answer": data["answer"],
281
- "solution": str(explanation_row),
282
- "level": data["level"],
283
- "type": data["type"],
284
- }
285
- )
286
- elif self.config.name == 'gaokao-mathcloze':
287
- features = datasets.Features(
288
- {
289
- "passage": data["passage"],
290
- "question": data["question"],
291
- "answer": data["answer"],
292
- "solution": str(explanation_row),
293
- }
294
- )
 
 
 
 
 
 
 
 
295
  elif self.config.name in ['lsat_lr', 'lsat_rc', 'lsat_ar']:
296
- features = datasets.Features(
297
- {
298
- "passage": data["passage"],
299
- "question": data["question"],
300
- "options": data["options"],
301
- "label": data["label"],
302
- "solution": str(explanation_row),
303
- }
304
- )
305
- elif self.config.name in ['gaokao-mathqa', 'gaokao-chinese', 'gaokao-history', 'gaokao-geography', 'gaokao-biology', 'gaokao-chemistry', 'gaokao-english']:
306
- features = datasets.Features(
307
- {
308
- "passage": data["passage"],
309
- "question": data["question"],
310
- "options": data["options"],
311
- "label": data["label"],
312
- "solution": str(explanation_row),
313
- }
314
- )
315
- elif self.config.name in ['gaokao-physics', 'jec-qa-ca', 'jec-qa-kd']:
316
- features = datasets.Features(
317
- {
318
- "passage": data["passage"],
319
- "question": data["question"],
320
- "options": data["options"],
321
- "label": data["label"],
322
- "solution": str(explanation_row),
323
- }
324
- )
325
  except:
326
  pass
327
  else:
328
  with open(filepath, encoding="utf-8") as f:
329
  for key, row in enumerate(f):
330
  data = json.loads(row)
331
- if self.config.name == "aqua_rat":
332
- # yield key, {
333
- # "question": data["question"],
334
- # "options": data["options"],
335
- # "label": data["label"],
336
- # "solution": data["other"]["solution"],
337
- # }
338
  yield key, {
339
- "question": "",
340
- "options": "",
341
- "label": "",
342
- "solution": "",
343
  }
344
- elif self.config.name in ["sat-en-without-passage", "sat_en", "sat_math"]:
345
- label_index = "ABCDE".index(data["label"])
346
- if label_index > len(data["options"]) - 1:
347
- continue
348
- else:
349
- yield key, {
350
- "passage": data["passage"],
351
- "question": data["question"],
352
- "options": data["options"],
353
- "label": data["label"],
354
- "solution": data["other"]["solution"],
355
- }
356
-
357
- elif self.config.name in ['logiqa-en', 'logiqa-zh']:
358
  yield key, {
359
- "passage": data["passage"],
360
- "question": data["question"],
361
- "options": data["options"],
362
- "label": data["label"],
363
- "solution": data["label"],
364
  }
365
- elif self.config.name == 'math':
366
  if not data.get("level"):
367
  data["level"] = data['other']['level']
368
  if not data.get("type"):
@@ -374,35 +713,23 @@ class AgiEval(datasets.GeneratorBasedBuilder):
374
  "level": data["level"],
375
  "type": data["type"],
376
  }
377
- elif self.config.name == 'gaokao-mathcloze':
378
- yield key, {
379
- "passage": data["passage"],
380
- "question": data["question"],
381
- "answer": data["answer"],
382
- "solution": data["answer"],
383
- }
384
- elif self.config.name in ['lsat_lr', 'lsat_rc', 'lsat_ar']:
385
- yield key, {
386
- "passage": data["passage"],
387
- "question": data["question"],
388
- "options": data["options"],
389
- "label": data["label"],
390
- "solution": data["label"],
391
- }
392
- elif self.config.name in ['gaokao-mathqa', 'gaokao-chinese', 'gaokao-history', 'gaokao-geography', 'gaokao-biology', 'gaokao-chemistry', 'gaokao-english']:
393
- yield key, {
394
  "passage": data["passage"],
395
  "question": data["question"],
396
  "options": data["options"],
397
  "label": data["label"],
398
- "solution": data["label"],
399
- }
400
-
401
- elif self.config.name in ['gaokao-physics', 'jec-qa-ca', 'jec-qa-kd']:
402
  yield key, {
403
- "passage": data["passage"],
404
- "question": data["question"],
405
- "options": data["options"],
406
- "label": data["label"],
407
- "solution": data["label"],
408
  }
 
1
+ # import datasets
2
+ # import json
3
+ # import ast
4
+ # import pandas as pd
5
+ # import csv
6
+ # _CITATION = """\
7
+ # @ARTICLE{10174688,
8
+ # author={Liu, Hanmeng and Liu, Jian and Cui, Leyang and Teng, Zhiyang and Duan, Nan and Zhou, Ming and Zhang, Yue},
9
+ # journal={IEEE/ACM Transactions on Audio, Speech, and Language Processing},
10
+ # title={LogiQA 2.0 — An Improved Dataset for Logical Reasoning in Natural Language Understanding},
11
+ # year={2023},
12
+ # volume={},
13
+ # number={},
14
+ # pages={1-16},
15
+ # doi={10.1109/TASLP.2023.3293046}}
16
+ # """
17
+ # _DESCRIPTION = """\
18
+ # The dataset is an amendment and re-annotation of LogiQA in 2020, a large-scale logical reasoning reading comprehension dataset adapted from the Chinese Civil Service Examination. We increase the data size, refine the texts with manual translation by professionals, and improve the quality by removing items with distinctive cultural features like Chinese idioms. Furthermore, we conduct a fine-grained annotation on the dataset and turn it into a two-way natural language inference (NLI) task, resulting in 35k premise-hypothesis pairs with gold labels, making it the first large-scale NLI dataset for complex logical reasoning
19
+ # """
20
+
21
+ # _HOMEPAGE = "https://github.com/csitfun/LogiQA2.0/tree/main"
22
+
23
+ # _LICENSE = (
24
+ # "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License"
25
+ # )
26
+ # english_qa_datasets = ["lsat-ar", "lsat-lr", "lsat-rc", "logiqa-en", "sat-math", "sat-en", "aqua-rat",
27
+ # "sat-en-without-passage", "gaokao-english"]
28
+ # chinese_qa_datasets = ["logiqa-zh", "jec-qa-kd", "jec-qa-ca", "gaokao-chinese", "gaokao-geography", "gaokao-history",
29
+ # "gaokao-biology", "gaokao-chemistry", "gaokao-physics", "gaokao-mathqa"]
30
+ # english_cloze_datasets = ["math"]
31
+ # chinese_cloze_datasets = ["gaokao-mathcloze"]
32
+ # all_lst = english_qa_datasets + chinese_qa_datasets + english_cloze_datasets + chinese_cloze_datasets
33
+ # HEAD= 'https://raw.githubusercontent.com/microsoft/AGIEval/main/data/v1/'
34
+ # _URLS = {
35
+ # e: {
36
+ # "test": HEAD+e+'.jsonl',
37
+ # } for e in all_lst
38
+
39
+ # }
40
+ # _URLS['few_shot'] ={'few_shot':'https://raw.githubusercontent.com/microsoft/AGIEval/main/data/few_shot_prompts.csv'}
41
+
42
+ # class AgiEval(datasets.GeneratorBasedBuilder):
43
+ # """TODO: Short description of my dataset."""
44
+
45
+
46
+ # BUILDER_CONFIGS = [
47
+ # datasets.BuilderConfig(
48
+ # name= e,
49
+ # version=datasets.Version("2.0.1"),
50
+ # description="",
51
+ # ) for e in all_lst
52
+
53
+ # ]
54
+ # DEFAULT_CONFIG_NAME = "aqua_rat"
55
+
56
+ # def _info(self):
57
+ # # features = datasets.Features(
58
+ # # {
59
+ # # "question": datasets.Value("string"),
60
+ # # "options": datasets.features.Sequence(datasets.Value("string")),
61
+ # # "label": datasets.ClassLabel(num_classes=5, names=["A", "B", "C", "D", "E"]),
62
+ # # "solution": datasets.Value("string"),
63
+ # # }
64
+ # # )
65
+ # # if self.config.name == "aqua_rat":
66
+ # # features = datasets.Features(
67
+ # # {
68
+ # # "question": datasets.Value("string"),
69
+ # # "options": datasets.features.Sequence(datasets.Value("string")),
70
+ # # "label": datasets.ClassLabel(num_classes=5, names=["A", "B", "C", "D", "E"]),
71
+ # # "solution": datasets.Value("string"),
72
+ # # }
73
+ # # )
74
+ # # elif self.config.name in ["sat_en", "sat_math", "sat-en-without-passage"]:
75
+ # # features = datasets.Features(
76
+ # # {"passage": datasets.Value("string"),
77
+ # # "question": datasets.Value("string"),
78
+ # # "options": datasets.features.Sequence(datasets.Value("string")),
79
+ # # "label": datasets.ClassLabel(num_classes=4, names=["A", "B", "C", "D"]),
80
+ # # "solution": datasets.Value("string"),
81
+ # # }
82
+ # # )
83
+ # # elif self.config.name in ['logiqa-en', 'logiqa-zh']:
84
+ # # # remove solution from other
85
+ # # features = datasets.Features(
86
+ # # {"passage": datasets.Value("string"),
87
+ # # "question": datasets.Value("string"),
88
+ # # "options": datasets.features.Sequence(datasets.Value("string")),
89
+ # # "label": datasets.ClassLabel(num_classes=4, names=["A", "B", "C", "D"]),
90
+ # # "solution": datasets.Value("string"),
91
+ # # }
92
+ # # )
93
+ # # elif self.config.name == 'math':
94
+ # # features = datasets.Features(
95
+ # # {
96
+ # # "passage": datasets.Value("string"),
97
+ # # "question": datasets.Value("string"),
98
+ # # "answer": datasets.Value("string"),
99
+ # # "solution": datasets.Value("string"),
100
+ # # "level": datasets.Value("int32"),
101
+ # # "type": datasets.Value("string"),
102
+ # # }
103
+ # # )
104
+ # # elif self.config.name == 'gaokao-mathcloze':
105
+ # # features = datasets.Features(
106
+ # # {
107
+ # # "passage": datasets.Value("string"),
108
+ # # "question": datasets.Value("string"),
109
+ # # "answer": datasets.Value("string"),
110
+ # # "solution": datasets.Value("string"),
111
+ # # }
112
+ # # )
113
+ # # elif self.config.name in ['lsat_lr', 'lsat_rc', 'lsat_ar']:
114
+ # # features = datasets.Features(
115
+ # # {
116
+ # # "passage": datasets.Value("string"),
117
+ # # "question": datasets.Value("string"),
118
+ # # "options": datasets.features.Sequence(datasets.Value("string")),
119
+ # # "label": datasets.ClassLabel(num_classes=5, names=["A", "B", "C", "D", "E"]),
120
+ # # "solution": datasets.Value("string"),
121
+ # # }
122
+ # # )
123
+ # # elif self.config.name in ['gaokao-mathqa', 'gaokao-chinese', 'gaokao-history', 'gaokao-geography', 'gaokao-biology', 'gaokao-chemistry', 'gaokao-english']:
124
+ # # features = datasets.Features(
125
+ # # {
126
+ # # "passage": datasets.Value("string"),
127
+ # # "question": datasets.Value("string"),
128
+ # # "options": datasets.features.Sequence(datasets.Value("string")),
129
+ # # "label": datasets.ClassLabel(num_classes=4, names=["A", "B", "C", "D"]),
130
+ # # "solution": datasets.Value("string"),
131
+ # # }
132
+ # # )
133
+ # # elif self.config.name in ['gaokao-physics', 'jec-qa-ca', 'jec-qa-kd']:
134
+ # # features = datasets.Features(
135
+ # # {
136
+ # # "passage": datasets.Value("string"),
137
+ # # "question": datasets.Value("string"),
138
+ # # "options": datasets.features.Sequence(datasets.Value("string")),
139
+ # # "label": datasets.features.Sequence(datasets.Value("string")),
140
+ # # "solution": datasets.Value("string"),
141
+ # # }
142
+ # # )
143
+ # if self.config.name == "aqua_rat":
144
+ # features = datasets.Features(
145
+ # {
146
+ # "question": datasets.Value("string"),
147
+ # "options": datasets.features.Sequence(datasets.Value("string")),
148
+ # "label": datasets.ClassLabel(num_classes=5, names=["A", "B", "C", "D", "E"]),
149
+ # "solution": datasets.Value("string"),
150
+ # }
151
+ # )
152
+ # elif self.config.name == "sat_en":
153
+ # features = datasets.Features(
154
+ # {"passage": datasets.Value("string"),
155
+ # "question": datasets.Value("string"),
156
+ # "options": datasets.features.Sequence(datasets.Value("string")),
157
+ # "label": datasets.ClassLabel(num_classes=4, names=["A", "B", "C", "D"]),
158
+ # "solution": datasets.Value("string"),
159
+ # }
160
+ # )
161
+ # elif self.config.name == "sat_math":
162
+ # # remove solution from other
163
+ # features = datasets.Features(
164
+ # {"question": datasets.Value("string"),
165
+ # "options": datasets.features.Sequence(datasets.Value("string")),
166
+ # "label": datasets.ClassLabel(num_classes=4, names=["A", "B", "C", "D"]),
167
+ # "solution": datasets.Value("string"),
168
+ # }
169
+ # )
170
+ # elif self.config.name == "logiqa":
171
+ # # remove solution from other
172
+ # features = datasets.Features(
173
+ # {"passage": datasets.Value("string"),
174
+ # "question": datasets.Value("string"),
175
+ # "options": datasets.features.Sequence(datasets.Value("string")),
176
+ # "label": datasets.ClassLabel(num_classes=4, names=["A", "B", "C", "D"]),
177
+ # "solution": datasets.Value("string"),
178
+ # }
179
+ # )
180
+ # elif self.config.name == "math_agieval":
181
+ # features = datasets.Features(
182
+ # {"question": datasets.Value("string"),
183
+ # "answer": datasets.Value("string"),
184
+ # "solution": datasets.Value("string"),
185
+ # "level": datasets.Value("int32"),
186
+ # "type": datasets.Value("string"),
187
+ # }
188
+ # )
189
+ # elif self.config.name in ['lsat_lr', 'lsat_rc', 'lsat_ar']:
190
+ # features = datasets.Features(
191
+ # {"question": datasets.Value("string"),
192
+ # "options": datasets.features.Sequence(datasets.Value("string")),
193
+ # "label": datasets.ClassLabel(num_classes=5, names=["A", "B", "C", "D", "E"]),
194
+ # "solution": datasets.Value("string"),
195
+ # }
196
+ # )
197
+
198
+
199
+ # return datasets.DatasetInfo(
200
+ # description=_DESCRIPTION,
201
+ # features=features,
202
+ # homepage=_HOMEPAGE,
203
+ # license=_LICENSE,
204
+ # citation=_CITATION,
205
+ # )
206
+
207
+ # def _split_generators(self, dl_manager):
208
+ # _urls = _URLS[self.config.name]
209
+ # urls = {
210
+ # "test": _urls["test"],
211
+ # "few_shot": _URLS["few_shot"]["few_shot"],
212
+ # }
213
+ # data_dir = dl_manager.download_and_extract(urls)
214
+ # splits = [
215
+ # datasets.SplitGenerator(
216
+ # name=datasets.Split.TEST,
217
+ # gen_kwargs={"filepath": data_dir["test"], "split": "test"},
218
+ # ),
219
+ # ]
220
+ # splits.append(datasets.SplitGenerator(
221
+ # name="few_shot",
222
+ # gen_kwargs={"filepath": data_dir["few_shot"], "split": "few_shot"},
223
+ # ))
224
+
225
+ # return splits
226
+
227
+ # def _generate_examples(self, filepath, split):
228
+ # # Mapping for column names in CSV to dataset names
229
+ # names = {'aqua_rat': 'aqua-rat', 'sat_en': 'sat-en', 'sat_math': 'sat-math',
230
+ # 'lsat_ar': 'lsat-ar', 'lsat_lr': 'lsat-lr', 'lsat_rc': 'lsat-rc',
231
+ # 'logiqa': 'logiqa-en', 'math_agieval': 'math'}
232
+
233
+ # if split == "few_shot":
234
+ # # Load the data from the CSV
235
+ # df = pd.read_csv(filepath, keep_default_na=False)
236
+
237
+ # # Extract samples and explanations
238
+ # samples = df[df.index % 2 == 0].reset_index(drop=True)
239
+ # explanations = df[df.index % 2 != 0].reset_index(drop=True)
240
+ # for key in range(samples.shape[0]):
241
+ # try:
242
+ # data = ast.literal_eval(samples[names[self.config.name]][key])
243
+ # explanation_row = explanations[names[self.config.name]][key]
244
+ # if self.config.name == "aqua_rat":
245
+ # features = datasets.Features(
246
+ # {
247
+ # "passage": data["passage"],
248
+ # "question": data["question"],
249
+ # "options": data["options"],
250
+ # "label": data["label"],
251
+ # "solution": str(explanation_row),
252
+ # }
253
+ # )
254
+ # elif self.config.name in ["sat_en", "sat_math", "sat-en-without-passage"]:
255
+ # features = datasets.Features(
256
+ # {
257
+ # "passage": data["passage"],
258
+ # "question": data["question"],
259
+ # "options": data["options"],
260
+ # "label": data["label"],
261
+ # "solution": str(explanation_row),
262
+ # }
263
+ # )
264
+ # elif self.config.name in ['logiqa-en', 'logiqa-zh']:
265
+ # # remove solution from other
266
+ # features = datasets.Features(
267
+ # {
268
+ # "passage": data["passage"],
269
+ # "question": data["question"],
270
+ # "options": data["options"],
271
+ # "label": data["label"],
272
+ # "solution": str(explanation_row),
273
+ # }
274
+ # )
275
+ # elif self.config.name == 'math':
276
+ # features = datasets.Features(
277
+ # {
278
+ # "passage": data["passage"],
279
+ # "question": data["question"],
280
+ # "answer": data["answer"],
281
+ # "solution": str(explanation_row),
282
+ # "level": data["level"],
283
+ # "type": data["type"],
284
+ # }
285
+ # )
286
+ # elif self.config.name == 'gaokao-mathcloze':
287
+ # features = datasets.Features(
288
+ # {
289
+ # "passage": data["passage"],
290
+ # "question": data["question"],
291
+ # "answer": data["answer"],
292
+ # "solution": str(explanation_row),
293
+ # }
294
+ # )
295
+ # elif self.config.name in ['lsat_lr', 'lsat_rc', 'lsat_ar']:
296
+ # features = datasets.Features(
297
+ # {
298
+ # "passage": data["passage"],
299
+ # "question": data["question"],
300
+ # "options": data["options"],
301
+ # "label": data["label"],
302
+ # "solution": str(explanation_row),
303
+ # }
304
+ # )
305
+ # elif self.config.name in ['gaokao-mathqa', 'gaokao-chinese', 'gaokao-history', 'gaokao-geography', 'gaokao-biology', 'gaokao-chemistry', 'gaokao-english']:
306
+ # features = datasets.Features(
307
+ # {
308
+ # "passage": data["passage"],
309
+ # "question": data["question"],
310
+ # "options": data["options"],
311
+ # "label": data["label"],
312
+ # "solution": str(explanation_row),
313
+ # }
314
+ # )
315
+ # elif self.config.name in ['gaokao-physics', 'jec-qa-ca', 'jec-qa-kd']:
316
+ # features = datasets.Features(
317
+ # {
318
+ # "passage": data["passage"],
319
+ # "question": data["question"],
320
+ # "options": data["options"],
321
+ # "label": data["label"],
322
+ # "solution": str(explanation_row),
323
+ # }
324
+ # )
325
+ # except:
326
+ # pass
327
+ # else:
328
+ # with open(filepath, encoding="utf-8") as f:
329
+ # for key, row in enumerate(f):
330
+ # data = json.loads(row)
331
+ # if self.config.name == "aqua_rat":
332
+ # # yield key, {
333
+ # # "question": data["question"],
334
+ # # "options": data["options"],
335
+ # # "label": data["label"],
336
+ # # "solution": data["other"]["solution"],
337
+ # # }
338
+ # yield key, {
339
+ # "question": "",
340
+ # "options": "",
341
+ # "label": "",
342
+ # "solution": "",
343
+ # }
344
+ # elif self.config.name in ["sat-en-without-passage", "sat_en", "sat_math"]:
345
+ # label_index = "ABCDE".index(data["label"])
346
+ # if label_index > len(data["options"]) - 1:
347
+ # continue
348
+ # else:
349
+ # yield key, {
350
+ # "passage": data["passage"],
351
+ # "question": data["question"],
352
+ # "options": data["options"],
353
+ # "label": data["label"],
354
+ # "solution": data["other"]["solution"],
355
+ # }
356
+
357
+ # elif self.config.name in ['logiqa-en', 'logiqa-zh']:
358
+ # yield key, {
359
+ # "passage": data["passage"],
360
+ # "question": data["question"],
361
+ # "options": data["options"],
362
+ # "label": data["label"],
363
+ # "solution": data["label"],
364
+ # }
365
+ # elif self.config.name == 'math':
366
+ # if not data.get("level"):
367
+ # data["level"] = data['other']['level']
368
+ # if not data.get("type"):
369
+ # data["type"] = data['other']['type']
370
+ # yield key, {
371
+ # "question": data["question"],
372
+ # "answer": data["answer"],
373
+ # "solution": data["other"]["solution"],
374
+ # "level": data["level"],
375
+ # "type": data["type"],
376
+ # }
377
+ # elif self.config.name == 'gaokao-mathcloze':
378
+ # yield key, {
379
+ # "passage": data["passage"],
380
+ # "question": data["question"],
381
+ # "answer": data["answer"],
382
+ # "solution": data["answer"],
383
+ # }
384
+ # elif self.config.name in ['lsat_lr', 'lsat_rc', 'lsat_ar']:
385
+ # yield key, {
386
+ # "passage": data["passage"],
387
+ # "question": data["question"],
388
+ # "options": data["options"],
389
+ # "label": data["label"],
390
+ # "solution": data["label"],
391
+ # }
392
+ # elif self.config.name in ['gaokao-mathqa', 'gaokao-chinese', 'gaokao-history', 'gaokao-geography', 'gaokao-biology', 'gaokao-chemistry', 'gaokao-english']:
393
+ # yield key, {
394
+ # "passage": data["passage"],
395
+ # "question": data["question"],
396
+ # "options": data["options"],
397
+ # "label": data["label"],
398
+ # "solution": data["label"],
399
+ # }
400
+
401
+ # elif self.config.name in ['gaokao-physics', 'jec-qa-ca', 'jec-qa-kd']:
402
+ # yield key, {
403
+ # "passage": data["passage"],
404
+ # "question": data["question"],
405
+ # "options": data["options"],
406
+ # "label": data["label"],
407
+ # "solution": data["label"],
408
+ # }
409
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
410
+ #
411
+ # Licensed under the Apache License, Version 2.0 (the "License");
412
+ # you may not use this file except in compliance with the License.
413
+ # You may obtain a copy of the License at
414
+ #
415
+ # http://www.apache.org/licenses/LICENSE-2.0
416
+ #
417
+ # Unless required by applicable law or agreed to in writing, software
418
+ # distributed under the License is distributed on an "AS IS" BASIS,
419
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
420
+ # See the License for the specific language governing permissions and
421
+ # limitations under the License.
422
+ """LogiQA dataset."""
423
+
424
  import datasets
425
  import json
426
  import ast
427
  import pandas as pd
428
  import csv
429
+
430
  _CITATION = """\
431
  @ARTICLE{10174688,
432
  author={Liu, Hanmeng and Liu, Jian and Cui, Leyang and Teng, Zhiyang and Duan, Nan and Zhou, Ming and Zhang, Yue},
 
438
  pages={1-16},
439
  doi={10.1109/TASLP.2023.3293046}}
440
  """
441
+
442
  _DESCRIPTION = """\
443
  The dataset is an amendment and re-annotation of LogiQA in 2020, a large-scale logical reasoning reading comprehension dataset adapted from the Chinese Civil Service Examination. We increase the data size, refine the texts with manual translation by professionals, and improve the quality by removing items with distinctive cultural features like Chinese idioms. Furthermore, we conduct a fine-grained annotation on the dataset and turn it into a two-way natural language inference (NLI) task, resulting in 35k premise-hypothesis pairs with gold labels, making it the first large-scale NLI dataset for complex logical reasoning
444
  """
 
448
  _LICENSE = (
449
  "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License"
450
  )
 
 
 
 
 
 
 
451
  HEAD= 'https://raw.githubusercontent.com/microsoft/AGIEval/main/data/v1/'
452
+
453
  _URLS = {
454
+ "sat_en": {
455
+ "test": HEAD+'sat-en.jsonl',
456
+ },
457
+ "sat_math": {
458
+ "test": HEAD+'sat-math.jsonl'
459
+ },
460
+ "lsat_ar": {
461
+ "test": HEAD+'lsat-ar.jsonl'
462
+ },
463
+ "lsat_lr": {
464
+ "test": HEAD+'lsat-lr.jsonl'
465
+ },
466
+ "lsat_rc": {
467
+ "test": HEAD+'lsat-rc.jsonl'
468
+ },
469
+ "logiqa": {
470
+ "test": HEAD+'logiqa-en.jsonl'
471
+ },
472
+ "aqua_rat": {
473
+ "test": HEAD+'aqua-rat.jsonl'
474
+ },
475
+ 'math_agieval': {
476
+ "test": HEAD+'math.jsonl'
477
+ },
478
+ 'few_shot': {
479
+ 'few_shot':'https://raw.githubusercontent.com/microsoft/AGIEval/main/data/few_shot_prompts.csv'
480
+ }
481
 
482
  }
483
+
484
 
485
  class AgiEval(datasets.GeneratorBasedBuilder):
486
  """TODO: Short description of my dataset."""
487
+
488
+ VERSION = datasets.Version("2.0.1")
489
+ # 25/08/2023: Removed row 56 of `sat_en`(label > num_of_choices).
490
+
491
  BUILDER_CONFIGS = [
492
  datasets.BuilderConfig(
493
+ name="aqua_rat",
494
+ version=VERSION,
495
  description="",
496
+ ),
497
+ datasets.BuilderConfig(
498
+ name="sat_en",
499
+ version=VERSION,
500
+ description="",
501
+ ),
502
+ datasets.BuilderConfig(
503
+ name="sat_math",
504
+ version=VERSION,
505
+ description="",
506
+ ),
507
+ datasets.BuilderConfig(
508
+ name="lsat_ar",
509
+ version=VERSION,
510
+ description="",
511
+ ),
512
+ datasets.BuilderConfig(
513
+ name="lsat_lr",
514
+ version=VERSION,
515
+ description="",
516
+ ),
517
+ datasets.BuilderConfig(
518
+ name="lsat_rc",
519
+ version=VERSION,
520
+ description="",
521
+ ),
522
+ datasets.BuilderConfig(
523
+ name="logiqa",
524
+ version=VERSION,
525
+ description="",
526
+ ),
527
+ datasets.BuilderConfig(
528
+ name="math_agieval",
529
+ version=VERSION,
530
+ description="",
531
+ ),
532
  ]
533
  DEFAULT_CONFIG_NAME = "aqua_rat"
534
 
535
  def _info(self):
536
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
537
  if self.config.name == "aqua_rat":
538
  features = datasets.Features(
539
  {
 
589
  }
590
  )
591
 
592
+
593
  return datasets.DatasetInfo(
594
  description=_DESCRIPTION,
595
  features=features,
 
631
  # Extract samples and explanations
632
  samples = df[df.index % 2 == 0].reset_index(drop=True)
633
  explanations = df[df.index % 2 != 0].reset_index(drop=True)
634
+
635
  for key in range(samples.shape[0]):
636
  try:
637
  data = ast.literal_eval(samples[names[self.config.name]][key])
638
  explanation_row = explanations[names[self.config.name]][key]
639
+ if self.config.name in ["aqua_rat", "sat_math"]:
640
+ yield key, {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
641
  "question": data["question"],
642
  "options": data["options"],
643
  "label": data["label"],
644
  "solution": str(explanation_row),
645
  }
646
+ elif self.config.name == "logiqa":
647
+ yield key, {
648
+ "passage": data["passage"],
649
+ "question": data["question"],
650
+ "options": data["options"],
651
+ "label": data["label"],
652
+ "solution": str(explanation_row),
653
+ }
654
+ elif self.config.name == "math_agieval":
655
+ if not data.get("level"):
656
+ data["level"] = data['other']['level']
657
+ if not data.get("type"):
658
+ data["type"] = data['other']['type']
659
+ yield key, {
660
+ "question": data["question"],
661
+ "answer": data["answer"],
662
+ "level": data["level"],
663
+ "type": data["type"],
664
+ "solution": str(explanation_row),
665
+ }
666
+
667
+ elif self.config.name == "sat_en":
668
+ yield key, {
669
+ "passage": data["passage"],
670
+ "question": data["question"],
671
+ "options": data["options"],
672
+ "label": data["label"],
673
+ "solution": str(explanation_row),
674
+ }
675
  elif self.config.name in ['lsat_lr', 'lsat_rc', 'lsat_ar']:
676
+ yield key, {
677
+ "question": data["question"],
678
+ "options": data["options"],
679
+ "label": data["label"],
680
+ "solution": str(explanation_row),
681
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
682
  except:
683
  pass
684
  else:
685
  with open(filepath, encoding="utf-8") as f:
686
  for key, row in enumerate(f):
687
  data = json.loads(row)
688
+
689
+ if self.config.name in ["aqua_rat","sat_math"]:
 
 
 
 
 
690
  yield key, {
691
+ "question": data["question"],
692
+ "options": data["options"],
693
+ "label": data["label"],
694
+ "solution": data["other"]["solution"],
695
  }
696
+ elif self.config.name == "logiqa":
 
 
 
 
 
 
 
 
 
 
 
 
 
697
  yield key, {
698
+ "passage": data["passage"],
699
+ "question": data["question"],
700
+ "options": data["options"],
701
+ "label": data["label"],
702
+ "solution": data["label"],
703
  }
704
+ elif self.config.name == "math_agieval":
705
  if not data.get("level"):
706
  data["level"] = data['other']['level']
707
  if not data.get("type"):
 
713
  "level": data["level"],
714
  "type": data["type"],
715
  }
716
+
717
+ elif self.config.name == "sat_en":
718
+ label_index = "ABCDE".index(data["label"])
719
+ if label_index > len(data["options"]) - 1:
720
+ continue
721
+ else:
722
+ yield key, {
 
 
 
 
 
 
 
 
 
 
723
  "passage": data["passage"],
724
  "question": data["question"],
725
  "options": data["options"],
726
  "label": data["label"],
727
+ "solution": data["other"]["solution"],
728
+ }
729
+ elif self.config.name in ['lsat_lr', 'lsat_rc', 'lsat_ar']:
 
730
  yield key, {
731
+ "question": data["question"],
732
+ "options": data["options"],
733
+ "label": data["label"],
734
+ "solution": data["label"],
 
735
  }