oluwatosin adewumi commited on
Commit
add1178
1 Parent(s): 5c61a53

python script added

Browse files
Files changed (1) hide show
  1. Taskmaster.py +180 -0
Taskmaster.py ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # TODO: Add BibTeX citation
26
+ # Find for instance the citation on arxiv or on the dataset repo/website
27
+ _CITATION = """\
28
+ @article{byrne2020tickettalk,
29
+ title={TicketTalk: Toward human-level performance with end-to-end, transaction-based dialog systems},
30
+ author={Byrne, Bill and Krishnamoorthi, Karthik and Ganesh, Saravanan and Kale, Mihir Sanjay},
31
+ journal={arXiv preprint arXiv:2012.12458},
32
+ year={2020}
33
+ }
34
+ """
35
+
36
+ # TODO: Add description of the dataset here
37
+ # You can copy an official description
38
+ _DESCRIPTION = """\
39
+ The Taskmaster-3 (aka TicketTalk) dataset consists of 23,789 movie ticketing dialogs (located in Taskmaster/TM-3-2020/data/). By "movie ticketing" we mean conversations where the customer's goal is to purchase tickets after deciding on theater, time, movie name, number of tickets, and date, or opt out of the transaction.
40
+ The columns are gem_id, 0, 1 for serial numbering, 2 for the text dialog and id for the default id by the authors.
41
+ """
42
+
43
+ # TODO: Add a link to an official homepage for the dataset here
44
+ _HOMEPAGE = "https://github.com/google-research-datasets/Taskmaster/tree/master/TM-3-2020"
45
+
46
+ # TODO: Add the licence for the dataset here if you can find it
47
+ _LICENSE = "CC BY 4.0"
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
+ _URLs = {
53
+ "train": "https://huggingface.co/datasets/GEM/Taskmaster/train.csv",
54
+ "dev": "https://huggingface.co/datasets/GEM/Taskmaster/dev.csv",
55
+ "test": "https://huggingface.co/datasets/GEM/Taskmaster/test.csv",
56
+ }
57
+
58
+
59
+ # TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
60
+ class Taskmaster(datasets.GeneratorBasedBuilder):
61
+ """The Taskmaster-3 (aka TicketTalk) dataset consists of 23,789 movie ticketing dialogs. The columns are gem_id, 0, 1 for serial numbering, 2 for the text dialog and id for the default id by the authors."""
62
+
63
+ VERSION = datasets.Version("3.0")
64
+
65
+
66
+ # If you need to make complex sub-parts in the datasets with configurable options
67
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
68
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
69
+
70
+ # You will be able to load one or the other configurations in the following list with
71
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
72
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
73
+ BUILDER_CONFIGS = [
74
+ datasets.BuilderConfig(name="train", version=VERSION, description="training set"),
75
+ datasets.BuilderConfig(name="dev", version=VERSION, description="dev set"),
76
+ datasets.BuilderConfig(name="test", version=VERSION, description="test set"),
77
+ ]
78
+
79
+ DEFAULT_CONFIG_NAME = "TaskmasterConfigName" # It's not mandatory to have a default configuration. Just use one if it makes sense.
80
+
81
+ def _info(self):
82
+ # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
83
+ features = datasets.Features(
84
+ {
85
+ "gem_id": datasets.Value("string"),
86
+ "0": datasets.Value("string"),
87
+ "1": datasets.Value("string"),
88
+ "2": datasets.Value("string"),
89
+ "id": datasets.Value("string"),
90
+ # "paragraphs": datasets.features.Sequence(
91
+ # datasets.Value("string")),
92
+ # "summary": datasets.features.Sequence(
93
+ # {
94
+ # "text": datasets.Value("string"),
95
+ # "topic": datasets.Value("int"),
96
+ # })
97
+ # These are the features of your dataset like images, labels ...
98
+ }
99
+ )
100
+ return datasets.DatasetInfo(
101
+ # This is the description that will appear on the datasets page.
102
+ description=_DESCRIPTION,
103
+ # This defines the different columns of the dataset and their types
104
+ features=features, # Here we define them above because they are different between the two configurations
105
+ # If there's a common (input, target) tuple from the features,
106
+ # specify them here. They'll be used if as_supervised=True in
107
+ # builder.as_dataset.
108
+ supervised_keys=None,
109
+ # Homepage of the dataset for documentation
110
+ homepage=_HOMEPAGE,
111
+ # License for the dataset if available
112
+ license=_LICENSE,
113
+ # Citation for the dataset
114
+ citation=_CITATION,
115
+ )
116
+
117
+ def _split_generators(self, dl_manager):
118
+ """Returns SplitGenerators."""
119
+ # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
120
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
121
+
122
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLs
123
+ # 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.
124
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
125
+ my_urls = _URLs[self.config.name]
126
+ data_dir = dl_manager.download_and_extract(my_urls)
127
+ challenge_sets = [
128
+ ("challenge_%s_nov_%s" % (split,lvl),"%s-%s_nv2_%s.jsonl" % (split,self.config.name,lvl)) \
129
+ for split in ["train","valid","test"] for lvl in ["low","mid","high"]
130
+ ]
131
+ # + ...
132
+
133
+ return [
134
+ datasets.SplitGenerator(
135
+ name=datasets.Split.TRAIN,
136
+ # These kwargs will be passed to _generate_examples
137
+ gen_kwargs={
138
+ "filepath": os.path.join(data_dir, "train-%s.jsonl" % (self.config.name)),
139
+ "split": "train",
140
+ },
141
+ ),
142
+ datasets.SplitGenerator(
143
+ name=datasets.Split.TEST,
144
+ # These kwargs will be passed to _generate_examples
145
+ gen_kwargs={
146
+ "filepath": os.path.join(data_dir, "test-%s.jsonl" % (self.config.name)),
147
+ "split": "test"
148
+ },
149
+ ),
150
+ datasets.SplitGenerator(
151
+ name=datasets.Split.VALIDATION,
152
+ # These kwargs will be passed to _generate_examples
153
+ gen_kwargs={
154
+ "filepath": os.path.join(data_dir, "valid-%s.jsonl" % (self.config.name)),
155
+ "split": "dev",
156
+ },
157
+ ),
158
+ ] + [
159
+ datasets.SplitGenerator(
160
+ name=challenge_split,
161
+ gen_kwargs={
162
+ "filepath": os.path.join(data_dir, filename),
163
+ "split": challenge_split,
164
+ },
165
+ )
166
+ for challenge_split, filename in challenge_sets
167
+ ]
168
+
169
+ def _generate_examples(
170
+ self, filepath, split # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
171
+ ):
172
+ """ Yields examples as (key, example) tuples. """
173
+ # This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
174
+ # The `key` is here for legacy reason (tfds) and is not important in itself.
175
+
176
+ with open(filepath, encoding="utf-8") as f:
177
+ for row in f:
178
+ data = json.loads(row)
179
+ data["gem_id"] = "GEM-TASKMASTER-%s-%d" % (split,data["id"]+1)
180
+ yield data["id"],data