File size: 4,313 Bytes
fcf6b5e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
301b108
fcf6b5e
 
 
 
 
301b108
fcf6b5e
 
301b108
 
fcf6b5e
 
301b108
 
fcf6b5e
 
 
 
 
 
 
301b108
fcf6b5e
 
 
 
 
c5d0fec
fcf6b5e
 
 
 
 
 
 
 
301b108
fcf6b5e
 
 
 
 
 
 
 
 
 
 
 
 
 
301b108
fcf6b5e
 
 
 
 
 
 
 
 
 
 
 
 
301b108
 
 
fcf6b5e
 
 
 
 
 
 
 
301b108
fcf6b5e
 
 
 
 
301b108
 
 
 
 
 
 
 
 
fcf6b5e
 
 
 
 
301b108
fcf6b5e
 
301b108
fcf6b5e
 
 
 
 
 
 
 
301b108
 
f7a10fb
c5d0fec
 
 
 
 
 
 
 
 
f7a10fb
 
 
 
 
301b108
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import json
import datasets

_REPO_NAME = "TeDriCS/tedrics-data"

_DESCRIPTION = ""

_HOMEPAGE = ""

_CITATION = """\
@misc{,
      title={ },
      author={},
      year={2022}
}
"""

_LICENSE = 'CC BY-SA'

_SUBSETS = ["tasks", "testcases", "codefunctions"]

_DATA_URLS = {
    "tasks": {
        "train": "tedrics_data_tasks.json"
    },
    "testcases": {
        "train": "tedrics_data_testcases.json",
        "validation": "tedrics_data_testcases_val.json"
    },
    "codefunctions": {
        "train": "tedrics_data_codefunctions.json",
        "validation": "tedrics_data_codefunctions_val.json"
    }
}

class TeDriCSData(datasets.GeneratorBasedBuilder):
    BUILDER_CONFIGS = [
        datasets.BuilderConfig(
            name=f"{subset}",
            version=datasets.Version("1.1.0"),
            description=_DESCRIPTION,
        )
        for subset in _SUBSETS
    ]

    DEFAULT_CONFIG_NAME = "testcases"

    def _info(self):
        if self.config.name == "tasks":
            features = datasets.Features(
                {
                    "task_id": datasets.Value("int32"),
                    "mbpp_task_id": datasets.Value("int32"),
                    "source": datasets.Value("string"),
                    "licence": datasets.Value("string"),
                    "task": datasets.Value("string"),
                }
            )

        if self.config.name == "testcases":
            features = datasets.Features(
                {
                    "task_id": datasets.Value("int32"),
                    "mbpp_task_id": datasets.Value("int32"),
                    "task": datasets.Value("string"),
                    "test_cases": datasets.Sequence(
                        {
                            "test_case_id": datasets.Value("int32"),
                            "cot": datasets.Value("string"),
                            "input": datasets.Value("string"),
                            "output": datasets.Value("string")
                        }
                    )
                }
            )

        if self.config.name == "codefunctions":
            features = datasets.Features(
                {
                    "task_id": datasets.Value("int32"),
                    "mbpp_task_id": datasets.Value("int32"),
                    "description": datasets.Value("string"),
                    "cot": datasets.Value("string"),
                    "imports": datasets.Value("string"),
                    "function_head": datasets.Value("string"),
                    "function_body": 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):
        urls = _DATA_URLS[self.config.name]
        data = dl_manager.download_and_extract(urls)

        splits = []

        if self.config.name == "tasks":
            splits = [datasets.Split.TRAIN]

        if self.config.name == "testcases" or self.config.name == "codefunctions":
            splits = [datasets.Split.TRAIN, datasets.Split.VALIDATION]

        return [
            datasets.SplitGenerator(
                name=split,
                gen_kwargs={
                    "filepath": data[split],
                },
            )
            for split in splits
        ]

    def _generate_examples(self, filepath):
        with open(filepath, encoding="utf-8") as file:
            data = json.load(file)
            id_ = 0
            for sample in data:
                yield id_, sample
                id_ += 1

####Zum Testen der Implementierung
# from datasets import load_dataset
# def main():
#     dataset = load_dataset('C:\\Users\\klaud\\TeDriCSProj\\tedrics-data\\tedrics-data.py')
#     print(dataset["train"])
#     print(dataset["train"][0])
#     print(dataset["validation"])
#     print(dataset["validation"][0])

# if __name__ == "__main__":
#    main()

#### Zum Generieren der dataset_infos.json (im Terminal)
# (hf-gptneox-cpu) PS C:\Users\klaud\TeDriCSProj\tedrics-data> datasets-cli test C:\Users\klaud\TeDriCSProj\tedrics-data\tedrics-data.py --save_infos --all_configs