File size: 2,362 Bytes
d68d2f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import glob
import json

import datasets

_VERSION = datasets.Version("1.0.0", "")

_URL = ""

_CITATION = """\
There is no citation information
"""

_DESCRIPTION = """\
simple code knowledge eval dataset loading script
"""

TRAIN_FILE = "train.json"
VALIDATION_FILE = "validation.json"
TEST_FILE = "test.json"


def generator(fpath):
    with open(fpath, "r") as f:
        in_json = json.load(f)
        for item in in_json:
            yield {
                "content": item["content"],
                "label": str(item["score"]),
                "lang": item["lang"],
                "repo_name": item["repo_name"],
                "repo_path": item["repo_path"],
                "repo_licenses": item["repo_licenses"],
            }
            
class CodeKnowledgeEvalDataset(datasets.GeneratorBasedBuilder):
    """Code Knowledge Evaluation Dataset"""

    BUILDER_CONFIGS = [
        datasets.BuilderConfig(
            name="default",
            version=_VERSION,
            description="Code Knowledge Evaluation Dataset",
        )
    ]

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features(
                {
                    "content": datasets.Value("string"),
                    "label": datasets.ClassLabel(num_classes=6, names=['0', '1', '2', '3', '4', '5']),
                    "lang": datasets.Value("string"),
                    "repo_name": datasets.Value("string"),
                    "repo_path": datasets.Value("string"),
                    "repo_licenses": datasets.Sequence(feature=datasets.Value("string")),
                }
            ),
            supervised_keys=None,  # Probably needs to be fixed.
            homepage=_URL,
            citation=_CITATION,
            
        )

    def _split_generators(self, dl_manager: datasets.DownloadManager):

        path_kv = {
            datasets.Split.TRAIN: TRAIN_FILE,
            datasets.Split.VALIDATION: VALIDATION_FILE,
            datasets.Split.TEST: TEST_FILE,
        }
        

        return [
                datasets.SplitGenerator(name=k, gen_kwargs={'fpath': v}) for k, v in path_kv.items()
        ]

    def _generate_examples(self, fpath):
        """Yields examples."""
        for idx, item in enumerate(generator(fpath)):
            yield idx, item