vipulraheja commited on
Commit
71079b6
1 Parent(s): d2c12b5

init: conversational weather data

Browse files
Files changed (3) hide show
  1. README.md +1 -0
  2. conversational_weather.py +176 -0
  3. dataset_infos.json +1 -0
README.md ADDED
@@ -0,0 +1 @@
 
 
1
+ TODO
conversational_weather.py ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 json
20
+ import os
21
+
22
+ import datasets
23
+
24
+
25
+ _CITATION = """\
26
+ @inproceedings{balakrishnan-etal-2019-constrained,
27
+ title = "Constrained Decoding for Neural {NLG} from Compositional Representations in Task-Oriented Dialogue",
28
+ author = "Balakrishnan, Anusha and
29
+ Rao, Jinfeng and
30
+ Upasani, Kartikeya and
31
+ White, Michael and
32
+ Subba, Rajen",
33
+ booktitle = "Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics",
34
+ month = jul,
35
+ year = "2019",
36
+ address = "Florence, Italy",
37
+ publisher = "Association for Computational Linguistics",
38
+ url = "https://www.aclweb.org/anthology/P19-1080",
39
+ doi = "10.18653/v1/P19-1080",
40
+ pages = "831--844"
41
+ }
42
+ """
43
+
44
+ _DESCRIPTION = """\
45
+ The Conversational Weather dataset is designed for generation of responses to weather queries based on a structured input data. The input allows specifying data attributes such as dates, times, locations, weather conditions, and errors, and also offers control over structure of response through discourse relations such as join, contrast, and justification.
46
+ """
47
+
48
+ _HOMEPAGE = "https://github.com/facebookresearch/TreeNLG"
49
+
50
+ _LICENSE = "CC-BY-NC-4.0"
51
+
52
+ # The HuggingFace dataset library don't host the datasets but only point to the original files
53
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
54
+ _URLs = {
55
+ 'weather': {
56
+ 'train': 'https://raw.githubusercontent.com/facebookresearch/TreeNLG/master/data/weather/train.tsv',
57
+ 'validation': 'https://raw.githubusercontent.com/facebookresearch/TreeNLG/master/data/weather/val.tsv',
58
+ 'test': 'https://raw.githubusercontent.com/facebookresearch/TreeNLG/master/data/weather/test.tsv'
59
+ }
60
+ }
61
+
62
+
63
+ # TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
64
+ class ConversationalWeather(datasets.GeneratorBasedBuilder):
65
+ """TODO: Short description of my dataset."""
66
+
67
+ VERSION = datasets.Version("1.1.0")
68
+
69
+ # This is an example of a dataset with multiple configurations.
70
+ # If you don't want/need to define several sub-sets in your dataset,
71
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
72
+
73
+ # If you need to make complex sub-parts in the datasets with configurable options
74
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
75
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
76
+
77
+ # You will be able to load one or the other configurations in the following list with
78
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
79
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
80
+ BUILDER_CONFIGS = [
81
+ datasets.BuilderConfig(name="weather", version=VERSION, description="This part of my dataset covers a first domain"),
82
+ #datasets.BuilderConfig(name="second_domain", version=VERSION, description="This part of my dataset covers a second domain"),
83
+ ]
84
+
85
+ DEFAULT_CONFIG_NAME = "weather" # It's not mandatory to have a default configuration. Just use one if it make sense.
86
+
87
+ def _info(self):
88
+ # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
89
+ if self.config.name == "weather": # This is the name of the configuration selected in BUILDER_CONFIGS above
90
+ features = datasets.Features(
91
+ {
92
+ "gem_id": datasets.Value("string"),
93
+ "data_id": datasets.Value("string"),
94
+ "user_query": datasets.Value("string"),
95
+ "tree_str_mr": datasets.Value("string"),
96
+ "response": datasets.Value("string"),
97
+ # These are the features of your dataset like images, labels ...
98
+ }
99
+ )
100
+ else: # This is an example to show how to have different features for "first_domain" and "second_domain"
101
+ features = datasets.Features({})
102
+
103
+ return datasets.DatasetInfo(
104
+ # This is the description that will appear on the datasets page.
105
+ description=_DESCRIPTION,
106
+ # This defines the different columns of the dataset and their types
107
+ features=features, # Here we define them above because they are different between the two configurations
108
+ # If there's a common (input, target) tuple from the features,
109
+ # specify them here. They'll be used if as_supervised=True in
110
+ # builder.as_dataset.
111
+ supervised_keys=None,
112
+ # Homepage of the dataset for documentation
113
+ homepage=_HOMEPAGE,
114
+ # License for the dataset if available
115
+ license=_LICENSE,
116
+ # Citation for the dataset
117
+ citation=_CITATION,
118
+ )
119
+
120
+ def _split_generators(self, dl_manager):
121
+ """Returns SplitGenerators."""
122
+ # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
123
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
124
+
125
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLs
126
+ # 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.
127
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
128
+ my_urls = _URLs[self.config.name]
129
+ print(my_urls)
130
+ data_dir = dl_manager.download_and_extract(my_urls)
131
+ print(data_dir)
132
+ return [
133
+ datasets.SplitGenerator(
134
+ name=datasets.Split.TRAIN,
135
+ # These kwargs will be passed to _generate_examples
136
+ gen_kwargs={
137
+ "filepath": os.path.join(data_dir['train']),
138
+ "split": "train",
139
+ },
140
+ ),
141
+ datasets.SplitGenerator(
142
+ name=datasets.Split.TEST,
143
+ # These kwargs will be passed to _generate_examples
144
+ gen_kwargs={
145
+ "filepath": os.path.join(data_dir['test']),
146
+ "split": "test"
147
+ },
148
+ ),
149
+ datasets.SplitGenerator(
150
+ name=datasets.Split.VALIDATION,
151
+ # These kwargs will be passed to _generate_examples
152
+ gen_kwargs={
153
+ "filepath": os.path.join(data_dir['validation']),
154
+ "split": "dev",
155
+ },
156
+ ),
157
+ ]
158
+
159
+ def _generate_examples(
160
+ self, filepath, split # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
161
+ ):
162
+ """ Yields examples as (key, example) tuples. """
163
+ # This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
164
+ # The `key` is here for legacy reason (tfds) and is not important in itself.
165
+ with open(filepath, encoding="utf-8") as f:
166
+ csv_reader = csv.reader(f, delimiter='\t')
167
+ for id_, row in enumerate(csv_reader):
168
+ if self.config.name == "weather":
169
+ assert len(row) == 4
170
+ yield id_, {
171
+ "gem_id": f"{self.config.name}-{split}-{id_}",
172
+ "data_id": row[0],
173
+ "user_query": row[1],
174
+ "tree_str_mr": row[2],
175
+ "response": row[3],
176
+ }
dataset_infos.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {'todo': 'true'}