|
import csv |
|
import json |
|
import logging as logger |
|
import os |
|
|
|
import datasets |
|
|
|
|
|
_CITATION = """\ |
|
@misc{welleck2019dialogue, |
|
title={Dialogue Natural Language Inference}, |
|
author={Sean Welleck and Jason Weston and Arthur Szlam and Kyunghyun Cho}, |
|
year={2019}, |
|
eprint={1811.00671}, |
|
archivePrefix={arXiv}, |
|
primaryClass={cs.CL} |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
Dialogue NLI is a dataset that addresses the issue of consistency in dialogue models. |
|
""" |
|
|
|
_URL = "dnli.zip" |
|
|
|
_HOMEPAGE = "https://wellecks.github.io/dialogue_nli/" |
|
|
|
_LICENSE = "MIT" |
|
|
|
class Dialogue_NLI(datasets.GeneratorBasedBuilder): |
|
"""DNLI""" |
|
|
|
VERSION = datasets.Version("1.0.0") |
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig(name="dialogue_nli", version=VERSION, description="dnli"), |
|
] |
|
|
|
DEFAULT_CONFIG_NAME = "dialogue_nli" |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features( |
|
{ |
|
"id": datasets.Value("string"), |
|
"label": datasets.Value("string"), |
|
"premise": datasets.Value("string"), |
|
"hypothesis": datasets.Value("string"), |
|
|
|
|
|
"dtype": datasets.Value("string"), |
|
} |
|
), |
|
|
|
|
|
supervised_keys=None, |
|
homepage=_HOMEPAGE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
|
|
|
|
|
|
|
|
|
|
data_dir = dl_manager.download_and_extract(_URL) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={ |
|
"filepath": os.path.join(data_dir, "dnli/dialogue_nli/dialogue_nli_train.jsonl"), |
|
"split": "train", |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
|
|
gen_kwargs={ |
|
"filepath": os.path.join(data_dir, "dnli/dialogue_nli/dialogue_nli_dev.jsonl"), |
|
"split": "dev", |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
|
|
gen_kwargs={ |
|
"filepath": os.path.join(data_dir, "dnli/dialogue_nli/dialogue_nli_test.jsonl"), |
|
"split": "test" |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, filepath, split): |
|
"""This function returns the examples in the raw (text) form.""" |
|
logger.info("generating examples from = %s", filepath) |
|
with open(filepath) as f: |
|
data = json.load(f) |
|
|
|
for example in data: |
|
label = example.get("label", "").strip() |
|
id_ = example.get("id", "").strip() |
|
hypothesis = example.get("sentence1", "").strip() |
|
premise = example.get("sentence2", "").strip() |
|
dtype = example.get("dtype", "").strip() |
|
|
|
|
|
|
|
yield id_, { |
|
"premise": premise, |
|
"hypothesis": hypothesis, |
|
"id": id_, |
|
"label": label, |
|
"dtype": dtype, |
|
} |
|
|
|
|