File size: 3,474 Bytes
fcf6b5e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
import datasets

_REPO_NAME = "TeDriCS/tedrics-data"

_DESCRIPTION = ""

_HOMEPAGE = ""

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

_LICENSES = ['CC BY-SA', 'CC Attribution 4.0']

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

_DATA_URLS = {
    "tasks": {
        "train": ["tedrics_data_tasks.json"]
    },
    "testcases": {
        "train": ["tedrics_data_testcases.json"]
    },
    "codefunctions": {
        "train": ["tedrics_data_codefunctions.json"]
    }
}

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

    DEFAULT_CONFIG_NAME = "tasks"

    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.Sequence(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.Sequence(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.Sequence(datasets.Value("string")),
                    "function_head": datasets.Sequence(datasets.Value("string")),
                    "function_body": datasets.Sequence(datasets.Value("string"))
                }
            )

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

    def _split_generators(self, dl_manager):
        urls = _DATA_URLS[self.config.name]
        data = dl_manager.download(urls)

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

    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