|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import csv |
|
import json |
|
import os |
|
|
|
import datasets |
|
|
|
|
|
|
|
_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} |
|
} |
|
|
|
""" |
|
|
|
|
|
|
|
_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. |
|
""" |
|
|
|
|
|
_HOMEPAGE = "https://diplomat-dataset.github.io" |
|
|
|
|
|
_LICENSE = "CC BY-NC-SA (Attribution-NonCommercial-ShareAlike)" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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" |
|
|
|
def _info(self): |
|
|
|
|
|
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, |
|
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, |
|
|
|
gen_kwargs={ |
|
"filepath": downloaded_files['train'], |
|
"split": "train", |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
|
|
gen_kwargs={ |
|
"filepath": downloaded_files['val'], |
|
"split": "val", |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
|
|
gen_kwargs={ |
|
"filepath": downloaded_files['test'], |
|
"split": "test" |
|
}, |
|
), |
|
] |
|
else: |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={ |
|
"filepath": downloaded_files['train'], |
|
"split": "train", |
|
}, |
|
), |
|
] |
|
|
|
|
|
def _generate_examples(self, filepath, split): |
|
|
|
|
|
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") |
|
|
|
|
|
|