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