Datasets:

ArXiv:
License:
File size: 7,623 Bytes
25bfee2
 
 
 
 
 
 
 
d32cc51
 
 
 
 
 
 
 
 
 
 
25bfee2
 
 
 
 
 
 
 
d32cc51
 
03b1a85
25bfee2
 
 
d32cc51
002de1f
 
d32cc51
 
 
 
002de1f
d32cc51
002de1f
54013c1
25bfee2
 
9d0d843
25bfee2
 
b1809b6
25bfee2
 
 
 
 
0cf4a82
25bfee2
 
 
d32cc51
 
25bfee2
9d0d843
b1809b6
25bfee2
9d0d843
 
b1809b6
 
 
 
9d0d843
25bfee2
 
d6b4ca4
 
 
25bfee2
 
002de1f
25bfee2
 
54013c1
25bfee2
 
 
 
54013c1
 
25bfee2
 
 
 
 
 
d32cc51
 
25bfee2
 
 
 
 
 
d32cc51
25bfee2
 
 
 
 
 
 
 
 
 
 
 
 
002de1f
25bfee2
9d0d843
b1809b6
 
03b1a85
9d0d843
d32cc51
b1809b6
 
 
 
d32cc51
 
 
0cf4a82
9d0d843
d32cc51
c9583e3
d32cc51
 
 
 
 
 
 
 
 
 
 
 
 
9d0d843
25bfee2
 
 
 
 
 
 
 
 
 
 
d32cc51
25bfee2
d32cc51
 
25bfee2
 
d32cc51
 
 
 
 
 
 
 
 
 
 
 
 
 
25bfee2
 
 
 
d32cc51
 
 
 
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import os

import pyarrow as pa
import pyarrow.parquet as pq
import datasets

_REPO_NAME = 'Fsoft-AIC/the-vault'

_LANG_TO_TEXT = {
    "python": "python",
    "c": "c",
    "c#": "c_sharp",
    "c++": "cpp",
    "go": "go",
    "Java": "java",
    "javascript": "javascript",
    "php": "php",
    "ruby": "ruby",
    "rust": "rust",
}


_DESCRIPTION = """The Vault"""

_HOMEPAGE = "https://huggingface.co/Fsoft-AIC"


_TEXT_TO_LANG = {}
for lang in _LANG_TO_TEXT:
    _TEXT_TO_LANG[_LANG_TO_TEXT[lang]] = lang


        
_LANG_CONFIGS = ["all"] + list(_TEXT_TO_LANG.keys())

num_shard_split = {
    'train/small/python': 1,
    'train/medium/python': 1,
    'train/small/c': 1,
    'train/medium/c': 1
}  
_SPLIT_CONFIGS = ["all", "train/small", "train/medium"]

class TheVaultFunctionConfig(datasets.BuilderConfig):
    """BuilderConfig for The Vault dataset."""

    def __init__(self, *args, languages=["all"], split_set= ["all"], **kwargs):
        """BuilderConfig for the GitHub Code dataset.
        Args:
            split_set (:obj:`List[str]`): List of split set to load.
            languages (:obj:`List[str]`): List of languages to load.
            **kwargs: keyword arguments forwarded to super.
        """
        super().__init__(
            *args,
            name= "+".join([split.replace("/", "_") for split in split_set]) + "-" + "+".join(languages),
            **kwargs,
        )
        
        languages = set([lang.lower() for lang in languages])
        split_set = set([split.lower() for split in split_set]) 
        
        assert all([language in _LANG_CONFIGS for language in languages]), f"languages {languages} contains language not in {_LANG_CONFIGS}."
        assert all([split in _SPLIT_CONFIGS for split in split_set]), f"split_set {split_set} contains element not in {_SPLIT_CONFIGS}."
        
        if "all" in split_set:
            assert len(split_set)==1, f"Passed 'all' together with other split sets. {split_set}"
        elif "train" in split_set:
            for split in split_set:
                if "train" in split and split != "train":
                    raise f"Split set 'train' already contains '{split}'. Please only include one."

        if "all" in languages:
            assert len(languages)==1, f"Passed 'all' together with other languages. {languages}"
        #     self.filter_languages = False
        # else:
        #     self.filter_languages = True
        
        self.languages = set(languages)
        self.split_set= split_set


class TheVaultFunction(datasets.GeneratorBasedBuilder):
    """The Vault dataset."""

    VERSION = datasets.Version("1.0.0")
    
    BUILDER_CONFIG_CLASS = TheVaultFunctionConfig
    BUILDER_CONFIGS = [TheVaultFunctionConfig(languages=[lang], split_set=[spl]) for lang in _LANG_CONFIGS for spl in _SPLIT_CONFIGS]
    DEFAULT_CONFIG_NAME = "all-all"

    
    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features({
                                        # "original_string": datasets.Value("string"),
                                        "original_docstring": datasets.Value("string"),
                                        "code": datasets.Value("string"),
                                        "docstring": datasets.Value("string"),
                                        "code_tokens": datasets.Value("string"),
                                        "docstring_tokens": datasets.Value("string"),
                                        "short_docstring": datasets.Value("string"),
                                        "short_docstring_tokens": datasets.Value("string"),
                                        "comment": datasets.Value("string"),
                                        "return_type": datasets.Value("string"),
                                        "identifier": datasets.Value("string"),
                                        "repo": datasets.Value("string"),
                                        "path": datasets.Value("string"), 
                                        "language": datasets.Value("string"),
                                        }),
            supervised_keys=None,
            homepage=_HOMEPAGE,
            
        )

    def _split_generators(self, dl_manager):
        print(self.config.split_set)

        generators = []
        split_set = list(self.config.split_set)
        languages = list(self.config.languages)

        if "all" in split_set:
            split_set = _SPLIT_CONFIGS[1:]

        if "train" in split_set:
            split_set.remove('train')
            split_set.extend(["train/small", "train/medium"])
        
        if "all" in languages:
            languages = _LANG_CONFIGS[1:]

        for split in split_set:
            for language in languages:
                num_shards = num_shard_split[f"{split}/{language}"]
                data_files = [
                    f"data/{split}/{language}-{_index:05d}-of-{num_shards:05d}.parquet"
                    for _index in range(num_shards)
                ]
                files = dl_manager.download(data_files)
                generators.append(
                    datasets.SplitGenerator(
                        name=split.replace("/", "_"),
                        gen_kwargs={
                            "files": files,
                        },
                    ),
                )
        return generators

    def _generate_examples(self, files):
        key = 0
        for file_idx, file in enumerate(files):
            with open(file, "rb") as f:
                parquet_file = pq.ParquetFile(f)
                for batch_idx, record_batch in enumerate(parquet_file.iter_batches(batch_size=10_000)):
                    pa_table = pa.Table.from_batches([record_batch])
                    for row_index in range(pa_table.num_rows):
                        row = pa_table.slice(row_index, 1).to_pydict()
                        
                        # lang = row['language'][0]
                        
                        # if self.config.filter_languages and not lang in self.config.languages:
                        #     continue
                        
                        yield key, {
                                        "repo": row['repo'][0],
                                        "path": row['path'][0], 
                                        "language": row['language'][0],
                                        "identifier": row['identifier'][0],
                                        "return_type": row['return_type'][0],
                                        # "original_string": row['original_string'][0],
                                        "original_docstring": row['original_docstring'][0],
                                        "docstring": row['docstring'][0],
                                        "docstring_tokens": row['docstring_tokens'][0],
                                        "code": row['code'][0],
                                        "code_tokens": row['code_tokens'][0],
                                        "short_docstring": row['short_docstring'][0],
                                        "short_docstring_tokens": row['short_docstring_tokens'][0],
                                        "comment": row['comment'][0]
                                    } 
                        key += 1

                        
# def lang_from_name(name):
#     for extension in _EXTENSION_TO_LANG:
#         if name.endswith(extension):
#             return _EXTENSION_TO_LANG[extension]