nmd2k commited on
Commit
9a27193
·
verified ·
1 Parent(s): f7e96e5

builder script

Browse files
Files changed (1) hide show
  1. testcm.py +121 -0
testcm.py ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ """The CodeMMLU benchmark."""
17
+
18
+ import os
19
+ import json
20
+ from glob import glob
21
+
22
+ import datasets
23
+
24
+
25
+ _CITATION = """\
26
+ @article{nguyen2024codemmlu,
27
+ title={CodeMMLU: A Multi-Task Benchmark for Assessing Code Understanding Capabilities},
28
+ author={Nguyen, Dung Manh and Phan, Thang Chau and Le, Nam Hai and Doan, Thong T. and Nguyen, Nam V. and Pham, Quang and Bui, Nghi D. Q.},
29
+ journal={arXiv preprint},
30
+ year={2024}
31
+ }
32
+ """
33
+
34
+ _DESCRIPTION = """\
35
+ CodeMMLU is a comprehensive benchmark designed to evaluate the capabilities of large language models (LLMs) in coding and software knowledge
36
+ """
37
+
38
+ _HOMEPAGE = "https://fsoft-ai4code.github.io/codemmlu/"
39
+
40
+ _URL = "./data/test"
41
+
42
+ _SUBJECTS = [
43
+ "programming_syntax", "api_frameworks",
44
+ "software_principles", "dbms_sql", "others",
45
+ "code_completion", "fill_in_the_middle", "code_repair", "defect_detection"
46
+ ]
47
+
48
+
49
+ class CodeMMLU(datasets.GeneratorBasedBuilder):
50
+ """CodeMMLU: A Multi-Task Benchmark for Assessing Code Understanding Capabilities"""
51
+ # Version history:
52
+ # 0.0.1: Initial release.
53
+ VERSION = datasets.Version("0.0.1")
54
+
55
+ # BUILDER_CONFIGS = [
56
+ # datasets.BuilderConfig(
57
+ # name=sub, version=VERSION,
58
+ # description="CodeMMLU test subject {}".format(sub)
59
+ # ) for sub in _SUBJECTS
60
+ # ]
61
+
62
+ BUILDER_CONFIGS = [
63
+ datasets.BuilderConfig(name="programming_syntax", version=VERSION, description="CodeMMLU test subject: Programming language syntax "),
64
+ datasets.BuilderConfig(name="api_frameworks", version=VERSION, description="CodeMMLU test subject: API & Frameworks "),
65
+ datasets.BuilderConfig(name="software_principles", version=VERSION, description="CodeMMLU test subject: Software Principles "),
66
+ datasets.BuilderConfig(name="dbms_sql", version=VERSION, description="CodeMMLU test subject: DBMS & SQL "),
67
+ datasets.BuilderConfig(name="others", version=VERSION, description="CodeMMLU test subject: Others "),
68
+ datasets.BuilderConfig(name="code_completion", version=VERSION, description="CodeMMLU test subject: Code Completion "),
69
+ datasets.BuilderConfig(name="fill_in_the_middle", version=VERSION, description="CodeMMLU test subject: Fill in the Middle "),
70
+ datasets.BuilderConfig(name="code_repair", version=VERSION, description="CodeMMLU test subject: Code Repair "),
71
+ datasets.BuilderConfig(name="defect_detection", version=VERSION, description="CodeMMLU test subject: Defect Detection "),
72
+ ]
73
+
74
+
75
+ def _info(self):
76
+ features = datasets.Features(
77
+ {
78
+ "task_id": datasets.Value("string"),
79
+ "question": datasets.Value("string"),
80
+ "choices": datasets.features.Sequence(datasets.Value("string")),
81
+ }
82
+ )
83
+
84
+ if self.config.name == "fill_in_the_middle":
85
+ features["problem_description"] = datasets.Value("string")
86
+
87
+ return datasets.DatasetInfo(
88
+ description=_DESCRIPTION,
89
+ features=features,
90
+ homepage=_HOMEPAGE,
91
+ citation=_CITATION,
92
+ )
93
+
94
+ def _split_generators(self, dl_manager):
95
+ """Returns SplitGenerators."""
96
+ path = os.path.join(_URL, self.config.name + ".jsonl")
97
+ dl_dir = dl_manager.download(path)
98
+ return [
99
+ datasets.SplitGenerator(
100
+ name=datasets.Split.TEST,
101
+ gen_kwargs={"data_path": dl_dir},
102
+ ),
103
+ ]
104
+
105
+ def _generate_examples(self, data_path):
106
+ """This function returns the examples in the raw (text) form."""
107
+ if data_path.endswith(".jsonl"):
108
+ lines = open(data_path, "r", encoding="utf-8").readlines()
109
+ reader = [json.loads(line) for line in lines]
110
+ for data in reader:
111
+ id_ = data['task_id']
112
+
113
+ return_dict = {
114
+ "question": data['question'],
115
+ "choices": data['choices'],
116
+ }
117
+
118
+ if "fill_in_the_middle" in data_path:
119
+ return_dict['problem_description'] = data['problem_description']
120
+
121
+ yield id_, return_dict