baber commited on
Commit
6f26501
1 Parent(s): 6c0fa7f

Create agieval.py

Browse files
Files changed (1) hide show
  1. agieval.py +208 -0
agieval.py ADDED
@@ -0,0 +1,208 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ """LogiQA dataset."""
15
+
16
+ import datasets
17
+ import json
18
+ import ast
19
+
20
+ _CITATION = """\
21
+ @ARTICLE{10174688,
22
+ author={Liu, Hanmeng and Liu, Jian and Cui, Leyang and Teng, Zhiyang and Duan, Nan and Zhou, Ming and Zhang, Yue},
23
+ journal={IEEE/ACM Transactions on Audio, Speech, and Language Processing},
24
+ title={LogiQA 2.0 — An Improved Dataset for Logical Reasoning in Natural Language Understanding},
25
+ year={2023},
26
+ volume={},
27
+ number={},
28
+ pages={1-16},
29
+ doi={10.1109/TASLP.2023.3293046}}
30
+ """
31
+
32
+ _DESCRIPTION = """\
33
+ 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
34
+ """
35
+
36
+ _HOMEPAGE = "https://github.com/csitfun/LogiQA2.0/tree/main"
37
+
38
+ _LICENSE = (
39
+ "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License"
40
+ )
41
+ HEAD= 'https://raw.githubusercontent.com/microsoft/AGIEval/main/data/v1/'
42
+
43
+ _URLS = {
44
+ "sat_en": {
45
+ "test": HEAD+'sat-en.jsonl',
46
+ },
47
+ "sat_math": {
48
+ "test": HEAD+'sat-math.jsonl'
49
+ },
50
+ "lsat_ar": {
51
+ "test": HEAD+'lsat-ar.jsonl'
52
+ },
53
+ "lsat_lr": {
54
+ "test": HEAD+'lsat-lr.jsonl'
55
+ },
56
+ "lsat_rc": {
57
+ "test": HEAD+'lsat-rc.jsonl'
58
+ },
59
+ "logiqa": {
60
+ "test": HEAD+'logiqa-en.jsonl'
61
+ },
62
+ "aqua_rat": {
63
+ "test": HEAD+'aqua_rat.jsonl'
64
+ },
65
+ 'math_agieval': {
66
+ "test": HEAD+'math.jsonl'
67
+ },
68
+ }
69
+
70
+
71
+ class LogiQA2(datasets.GeneratorBasedBuilder):
72
+ """TODO: Short description of my dataset."""
73
+
74
+ VERSION = datasets.Version("2.0.0")
75
+
76
+ # This is an example of a dataset with multiple configurations.
77
+ # If you don't want/need to define several sub-sets in your dataset,
78
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
79
+
80
+ # If you need to make complex sub-parts in the datasets with configurable options
81
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
82
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
83
+
84
+ # You will be able to load one or the other configurations in the following list with
85
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
86
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
87
+ BUILDER_CONFIGS = [
88
+ datasets.BuilderConfig(
89
+ name="logiqa2",
90
+ version=VERSION,
91
+ description="The LogiQA multiple answer dataset translated in English from Chinese.",
92
+ ),
93
+ datasets.BuilderConfig(
94
+ name="logiqa2_zh",
95
+ version=VERSION,
96
+ description="The original LogiQA multiple answer dataset in Chinese.",
97
+ ),
98
+ datasets.BuilderConfig(
99
+ name="logiqa2_nli",
100
+ version=VERSION,
101
+ description="The NLI part of LogiQA2.0 dataset",
102
+ ),
103
+ ]
104
+ DEFAULT_CONFIG_NAME = "logiqa2"
105
+
106
+ def _info(self):
107
+
108
+ if self.config.name == "aqua_rat":
109
+ features = datasets.Features(
110
+ {
111
+ "question": datasets.Value("string"),
112
+ "options": datasets.features.Sequence(datasets.Value("string")),
113
+ "label": datasets.ClassLabel(num_classes=5, names=["A", "B", "C", "D", "E"]),
114
+ "solution": datasets.Value("string"),
115
+ }
116
+ )
117
+ elif self.config.name == "sat_en":
118
+ features = datasets.Features(
119
+ {"passage": datasets.Value("string"),
120
+ "question": datasets.Value("string"),
121
+ "options": datasets.features.Sequence(datasets.Value("string")),
122
+ "label": datasets.ClassLabel(num_classes=4, names=["A", "B", "C", "D"]),
123
+ "solution": datasets.Value("string"),
124
+ }
125
+ )
126
+ elif self.config.name in ["sat_math", "logiqa"]:
127
+ # remove solution from other
128
+ features = datasets.Features(
129
+ {"question": datasets.Value("string"),
130
+ "options": datasets.features.Sequence(datasets.Value("string")),
131
+ "label": datasets.ClassLabel(num_classes=4, names=["A", "B", "C", "D"]),
132
+ "solution": datasets.Value("string"),
133
+ }
134
+ )
135
+ elif self.config.name == "math_agieval":
136
+ features = datasets.Features(
137
+ {"question": datasets.Value("string"),
138
+ "answer": datasets.features.Sequence(datasets.Value("string")),
139
+ "solution": datasets.Value("string"),
140
+ "level": datasets.Value("int32"),
141
+ "type": datasets.Value("string"),
142
+ }
143
+ )
144
+ elif self.config.name in ['lsat_lr', 'lsat_rc', 'lsat_ar']:
145
+ features = datasets.Features(
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
+ }
150
+ )
151
+
152
+
153
+ return datasets.DatasetInfo(
154
+ description=_DESCRIPTION,
155
+ features=features,
156
+ homepage=_HOMEPAGE,
157
+ license=_LICENSE,
158
+ citation=_CITATION,
159
+ )
160
+
161
+ def _split_generators(self, dl_manager):
162
+ _urls = _URLS[self.config.name]
163
+ urls = {
164
+ "test": _urls["test"],
165
+ }
166
+ data_dir = dl_manager.download_and_extract(urls)
167
+ return [
168
+ datasets.SplitGenerator(
169
+ name=datasets.Split.TEST,
170
+ gen_kwargs={"filepath": data_dir["test"], "split": "test"},
171
+ ),
172
+ ]
173
+
174
+ def _generate_examples(self, filepath, split):
175
+ with open(filepath, encoding="utf-8") as f:
176
+ for key, row in enumerate(f):
177
+ data = json.loads(row)
178
+
179
+ if self.config.name in ["aqua_rat","sat_math", "logiqa"]:
180
+ yield key, {
181
+ "question": data["question"],
182
+ "options": data["options"],
183
+ "label": data["label"],
184
+ "solution": data["other"]["solution"],
185
+ }
186
+ elif self.config.name == "math_agieval":
187
+ yield key, {
188
+ "question": data["question"],
189
+ "answer": data["answer"],
190
+ "solution": data["solution"],
191
+ "level": data["level"],
192
+ "type": data["type"]
193
+ }
194
+
195
+ elif self.config.name == "sat_en":
196
+ yield key, {
197
+ "passage": data["passage"],
198
+ "question": data["question"],
199
+ "options": data["options"],
200
+ "label": data["label"],
201
+ "solution": data["other"]["solution"],
202
+ }
203
+ elif self.config.name in ['lsat_lr', 'lsat_rc', 'lsat_ar']:
204
+ yield key, {
205
+ "question": data["question"],
206
+ "options": data["options"],
207
+ "label": data["label"],
208
+ }