ldwang commited on
Commit
ff6beb7
1 Parent(s): 76239f9

init ceval in lighteval

Browse files

Signed-off-by: ldwang <ftgreat@gmail.com>

Files changed (2) hide show
  1. ceval-exam.zip +3 -0
  2. lighteval-ceval-exam.py +165 -0
ceval-exam.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:68786deeea68ff089c56563ee48fab8160da857b77b913437bb504d681fd8e20
3
+ size 1548171
lighteval-ceval-exam.py ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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"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
+ "question": datasets.Value("string"),
112
+ "subject": datasets.Value("string"),
113
+ "choices": datasets.features.Sequence(datasets.Value("string")),
114
+ "answer": datasets.features.ClassLabel(num_classes=4, names=["A", "B", "C", "D"]),
115
+ }
116
+ )
117
+ return datasets.DatasetInfo(
118
+ description=_DESCRIPTION,
119
+ features=features,
120
+ homepage=_HOMEPAGE,
121
+ license=_LICENSE,
122
+ citation=_CITATION,
123
+ )
124
+
125
+ def _split_generators(self, dl_manager):
126
+ data_dir = dl_manager.download_and_extract(_URL)
127
+ task_name = self.config.name
128
+ return [
129
+ datasets.SplitGenerator(
130
+ name=datasets.Split.TEST,
131
+ gen_kwargs={
132
+ "filepath": os.path.join(
133
+ data_dir, "test", f"{task_name}_test.csv"
134
+ ),
135
+ },
136
+ ),
137
+ datasets.SplitGenerator(
138
+ name=datasets.Split("val"),
139
+ gen_kwargs={
140
+ "filepath": os.path.join(
141
+ data_dir, "val", f"{task_name}_val.csv"
142
+ ),
143
+ },
144
+ ),
145
+ datasets.SplitGenerator(
146
+ name=datasets.Split("dev"),
147
+ gen_kwargs={
148
+ "filepath": os.path.join(
149
+ data_dir, "dev", f"{task_name}_dev.csv"
150
+ ),
151
+ },
152
+ ),
153
+ ]
154
+
155
+ def _generate_examples(self, filepath):
156
+ df = pd.read_csv(filepath,encoding="utf-8")
157
+ import os
158
+ subset = os.path.splitext(filepath)[0].split("/")[-1].rsplit("_",1)[0]
159
+ for i, instance in enumerate(df.to_dict(orient="records")):
160
+ # TODO
161
+ if "answer" not in instance.keys():
162
+ instance["answer"]="A"
163
+ if "explanation" not in instance.keys():
164
+ instance["explanation"]=""
165
+ yield i, {"question": instance['question'], "choices": [instance[x] for x in ["A","B","C","D"]], "answer": instance['answer'], "subject": subset}