Datasets:

Languages:
English
ArXiv:
License:
DiPlomat / DiPlomat.py
henry12348's picture
update
d98714e
raw
history blame
11.4 kB
# 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")