ncoop57 commited on
Commit
ce98917
1 Parent(s): 9b13142

Add initial dataloading script

Browse files
Files changed (1) hide show
  1. csnc_human_judgement.py +144 -0
csnc_human_judgement.py ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ """TODO: Add a description here."""
16
+
17
+
18
+ import csv
19
+ import glob
20
+ import os
21
+
22
+ import datasets
23
+
24
+ import numpy as np
25
+
26
+ # TODO: Add BibTeX citation
27
+ # Find for instance the citation on arxiv or on the dataset repo/website
28
+ _CITATION = """\
29
+ @InProceedings{huggingface:dataset,
30
+ title = {A great new dataset},
31
+ author={huggingface, Inc.
32
+ },
33
+ year={2020}
34
+ }
35
+ """
36
+
37
+ # TODO: Add description of the dataset here
38
+ # You can copy an official description
39
+ _DESCRIPTION = """\
40
+ This new dataset is designed to solve this great NLP task and is crafted with a lot of care.
41
+ """
42
+
43
+ # TODO: Add a link to an official homepage for the dataset here
44
+ _HOMEPAGE = "http://interactionmining.org/rico"
45
+
46
+ # TODO: Add the licence for the dataset here if you can find it
47
+ _LICENSE = ""
48
+
49
+ # TODO: Add link to the official dataset URLs here
50
+ # The HuggingFace dataset library don't host the datasets but only point to the original files
51
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
52
+ _DATA_URLs = {
53
+ "human_judgement": "https://raw.githubusercontent.com/github/CodeSearchNet/master/resources/annotationStore.csv",
54
+ }
55
+
56
+
57
+ # TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
58
+ class CSNCHumanJudgementDataset(datasets.GeneratorBasedBuilder):
59
+ """TODO: Short description of my dataset."""
60
+
61
+ VERSION = datasets.Version("1.1.0")
62
+
63
+ # This is an example of a dataset with multiple configurations.
64
+ # If you don't want/need to define several sub-sets in your dataset,
65
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
66
+
67
+ # If you need to make complex sub-parts in the datasets with configurable options
68
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
69
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
70
+
71
+ # You will be able to load one or the other configurations in the following list with
72
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
73
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
74
+ BUILDER_CONFIGS = [
75
+ datasets.BuilderConfig(
76
+ name="human_judgement",
77
+ version=VERSION,
78
+ description="",
79
+ ),
80
+ ]
81
+
82
+ DEFAULT_CONFIG_NAME = "human_judgement"
83
+
84
+ def _info(self):
85
+ features = datasets.Features(
86
+ {
87
+ "Language": datasets.Value("string"),
88
+ "Query": datasets.Value("string"),
89
+ "GitHubUrl": datasets.Value("string"),
90
+ "Relevance": datasets.Value("int32"),
91
+ "Notes": datasets.Value("string"),
92
+ }
93
+ )
94
+
95
+ return datasets.DatasetInfo(
96
+ description=_DESCRIPTION,
97
+ features=features,
98
+ supervised_keys=None,
99
+ homepage=_HOMEPAGE,
100
+ license=_LICENSE,
101
+ citation=_CITATION,
102
+ )
103
+
104
+ def _split_generators(self, dl_manager):
105
+ """Returns SplitGenerators."""
106
+ # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
107
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
108
+
109
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLs
110
+ # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
111
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
112
+ my_urls = _DATA_URLs[self.config.name]
113
+ data_dir = dl_manager.download_and_extract(my_urls)
114
+ return [
115
+ datasets.SplitGenerator(
116
+ name=datasets.Split.TEST,
117
+ # These kwargs will be passed to _generate_examples
118
+ gen_kwargs={
119
+ "file_path": data_dir,
120
+ },
121
+ )
122
+ ]
123
+
124
+ def _generate_examples(
125
+ self,
126
+ file_path,
127
+ ):
128
+ """Yields examples as (key, example) tuples."""
129
+ # This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
130
+ # The `key` is here for legacy reason (tfds) and is not important in itself.
131
+
132
+ with open(file_path, encoding="utf-8") as f:
133
+ csv_reader = csv.reader(f, quotechar='"', delimiter=",", quoting=csv.QUOTE_ALL, skipinitialspace=True)
134
+ next(csv_reader, None) # skip header
135
+
136
+ for row_id, row in enumerate(csv_reader):
137
+ language, query, github_url, relevance, notes = row
138
+ yield row_id, {
139
+ "Language": language,
140
+ "Query": query,
141
+ "GitHubUrl": github_url,
142
+ "Relevance": int(relevance),
143
+ "Notes": notes,
144
+ }