kimvu commited on
Commit
45ce84e
·
1 Parent(s): be46d0e

Update agieval.py

Browse files
Files changed (1) hide show
  1. agieval.py +28 -443
agieval.py CHANGED
@@ -1,411 +1,3 @@
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");
@@ -456,43 +48,36 @@ chinese_qa_datasets = ["logiqa-zh", "jec-qa-kd", "jec-qa-ca", "gaokao-chinese",
456
  english_cloze_datasets = ["math"]
457
  chinese_cloze_datasets = ["gaokao-mathcloze"]
458
  all_lst = english_qa_datasets + chinese_qa_datasets + english_cloze_datasets + chinese_cloze_datasets
459
- HEAD= 'https://raw.githubusercontent.com/microsoft/AGIEval/main/data/v1/'
460
  _URLS = {
461
- e: {
462
- "test": HEAD+e+'.jsonl',
463
- } for e in all_lst}
464
- _URLS['few_shot'] ={'few_shot':'https://raw.githubusercontent.com/microsoft/AGIEval/main/data/few_shot_prompts.csv'}
465
-
466
- # _URLS = {
467
- # "sat_en": {
468
- # "test": HEAD+'sat-en.jsonl',
469
- # },
470
- # "sat_math": {
471
- # "test": HEAD+'sat-math.jsonl'
472
- # },
473
- # "lsat_ar": {
474
- # "test": HEAD+'lsat-ar.jsonl'
475
- # },
476
- # "lsat_lr": {
477
- # "test": HEAD+'lsat-lr.jsonl'
478
- # },
479
- # "lsat_rc": {
480
- # "test": HEAD+'lsat-rc.jsonl'
481
- # },
482
- # "logiqa": {
483
- # "test": HEAD+'logiqa-en.jsonl'
484
- # },
485
- # "aqua_rat": {
486
- # "test": HEAD+'aqua-rat.jsonl'
487
- # },
488
- # 'math_agieval': {
489
- # "test": HEAD+'math.jsonl'
490
- # },
491
- # 'few_shot': {
492
- # 'few_shot':'https://raw.githubusercontent.com/microsoft/AGIEval/main/data/few_shot_prompts.csv'
493
- # }
494
 
495
- # }
496
 
497
 
498
  class AgiEval(datasets.GeneratorBasedBuilder):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
  #
3
  # Licensed under the Apache License, Version 2.0 (the "License");
 
48
  english_cloze_datasets = ["math"]
49
  chinese_cloze_datasets = ["gaokao-mathcloze"]
50
  all_lst = english_qa_datasets + chinese_qa_datasets + english_cloze_datasets + chinese_cloze_datasets
 
51
  _URLS = {
52
+ "sat_en": {
53
+ "test": HEAD+'sat-en.jsonl',
54
+ },
55
+ "sat_math": {
56
+ "test": HEAD+'sat-math.jsonl'
57
+ },
58
+ "lsat_ar": {
59
+ "test": HEAD+'lsat-ar.jsonl'
60
+ },
61
+ "lsat_lr": {
62
+ "test": HEAD+'lsat-lr.jsonl'
63
+ },
64
+ "lsat_rc": {
65
+ "test": HEAD+'lsat-rc.jsonl'
66
+ },
67
+ "logiqa": {
68
+ "test": HEAD+'logiqa-en.jsonl'
69
+ },
70
+ "aqua_rat": {
71
+ "test": HEAD+'aqua-rat.jsonl'
72
+ },
73
+ 'math_agieval': {
74
+ "test": HEAD+'math.jsonl'
75
+ },
76
+ 'few_shot': {
77
+ 'few_shot':'https://raw.githubusercontent.com/microsoft/AGIEval/main/data/few_shot_prompts.csv'
78
+ }
 
 
 
 
 
 
79
 
80
+ }
81
 
82
 
83
  class AgiEval(datasets.GeneratorBasedBuilder):