File size: 3,833 Bytes
2ae3d1c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import json
import datasets

_DESCRIPTION = """\
FudanSELab ClassEval
"""
_URL = "ClassEval_data.json"

_CITATION = """\
@misc{du2023classeval,
      title={ClassEval: A Manually-Crafted Benchmark for Evaluating LLMs on Class-level Code Generation}, 
      author={Xueying Du and Mingwei Liu and Kaixin Wang and Hanlin Wang and Junwei Liu and Yixuan Chen and Jiayi Feng and Chaofeng Sha and Xin Peng and Yiling Lou},
      year={2023},
      eprint={2308.01861},
      archivePrefix={arXiv},
      primaryClass={cs.CL}
}"""

_HOMEPAGE = "https://github.com/FudanSELab/ClassEval"

_LICENSE = "MIT"

class ClassEval(datasets.GeneratorBasedBuilder):
    VERSION = datasets.Version("1.0.0")
    BUILDER_CONFIGS = [
        datasets.BuilderConfig(
            name="class_eval",
            version=datasets.Version("1.0.0"),
            description=_DESCRIPTION,
        )
    ]

    def _info(self):
        method_feature = datasets.Features(
            {
                "method_name": datasets.Value("string"),
                "method_description": datasets.Value("string"),
                "test_class": datasets.Value("string"),
                "test_code": datasets.Value("string"),
                "solution_code": datasets.Value("string"),
                "dependencies": {
                    "Standalone": datasets.Value("bool"),
                    "lib_dependencies": datasets.Sequence(datasets.Value("string")),
                    "field_dependencies": datasets.Sequence(datasets.Value("string")),
                    "method_dependencies": datasets.Sequence(datasets.Value("string")),
                }
            }
        )

        features = datasets.Features(
            {
                "task_id": datasets.Value("string"),
                "skeleton": datasets.Value("string"),
                "test": datasets.Value("string"),
                "solution_code": datasets.Value("string"),
                "import_statement": datasets.Sequence(datasets.Value("string")),
                "class_description": datasets.Value("string"),
                "methods_info": [method_feature],
                "class_name": datasets.Value("string"),
                "test_classes": datasets.Sequence(datasets.Value("string")),
                "class_constructor": datasets.Value("string"),
                "fields": datasets.Sequence(datasets.Value("string")),
            }
        )

        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=features,
            supervised_keys=None,
            homepage=_HOMEPAGE,
            license=_LICENSE,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        """Returns SplitGenerators."""
        data_dir = dl_manager.download(_URL)
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                gen_kwargs={
                    "filepath": data_dir,
                },
            )
        ]

    def _generate_examples(self, filepath):
        key = 0
        with open(filepath, encoding = 'utf-8') as f:
            cont = json.load(f)
            for row in cont:
                yield key, {
                    "task_id": row["task_id"],
                    "skeleton": row["skeleton"],
                    "test": row["test"],
                    "solution_code": row["solution_code"],
                    "import_statement": row["import_statement"],
                    "class_description": row["class_description"],
                    "methods_info": row["methods_info"],
                    "class_name": row["class_name"],
                    "test_classes": row["test_classes"],
                    "class_constructor": row["class_constructor"],
                    "fields": row["fields"],
                }
                key += 1