Datasets:

Languages:
English
ArXiv:
License:
henry12348 commited on
Commit
d98714e
1 Parent(s): 3dcb529
Files changed (1) hide show
  1. DiPlomat.py +237 -0
DiPlomat.py ADDED
@@ -0,0 +1,237 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # TODO: Address all TODOs and remove all explanatory comments
15
+
16
+
17
+ import csv
18
+ import json
19
+ import os
20
+
21
+ import datasets
22
+
23
+
24
+ # Find for instance the citation on arxiv or on the dataset repo/website
25
+ _CITATION = """\
26
+ @inproceedings{li2023diplomat,
27
+ title={DiPlomat: A Dialogue Dataset for Situated Pragmatic Reasoning},
28
+ author={Hengli Li, Song-Chun Zhu, Zilong Zheng},
29
+ booktitle={Thirty-seventh Conference on Neural Information Processing Systems Datasets and Benchmarks Track},
30
+ year={2023}
31
+ }
32
+
33
+ """
34
+
35
+ # TODO: Add description of the dataset here
36
+ # You can copy an official description
37
+ _DESCRIPTION = """\
38
+ Pragmatic reasoning plays a pivotal role in deciphering implicit meanings that frequently arise in real-life conversations and is essential for the development of communicative social agents. In this paper, we introduce a novel challenge, DiPlomat, aiming at benchmarking machines’ capabilities on pragmatic reasoning and situated conversational understanding. Compared with previous works that treat different figurative expressions (e.g. metaphor, sarcasm) as individual tasks, DiPlomat provides a cohesive framework towards general pragmatic understanding.
39
+ """
40
+
41
+ # TODO: Add a link to an official homepage for the dataset here
42
+ _HOMEPAGE = "https://diplomat-dataset.github.io"
43
+
44
+ # TODO: Add the licence for the dataset here if you can find it
45
+ _LICENSE = "CC BY-NC-SA (Attribution-NonCommercial-ShareAlike)"
46
+
47
+ # TODO: Add link to the official dataset URLs here
48
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
49
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
50
+ #_URLS = {
51
+ # "PIR_first": "https://huggingface.co/datasets/henry12348/DiPlomat/PIR_first_subtask_dataset",
52
+ # "PIR_second": "https://huggingface.co/datasets/henry12348/DiPlomat/tree/main/PIR_second_subtask_dataset",
53
+ # "CQA": "https://huggingface.co/datasets/henry12348/DiPlomat/tree/main/CQA_task_dataset",
54
+ #"NLI_without_context":"https://huggingface.co/datasets/henry12348/DiPlomat/tree/main/NLI_dataset_without_context",
55
+ #"NLI_with_context":"https://huggingface.co/datasets/henry12348/DiPlomat/tree/main/NLI_task_dataset",
56
+ #}
57
+
58
+
59
+ # TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
60
+ class Diplomat(datasets.GeneratorBasedBuilder):
61
+ """This is the DiPlomat Dataset focusing on pragmatic reasoning."""
62
+
63
+ VERSION = datasets.Version("1.1.0")
64
+
65
+ BUILDER_CONFIGS = [
66
+ datasets.BuilderConfig(name="PIR_first", version=VERSION, description="This part of dataset covers the Pragmatic Identification and Reasoning Task Subtask 1"),
67
+ datasets.BuilderConfig(name="PIR_second", version=VERSION, description="This part of dataset covers the Pragmatic Identification and Reasoning Task Subtask 2"),
68
+ datasets.BuilderConfig(name="CQA", version=VERSION, description="This part of dataset covers the Conversational Question Answering Task"),
69
+ datasets.BuilderConfig(name="NLI_without_context", version=VERSION, description="This part of dataset covers the Zero-Shot Natural Language Inference Task"),
70
+ datasets.BuilderConfig(name="NLI_with_context", version=VERSION, description="This part of dataset covers the Zero-Shot Natural Language Inference Task")
71
+ ]
72
+ DEFAULT_CONFIG_NAME = "PIR_first" # It's not mandatory to have a default configuration. Just use one if it make sense.
73
+
74
+ def _info(self):
75
+ # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
76
+ # This is the name of the configuration selected in BUILDER_CONFIGS above
77
+ if self.config.name == "PIR_first":
78
+ features = datasets.Features(
79
+ {
80
+ "text": datasets.Sequence(datasets.Value("string")),
81
+ "speaker": datasets.Sequence(datasets.Value("string")),
82
+ "correct_turn_number":datasets.Sequence(datasets.Value("int64")),
83
+ }
84
+ )
85
+ elif self.config.name == "PIR_second":
86
+ features = datasets.Features(
87
+ {
88
+ "text": datasets.Sequence(datasets.Value("string")),
89
+ "speaker": datasets.Sequence(datasets.Value("string")),
90
+ "correct_turn_number":datasets.Value("int64"),
91
+ "label": datasets.Value("int64"),
92
+ "choice": datasets.Sequence(datasets.Value("string")),
93
+ }
94
+ )
95
+ elif self.config.name == "CQA":
96
+ features = datasets.Features(
97
+ {
98
+ "text": datasets.Sequence(datasets.Value("string")),
99
+ "speaker": datasets.Sequence(datasets.Value("string")),
100
+ "gold_statement": datasets.Value("string"),
101
+ "questions": datasets.Value("string"),
102
+ "answer": datasets.Value("string"),
103
+ }
104
+ )
105
+ elif self.config.name == "NLI_without_context":
106
+ features = datasets.Features(
107
+ {
108
+ "text": datasets.Value("string"),
109
+ "hypothesis": datasets.Value("string"),
110
+ }
111
+ )
112
+
113
+ elif self.config.name == "NLI_with_context":
114
+ features = datasets.Features(
115
+ {
116
+ "dialogue": datasets.Sequence(datasets.Value("string")),
117
+ "speaker": datasets.Sequence(datasets.Value("string")),
118
+ "human answer": datasets.Value("string"),
119
+ }
120
+ )
121
+ else:
122
+ raise ValueError("Unknown configuration name selected")
123
+
124
+
125
+ return datasets.DatasetInfo(
126
+ description=_DESCRIPTION,
127
+ features=features, # Here we define them above because they are different between the two configurations
128
+ homepage=_HOMEPAGE,
129
+ license=_LICENSE,
130
+ citation=_CITATION,
131
+ )
132
+
133
+ def _split_generators(self, dl_manager):
134
+ if self.config.name == "PIR_first":
135
+ name = "PIR_first_subtask_dataset"
136
+ urls = {'train':f"{name}/train.jsonl",'test':f"{name}/test.jsonl",'val':f"{name}/val.jsonl"}
137
+ elif self.config.name == "PIR_second":
138
+ name = "PIR_second_subtask_dataset"
139
+ urls = {'train':f"{name}/train.jsonl",'test':f"{name}/test.jsonl",'val':f"{name}/val.jsonl"}
140
+ elif self.config.name == "CQA":
141
+ name = "CQA_task_dataset"
142
+ urls = {'train':f"{name}/train.jsonl",'test':f"{name}/test.jsonl",'val':f"{name}/val.jsonl"}
143
+ elif self.config.name == "NLI_without_context":
144
+ name = "NLI_dataset_without_context"
145
+ urls = {'train':f"{name}/dataset.json"}
146
+ elif self.config.name == "NLI_with_context":
147
+ name = "NLI_task_dataset"
148
+ urls = {'train':f"{name}/dataset.json"}
149
+ else:
150
+ raise ValueError("Unknown configuration name selected")
151
+
152
+ downloaded_files = dl_manager.download_and_extract(urls)
153
+
154
+
155
+ if "NLI" not in self.config.name:
156
+ return [
157
+ datasets.SplitGenerator(
158
+ name=datasets.Split.TRAIN,
159
+ # These kwargs will be passed to _generate_examples
160
+ gen_kwargs={
161
+ "filepath": downloaded_files['train'],
162
+ "split": "train",
163
+ },
164
+ ),
165
+ datasets.SplitGenerator(
166
+ name=datasets.Split.VALIDATION,
167
+ # These kwargs will be passed to _generate_examples
168
+ gen_kwargs={
169
+ "filepath": downloaded_files['val'],
170
+ "split": "val",
171
+ },
172
+ ),
173
+ datasets.SplitGenerator(
174
+ name=datasets.Split.TEST,
175
+ # These kwargs will be passed to _generate_examples
176
+ gen_kwargs={
177
+ "filepath": downloaded_files['test'],
178
+ "split": "test"
179
+ },
180
+ ),
181
+ ]
182
+ else:
183
+ return [
184
+ datasets.SplitGenerator(
185
+ name=datasets.Split.TRAIN,
186
+ # These kwargs will be passed to _generate_examples
187
+ gen_kwargs={
188
+ "filepath": downloaded_files['train'],
189
+ "split": "train",
190
+ },
191
+ ),
192
+ ]
193
+
194
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
195
+ def _generate_examples(self, filepath, split):
196
+ # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
197
+ # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
198
+ with open(filepath, encoding="utf-8") as f:
199
+ for key, row in enumerate(f):
200
+ data = json.loads(row)
201
+ if self.config.name == "PIR_first":
202
+ yield key,{
203
+ "text": data['text'],
204
+ "speaker": data['speaker'],
205
+ "correct_turn_number":data['correct_turn_number'],
206
+ }
207
+ elif self.config.name == "PIR_second":
208
+ yield key, {
209
+ "text": data['text'],
210
+ "speaker": data['speaker'],
211
+ "correct_turn_number":data['correct_turn_number'],
212
+ "label": data['label'],
213
+ "choice": data['choice'],
214
+ }
215
+ elif self.config.name == "CQA":
216
+ yield key,{
217
+ "text": data['text'],
218
+ "speaker": data['speaker'],
219
+ "gold_statement": data['gold_statement'],
220
+ "questions": data['questions'],
221
+ "answer": data['answer'],
222
+ }
223
+ elif self.config.name == "NLI_without_context":
224
+ yield key,{
225
+ "text": data['text'],
226
+ "hypothesis": data['hypothesis'],
227
+ }
228
+ elif self.config.name == "NLI_with_context":
229
+ yield key,{
230
+ "dialogue": data['dialogue'],
231
+ "speaker": data['speaker'],
232
+ "human answer": data['human answer'],
233
+ }
234
+ else:
235
+ raise ValueError("Unknown configuration name selected")
236
+
237
+