nthngdy commited on
Commit
953289a
·
1 Parent(s): a9c513e

Upload bananas_script.py

Browse files
Files changed (1) hide show
  1. bananas_script.py +123 -0
bananas_script.py ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: Address all TODOs and remove all explanatory comments
16
+ """TODO: Add a description here."""
17
+
18
+
19
+ import csv
20
+ import json
21
+ import os
22
+
23
+ import datasets
24
+
25
+
26
+ # TODO: Add BibTeX citation
27
+ # Find for instance the citation on arxiv or on the dataset repo/website
28
+ _CITATION = """"""
29
+
30
+ # TODO: Add description of the dataset here
31
+ # You can copy an official description
32
+ _DESCRIPTION = """\
33
+ This new dataset is designed to solve this great NLP task and is crafted with a lot of care.
34
+ """
35
+
36
+ # TODO: Add a link to an official homepage for the dataset here
37
+ _HOMEPAGE = ""
38
+
39
+ # TODO: Add the licence for the dataset here if you can find it
40
+ _LICENSE = ""
41
+
42
+ # TODO: Add link to the official dataset URLs here
43
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
44
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
45
+ _URLS = {}
46
+
47
+
48
+ # TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
49
+ class Bananas(datasets.GeneratorBasedBuilder):
50
+ """TODO: Short description of my dataset."""
51
+
52
+ VERSION = datasets.Version("1.1.0")
53
+
54
+ DEFAULT_CONFIG_NAME = "first_domain" # It's not mandatory to have a default configuration. Just use one if it make sense.
55
+
56
+ def _info(self):
57
+ # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
58
+ features = datasets.Features(
59
+ {
60
+ "text": datasets.Value("string")
61
+ }
62
+ )
63
+ return datasets.DatasetInfo(
64
+ # This is the description that will appear on the datasets page.
65
+ description=_DESCRIPTION,
66
+ # This defines the different columns of the dataset and their types
67
+ features=features, # Here we define them above because they are different between the two configurations
68
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
69
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
70
+ # supervised_keys=("sentence", "label"),
71
+ # Homepage of the dataset for documentation
72
+ homepage=_HOMEPAGE,
73
+ # License for the dataset if available
74
+ license=_LICENSE,
75
+ # Citation for the dataset
76
+ citation=_CITATION,
77
+ )
78
+
79
+ def _split_generators(self, dl_manager):
80
+ # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
81
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
82
+
83
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
84
+ # 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.
85
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
86
+ urls = "https://huggingface.co/datasets/nthngdy/bananas/blob/main/
87
+ data_dir = dl_manager.download_and_extract(urls)
88
+ return [
89
+ datasets.SplitGenerator(
90
+ name=datasets.Split.TRAIN,
91
+ # These kwargs will be passed to _generate_examples
92
+ gen_kwargs={
93
+ "filepath": os.path.join(data_dir, "train.txt"),
94
+ "split": "train",
95
+ },
96
+ ),
97
+ datasets.SplitGenerator(
98
+ name=datasets.Split.TEST,
99
+ # These kwargs will be passed to _generate_examples
100
+ gen_kwargs={
101
+ "filepath": os.path.join(data_dir, "test.txt"),
102
+ "split": "test"
103
+ },
104
+ ),
105
+ datasets.SplitGenerator(
106
+ name=datasets.Split.VALIDATION,
107
+ # These kwargs will be passed to _generate_examples
108
+ gen_kwargs={
109
+ "filepath": os.path.join(data_dir, "validation.txt"),
110
+ "split": "validation",
111
+ },
112
+ ),
113
+ ]
114
+
115
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
116
+ def _generate_examples(self, filepath, split):
117
+ # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
118
+ # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
119
+ with open(filepath, encoding="utf-8") as f:
120
+ for key, row in enumerate(f):
121
+ yield key, {
122
+ "text": row
123
+ }