azz1990 commited on
Commit
5977517
1 Parent(s): b4fce63

Create ceval-exam.py

Browse files
Files changed (1) hide show
  1. ceval-exam.py +166 -0
ceval-exam.py ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ @article{huang2023ceval,
22
+ title={C-Eval: A Multi-Level Multi-Discipline Chinese Evaluation Suite for Foundation Models},
23
+ author={Huang, Yuzhen and Bai, Yuzhuo and Zhu, Zhihao and Zhang, Junlei and Zhang, Jinghan and Su, Tangjun and Liu, Junteng and Lv, Chuancheng and Zhang, Yikai and Lei, Jiayi and Fu, Yao and Sun, Maosong and He, Junxian},
24
+ journal={arXiv preprint arXiv:2305.08322},
25
+ year={2023}
26
+ }
27
+ """
28
+
29
+ _DESCRIPTION = """\
30
+ C-Eval is a comprehensive Chinese evaluation suite for foundation models. It consists of 13948 multi-choice questions spanning 52 diverse disciplines and four difficulty levels.
31
+ """
32
+
33
+ _HOMEPAGE = "https://cevalbenchmark.com"
34
+
35
+ _LICENSE = "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License"
36
+
37
+ _URL = r"https://huggingface.co/datasets/ceval/ceval-exam/resolve/main/ceval-exam.zip"
38
+
39
+ task_list = [
40
+ "computer_network",
41
+ "operating_system",
42
+ "computer_architecture",
43
+ "college_programming",
44
+ "college_physics",
45
+ "college_chemistry",
46
+ "advanced_mathematics",
47
+ "probability_and_statistics",
48
+ "discrete_mathematics",
49
+ "electrical_engineer",
50
+ "metrology_engineer",
51
+ "high_school_mathematics",
52
+ "high_school_physics",
53
+ "high_school_chemistry",
54
+ "high_school_biology",
55
+ "middle_school_mathematics",
56
+ "middle_school_biology",
57
+ "middle_school_physics",
58
+ "middle_school_chemistry",
59
+ "veterinary_medicine",
60
+ "college_economics",
61
+ "business_administration",
62
+ "marxism",
63
+ "mao_zedong_thought",
64
+ "education_science",
65
+ "teacher_qualification",
66
+ "high_school_politics",
67
+ "high_school_geography",
68
+ "middle_school_politics",
69
+ "middle_school_geography",
70
+ "modern_chinese_history",
71
+ "ideological_and_moral_cultivation",
72
+ "logic",
73
+ "law",
74
+ "chinese_language_and_literature",
75
+ "art_studies",
76
+ "professional_tour_guide",
77
+ "legal_professional",
78
+ "high_school_chinese",
79
+ "high_school_history",
80
+ "middle_school_history",
81
+ "civil_servant",
82
+ "sports_science",
83
+ "plant_protection",
84
+ "basic_medicine",
85
+ "clinical_medicine",
86
+ "urban_and_rural_planner",
87
+ "accountant",
88
+ "fire_engineer",
89
+ "environmental_impact_assessment_engineer",
90
+ "tax_accountant",
91
+ "physician",
92
+ ]
93
+
94
+
95
+ class CevalExamConfig(datasets.BuilderConfig):
96
+ def __init__(self, **kwargs):
97
+ super().__init__(version=datasets.Version("1.0.0"), **kwargs)
98
+
99
+
100
+ class CevalExam(datasets.GeneratorBasedBuilder):
101
+ BUILDER_CONFIGS = [
102
+ CevalExamConfig(
103
+ name=task_name,
104
+ )
105
+ for task_name in task_list
106
+ ]
107
+
108
+ def _info(self):
109
+ features = datasets.Features(
110
+ {
111
+ "id":datasets.Value("int32"),
112
+ "question": datasets.Value("string"),
113
+ "A": datasets.Value("string"),
114
+ "B": datasets.Value("string"),
115
+ "C": datasets.Value("string"),
116
+ "D": datasets.Value("string"),
117
+ "answer": datasets.Value("string"),
118
+ "explanation":datasets.Value("string"),
119
+ }
120
+ )
121
+ return datasets.DatasetInfo(
122
+ description=_DESCRIPTION,
123
+ features=features,
124
+ homepage=_HOMEPAGE,
125
+ license=_LICENSE,
126
+ citation=_CITATION,
127
+ )
128
+
129
+ def _split_generators(self, dl_manager):
130
+ data_dir = dl_manager.download_and_extract(_URL)
131
+ task_name = self.config.name
132
+ return [
133
+ datasets.SplitGenerator(
134
+ name=datasets.Split.TEST,
135
+ gen_kwargs={
136
+ "filepath": os.path.join(
137
+ data_dir, "test", f"{task_name}_test.csv"
138
+ ),
139
+ },
140
+ ),
141
+ datasets.SplitGenerator(
142
+ name=datasets.Split("val"),
143
+ gen_kwargs={
144
+ "filepath": os.path.join(
145
+ data_dir, "val", f"{task_name}_val.csv"
146
+ ),
147
+ },
148
+ ),
149
+ datasets.SplitGenerator(
150
+ name=datasets.Split("dev"),
151
+ gen_kwargs={
152
+ "filepath": os.path.join(
153
+ data_dir, "dev", f"{task_name}_dev.csv"
154
+ ),
155
+ },
156
+ ),
157
+ ]
158
+
159
+ def _generate_examples(self, filepath):
160
+ df = pd.read_csv(filepath,encoding="utf-8")
161
+ for i, instance in enumerate(df.to_dict(orient="records")):
162
+ if "answer" not in instance.keys():
163
+ instance["answer"]=""
164
+ if "explanation" not in instance.keys():
165
+ instance["explanation"]=""
166
+ yield i, instance