Datasets:
Modalities:
Text
Size:
10K - 100K
Create testcm.py
Browse files
testcm.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
"""The CodeMMLU benchmark."""
|
| 15 |
+
|
| 16 |
+
import os
|
| 17 |
+
import json
|
| 18 |
+
from glob import glob
|
| 19 |
+
|
| 20 |
+
import datasets
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
_CITATION = """\
|
| 24 |
+
@article{nguyen2024codemmlu,
|
| 25 |
+
title={CodeMMLU: A Multi-Task Benchmark for Assessing Code Understanding Capabilities},
|
| 26 |
+
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.},
|
| 27 |
+
journal={arXiv preprint},
|
| 28 |
+
year={2024}
|
| 29 |
+
}
|
| 30 |
+
"""
|
| 31 |
+
|
| 32 |
+
_DESCRIPTION = """\
|
| 33 |
+
CodeMMLU is a comprehensive benchmark designed to evaluate the capabilities of large language models (LLMs) in coding and software knowledge
|
| 34 |
+
"""
|
| 35 |
+
|
| 36 |
+
_HOMEPAGE = "https://fsoft-ai4code.github.io/codemmlu/"
|
| 37 |
+
|
| 38 |
+
_URL = "./data/test"
|
| 39 |
+
|
| 40 |
+
_SUBJECTS = [
|
| 41 |
+
"programming_syntax", "api_frameworks",
|
| 42 |
+
"software_principles", "dbms_sql", "others",
|
| 43 |
+
"code_completion", "fill_in_the_middle", "code_repair", "defect_detection"
|
| 44 |
+
]
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
class CodeMMLU(datasets.GeneratorBasedBuilder):
|
| 48 |
+
"""CodeMMLU: A Multi-Task Benchmark for Assessing Code Understanding Capabilities"""
|
| 49 |
+
# Version history:
|
| 50 |
+
# 0.0.1: Initial release.
|
| 51 |
+
VERSION = datasets.Version("0.0.1")
|
| 52 |
+
|
| 53 |
+
BUILDER_CONFIGS = [
|
| 54 |
+
datasets.BuilderConfig(
|
| 55 |
+
name=sub, version=datasets.Version("0.0.1"),
|
| 56 |
+
description="CodeMMLU test subject {}".format(sub)
|
| 57 |
+
) for sub in _SUBJECTS
|
| 58 |
+
]
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def _info(self):
|
| 62 |
+
features = datasets.Features(
|
| 63 |
+
{
|
| 64 |
+
"task_id": datasets.Value("string"),
|
| 65 |
+
"question": datasets.Value("string"),
|
| 66 |
+
"choices": datasets.features.Sequence(datasets.Value("string")),
|
| 67 |
+
}
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
if self.config.name == "fill_in_the_middle":
|
| 71 |
+
features["problem_description"] = datasets.Value("string")
|
| 72 |
+
|
| 73 |
+
return datasets.DatasetInfo(
|
| 74 |
+
description=_DESCRIPTION,
|
| 75 |
+
features=features,
|
| 76 |
+
homepage=_HOMEPAGE,
|
| 77 |
+
citation=_CITATION,
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
def _split_generators(self, dl_manager):
|
| 81 |
+
"""Returns SplitGenerators."""
|
| 82 |
+
path = os.path.join(_URL, self.config.name + ".jsonl")
|
| 83 |
+
dl_dir = dl_manager.download(path)
|
| 84 |
+
return [
|
| 85 |
+
datasets.SplitGenerator(
|
| 86 |
+
name=datasets.Split.TEST,
|
| 87 |
+
gen_kwargs={"data_path": dl_dir},
|
| 88 |
+
),
|
| 89 |
+
]
|
| 90 |
+
|
| 91 |
+
def _generate_examples(self, data_path):
|
| 92 |
+
"""This function returns the examples in the raw (text) form."""
|
| 93 |
+
if data_path.endswith(".jsonl"):
|
| 94 |
+
lines = open(data_path, "r", encoding="utf-8").readlines()
|
| 95 |
+
reader = [json.loads(line) for line in lines]
|
| 96 |
+
for idx, data in enumerate(reader):
|
| 97 |
+
return_dict = {
|
| 98 |
+
"task_id": data['task_id'],
|
| 99 |
+
"question": data['question'],
|
| 100 |
+
"choices": data['choices'],
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
if "fill_in_the_middle" in data_path:
|
| 104 |
+
return_dict['problem_description'] = data['problem_description']
|
| 105 |
+
|
| 106 |
+
yield idx, return_dict
|