Add loader script
Browse files- pytorrent-standalone.py +131 -0
pytorrent-standalone.py
ADDED
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
3 |
+
#
|
4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
+
# you may not use this file except in compliance with the License.
|
6 |
+
# You may obtain a copy of the License at
|
7 |
+
#
|
8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
+
#
|
10 |
+
# Unless required by applicable law or agreed to in writing, software
|
11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
+
# See the License for the specific language governing permissions and
|
14 |
+
# limitations under the License.
|
15 |
+
"""Wrapper for datasets in CodeXGLUE benchmark."""
|
16 |
+
import csv
|
17 |
+
import json
|
18 |
+
import os
|
19 |
+
import datasets
|
20 |
+
|
21 |
+
_CITATION = """\
|
22 |
+
@article{Bahrami2021,
|
23 |
+
author = {Bahrami, Mehdi and Shrikanth, N. C. and Ruangwan, Shade and Liu, Lei and Mizobuchi, Yuji and Fukuyori, Masahiro and Chen, Wei-Peng and Munakata, Kazuki and Menzies, Tim},
|
24 |
+
year = {2021},
|
25 |
+
journal = {arXiv},
|
26 |
+
title = {PyTorrent: A Python Library Corpus for Large-scale Language Models}
|
27 |
+
}
|
28 |
+
"""
|
29 |
+
|
30 |
+
_DESCRIPTION = """\
|
31 |
+
pytorrent-standalone is a subset of the PyTorrent dataset, where only functions that does not depend on external libraries
|
32 |
+
are kept.
|
33 |
+
"""
|
34 |
+
|
35 |
+
_HOMEPAGE = ""
|
36 |
+
|
37 |
+
_LICENSE = ""
|
38 |
+
|
39 |
+
# The HuggingFace dataset library don't host the datasets but only point to the original files
|
40 |
+
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
|
41 |
+
_URLs = {
|
42 |
+
'all': "data.jsonl",
|
43 |
+
}
|
44 |
+
|
45 |
+
|
46 |
+
# TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
|
47 |
+
class PyTorrentStandalone(datasets.GeneratorBasedBuilder):
|
48 |
+
"""TODO: Short description of my dataset."""
|
49 |
+
VERSION = datasets.Version("1.0.0")
|
50 |
+
# This is an example of a dataset with multiple configurations.
|
51 |
+
# If you don't want/need to define several sub-sets in your dataset,
|
52 |
+
# just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
|
53 |
+
# If you need to make complex sub-parts in the datasets with configurable options
|
54 |
+
# You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
|
55 |
+
# BUILDER_CONFIG_CLASS = MyBuilderConfig
|
56 |
+
# You will be able to load one or the other configurations in the following list with
|
57 |
+
# data = datasets.load_dataset('my_dataset', 'first_domain')
|
58 |
+
# data = datasets.load_dataset('my_dataset', 'second_domain')
|
59 |
+
BUILDER_CONFIGS = [
|
60 |
+
datasets.BuilderConfig(name="all", version=VERSION,
|
61 |
+
description="The corpus."),
|
62 |
+
]
|
63 |
+
|
64 |
+
# DEFAULT_CONFIG_NAME = "all" # It's not mandatory to have a default configuration. Just use one if it make sense.
|
65 |
+
|
66 |
+
def _info(self):
|
67 |
+
if self.config.name == "all": # This is the name of the configuration selected in BUILDER_CONFIGS above
|
68 |
+
features = datasets.Features(
|
69 |
+
{
|
70 |
+
"repo": datasets.Value("string"),
|
71 |
+
"path": datasets.Value("string"),
|
72 |
+
"code": datasets.Value("string"),
|
73 |
+
}
|
74 |
+
)
|
75 |
+
else:
|
76 |
+
assert False, f'Invalid config name: {self.config.name}'
|
77 |
+
return datasets.DatasetInfo(
|
78 |
+
# This is the description that will appear on the datasets page.
|
79 |
+
description=_DESCRIPTION,
|
80 |
+
# This defines the different columns of the dataset and their types
|
81 |
+
features=features, # Here we define them above because they are different between the two configurations
|
82 |
+
# If there's a common (input, target) tuple from the features,
|
83 |
+
# specify them here. They'll be used if as_supervised=True in
|
84 |
+
# builder.as_dataset.
|
85 |
+
supervised_keys=None,
|
86 |
+
# Homepage of the dataset for documentation
|
87 |
+
homepage=_HOMEPAGE,
|
88 |
+
# License for the dataset if available
|
89 |
+
license=_LICENSE,
|
90 |
+
# Citation for the dataset
|
91 |
+
citation=_CITATION,
|
92 |
+
)
|
93 |
+
|
94 |
+
def _split_generators(self, dl_manager):
|
95 |
+
"""Returns SplitGenerators."""
|
96 |
+
# If several configurations are possible (listed in BUILDER_CONFIGS),
|
97 |
+
# the configuration selected by the user is in self.config.name
|
98 |
+
# dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLs
|
99 |
+
# It can accept any type or nested list/dict and will give back the same structure with the url replaced with
|
100 |
+
# path to local files. By default the archives will be extracted and a path to a cached folder where they are
|
101 |
+
# extracted is returned instead of the archive
|
102 |
+
my_urls = _URLs[self.config.name]
|
103 |
+
data_path = dl_manager.download_and_extract(my_urls)
|
104 |
+
if self.config.name == 'all':
|
105 |
+
return [
|
106 |
+
datasets.SplitGenerator(
|
107 |
+
name=datasets.Split.TRAIN,
|
108 |
+
# These kwargs will be passed to _generate_examples
|
109 |
+
gen_kwargs={
|
110 |
+
'data_path': data_path
|
111 |
+
}
|
112 |
+
)
|
113 |
+
]
|
114 |
+
|
115 |
+
def _generate_examples(
|
116 |
+
self, data_path
|
117 |
+
):
|
118 |
+
""" Yields examples as (key, example) tuples. """
|
119 |
+
# This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
|
120 |
+
# The `key` is here for legacy reason (tfds) and is not important in itself.
|
121 |
+
with open(data_path) as jsonl_file:
|
122 |
+
idx = 0
|
123 |
+
for jsonl in jsonl_file:
|
124 |
+
sample = json.loads(jsonl)
|
125 |
+
result = {
|
126 |
+
'repo': sample['repo'],
|
127 |
+
'path': sample['path'],
|
128 |
+
'code': sample['original_string']
|
129 |
+
}
|
130 |
+
yield idx, result
|
131 |
+
idx += 1
|