yuzhen17 commited on
Commit
f283002
1 Parent(s): e13ba09

Upload ceval-exam.py

Browse files
Files changed (1) hide show
  1. ceval-exam.py +161 -0
ceval-exam.py ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ import os
15
+
16
+ import datasets
17
+ import pandas as pd
18
+
19
+
20
+ _CITATION = """\
21
+ TBD
22
+ """
23
+
24
+ _DESCRIPTION = """\
25
+ TBD
26
+ """
27
+
28
+ _HOMEPAGE = "https://cevalbenchmark.com"
29
+
30
+ _LICENSE = "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License"
31
+
32
+ _URL = r"https://huggingface.co/datasets/ceval/ceval-exam/resolve/main/ceval_data.tar"
33
+
34
+ task_list = [
35
+ "computer_network",
36
+ "operating_system",
37
+ "computer_architecture",
38
+ "college_programming",
39
+ "college_physics",
40
+ "college_chemistry",
41
+ "advanced_mathematics",
42
+ "probability_and_statistics",
43
+ "discrete_mathematics",
44
+ "electrical_engineer",
45
+ "metrology_engineer",
46
+ "high_school_mathematics",
47
+ "high_school_physics",
48
+ "high_school_chemistry",
49
+ "high_school_biology",
50
+ "middle_school_mathematics",
51
+ "middle_school_biology",
52
+ "middle_school_physics",
53
+ "middle_school_chemistry",
54
+ "veterinary_medicine",
55
+ "college_economics",
56
+ "business_administration",
57
+ "marxism",
58
+ "mao_zedong_thought",
59
+ "education_science",
60
+ "teacher_qualification",
61
+ "high_school_politics",
62
+ "high_school_geography",
63
+ "middle_school_politics",
64
+ "middle_school_geography",
65
+ "modern_chinese_history",
66
+ "ideological_and_moral_cultivation",
67
+ "logic",
68
+ "law",
69
+ "chinese_language_and_literature",
70
+ "art_studies",
71
+ "professional_tour_guide",
72
+ "legal_professional",
73
+ "high_school_chinese",
74
+ "high_school_history",
75
+ "middle_school_history",
76
+ "civil_servant",
77
+ "sports_science",
78
+ "plant_protection",
79
+ "basic_medicine",
80
+ "clinical_medicine",
81
+ "urban_and_rural_planner",
82
+ "accountant",
83
+ "fire_engineer",
84
+ "environmental_impact_assessment_engineer",
85
+ "tax_accountant",
86
+ "physician",
87
+ ]
88
+
89
+
90
+ class CevalExamConfig(datasets.BuilderConfig):
91
+ def __init__(self, **kwargs):
92
+ super().__init__(version=datasets.Version("1.0.0"), **kwargs)
93
+
94
+
95
+ class CevalExam(datasets.GeneratorBasedBuilder):
96
+ BUILDER_CONFIGS = [
97
+ CevalExamConfig(
98
+ name=task_name,
99
+ )
100
+ for task_name in task_list
101
+ ]
102
+
103
+ def _info(self):
104
+ features = datasets.Features(
105
+ {
106
+ "id":datasets.Value("int32"),
107
+ "question": datasets.Value("string"),
108
+ "A": datasets.Value("string"),
109
+ "B": datasets.Value("string"),
110
+ "C": datasets.Value("string"),
111
+ "D": datasets.Value("string"),
112
+ "answer": datasets.Value("string"),
113
+ "explanation":datasets.Value("string"),
114
+ }
115
+ )
116
+ return datasets.DatasetInfo(
117
+ description=_DESCRIPTION,
118
+ features=features,
119
+ homepage=_HOMEPAGE,
120
+ license=_LICENSE,
121
+ citation=_CITATION,
122
+ )
123
+
124
+ def _split_generators(self, dl_manager):
125
+ data_dir = dl_manager.download_and_extract(_URL)
126
+ task_name = self.config.name
127
+ return [
128
+ datasets.SplitGenerator(
129
+ name=datasets.Split.TEST,
130
+ gen_kwargs={
131
+ "filepath": os.path.join(
132
+ data_dir, "data","test", f"{task_name}_test.csv"
133
+ ),
134
+ },
135
+ ),
136
+ datasets.SplitGenerator(
137
+ name=datasets.Split("val"),
138
+ gen_kwargs={
139
+ "filepath": os.path.join(
140
+ data_dir,'data', "val", f"{task_name}_val.csv"
141
+ ),
142
+ },
143
+ ),
144
+ datasets.SplitGenerator(
145
+ name=datasets.Split("dev"),
146
+ gen_kwargs={
147
+ "filepath": os.path.join(
148
+ data_dir, "data", "dev", f"{task_name}_dev.csv"
149
+ ),
150
+ },
151
+ ),
152
+ ]
153
+
154
+ def _generate_examples(self, filepath):
155
+ df = pd.read_csv(filepath,encoding="utf-8")
156
+ for i, instance in enumerate(df.to_dict(orient="records")):
157
+ if "answer" not in instance.keys():
158
+ instance["answer"]=""
159
+ if "explanation" not in instance.keys():
160
+ instance["explanation"]=""
161
+ yield i, instance