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

doc: cleanup documentation of dataloader

Browse files
Files changed (1) hide show
  1. conversational_weather.py +27 -50
conversational_weather.py CHANGED
@@ -12,7 +12,6 @@
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
@@ -52,7 +51,7 @@ _LICENSE = "CC-BY-NC-4.0"
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'
@@ -60,51 +59,31 @@ _URLs = {
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.
@@ -119,16 +98,14 @@ class ConversationalWeather(datasets.GeneratorBasedBuilder):
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,
@@ -159,18 +136,18 @@ class ConversationalWeather(datasets.GeneratorBasedBuilder):
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
- }
 
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
 
16
 
17
  import csv
 
51
  # The HuggingFace dataset library don't host the datasets but only point to the original files
52
  # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
53
  _URLs = {
54
+ 'default': {
55
  'train': 'https://raw.githubusercontent.com/facebookresearch/TreeNLG/master/data/weather/train.tsv',
56
  'validation': 'https://raw.githubusercontent.com/facebookresearch/TreeNLG/master/data/weather/val.tsv',
57
  'test': 'https://raw.githubusercontent.com/facebookresearch/TreeNLG/master/data/weather/test.tsv'
 
59
  }
60
 
61
 
 
62
  class ConversationalWeather(datasets.GeneratorBasedBuilder):
63
+ """The Conversational Weather dataset is designed for generation of responses to weather queries
64
+ based on a structured input data. The input allows specifying data attributes such as dates, times,
65
+ locations, weather conditions, and errors, and also offers control over structure of response through
66
+ discourse relations such as join, contrast, and justification."""
67
 
68
  VERSION = datasets.Version("1.1.0")
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  def _info(self):
71
+ # This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
72
+ features = datasets.Features(
73
+ {
74
+ "gem_id": datasets.Value("string"),
75
+ "data_id": datasets.Value("string"),
76
+ "user_query": datasets.Value("string"),
77
+ "tree_str_mr": datasets.Value("string"),
78
+ "response": datasets.Value("string"),
79
+ }
80
+ )
 
 
 
 
81
 
82
  return datasets.DatasetInfo(
83
  # This is the description that will appear on the datasets page.
84
  description=_DESCRIPTION,
85
  # This defines the different columns of the dataset and their types
86
+ features=features,
87
  # If there's a common (input, target) tuple from the features,
88
  # specify them here. They'll be used if as_supervised=True in
89
  # builder.as_dataset.
 
98
 
99
  def _split_generators(self, dl_manager):
100
  """Returns SplitGenerators."""
101
+ # This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
 
102
 
103
  # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLs
104
  # 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.
105
  # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
106
+
107
  my_urls = _URLs[self.config.name]
 
108
  data_dir = dl_manager.download_and_extract(my_urls)
 
109
  return [
110
  datasets.SplitGenerator(
111
  name=datasets.Split.TRAIN,
 
136
  def _generate_examples(
137
  self, filepath, split # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
138
  ):
139
+ print(filepath)
140
  """ Yields examples as (key, example) tuples. """
141
  # This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
142
  # The `key` is here for legacy reason (tfds) and is not important in itself.
143
  with open(filepath, encoding="utf-8") as f:
144
  csv_reader = csv.reader(f, delimiter='\t')
145
  for id_, row in enumerate(csv_reader):
146
+ assert len(row) == 4
147
+ yield id_, {
148
+ "gem_id": f"{self.config.name}-{split}-{id_}",
149
+ "data_id": row[0],
150
+ "user_query": row[1],
151
+ "tree_str_mr": row[2],
152
+ "response": row[3],
153
+ }