|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""" |
|
The SciTail dataset is an entailment dataset created from multiple-choice science exams and |
|
web sentences. Each question and the correct answer choice are converted into an assertive |
|
statement to form the hypothesis. We use information retrieval to obtain relevant text from |
|
a large text corpus of web sentences, and use these sentences as a premise P. We crowdsource |
|
the annotation of such premise-hypothesis pair as supports (entails) or not (neutral), in order |
|
to create the SciTail dataset. The dataset contains 27,026 examples with 10,101 examples with |
|
entails label and 16,925 examples with neutral label. |
|
""" |
|
import os |
|
|
|
import datasets |
|
import pandas as pd |
|
|
|
from .licenses_data import LICENSES_DATA |
|
from .bigbiohub import entailment_features |
|
from .bigbiohub import BigBioConfig |
|
from .bigbiohub import Lang |
|
from .licenses import Licenses |
|
from .bigbiohub import Tasks |
|
|
|
|
|
_LANGUAGES = [Lang.EN] |
|
_PUBMED = False |
|
_LOCAL = False |
|
_CITATION = """\ |
|
@inproceedings{scitail, |
|
author = {Tushar Khot and Ashish Sabharwal and Peter Clark}, |
|
booktitle = {AAAI} |
|
title = {SciTail: A Textual Entailment Dataset from Science Question Answering}, |
|
year = {2018} |
|
} |
|
""" |
|
|
|
_DATASETNAME = "scitail" |
|
_DISPLAYNAME = "SciTail" |
|
|
|
_DESCRIPTION = """\ |
|
The SciTail dataset is an entailment dataset created from multiple-choice science exams and |
|
web sentences. Each question and the correct answer choice are converted into an assertive |
|
statement to form the hypothesis. We use information retrieval to obtain relevant text from |
|
a large text corpus of web sentences, and use these sentences as a premise P. We crowdsource |
|
the annotation of such premise-hypothesis pair as supports (entails) or not (neutral), in order |
|
to create the SciTail dataset. The dataset contains 27,026 examples with 10,101 examples with |
|
entails label and 16,925 examples with neutral label. |
|
""" |
|
|
|
_HOMEPAGE = "https://allenai.org/data/scitail" |
|
|
|
_LICENSE = Licenses.APACHE_2p0 |
|
|
|
_URLS = { |
|
_DATASETNAME: "https://ai2-public-datasets.s3.amazonaws.com/scitail/SciTailV1.1.zip", |
|
} |
|
|
|
_SUPPORTED_TASKS = [Tasks.TEXTUAL_ENTAILMENT] |
|
|
|
_SOURCE_VERSION = "1.1.0" |
|
|
|
_BIGBIO_VERSION = "1.0.0" |
|
|
|
|
|
LABEL_MAP = {"entails": "entailment", "neutral": "neutral"} |
|
|
|
|
|
class SciTailDataset(datasets.GeneratorBasedBuilder): |
|
"""TODO: Short description of my dataset.""" |
|
|
|
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION) |
|
BIGBIO_VERSION = datasets.Version(_BIGBIO_VERSION) |
|
|
|
BUILDER_CONFIGS = [ |
|
BigBioConfig( |
|
name="scitail_source", |
|
version=SOURCE_VERSION, |
|
description="SciTail source schema", |
|
schema="source", |
|
subset_id="scitail", |
|
), |
|
BigBioConfig( |
|
name="scitail_bigbio_te", |
|
version=BIGBIO_VERSION, |
|
description="SciTail BigBio schema", |
|
schema="bigbio_te", |
|
subset_id="scitail", |
|
), |
|
] |
|
|
|
DEFAULT_CONFIG_NAME = "scitail_source" |
|
|
|
def _info(self): |
|
|
|
if self.config.schema == "source": |
|
features = datasets.Features( |
|
{ |
|
"id": datasets.Value("string"), |
|
"premise": datasets.Value("string"), |
|
"hypothesis": datasets.Value("string"), |
|
"label": datasets.Value("string"), |
|
} |
|
) |
|
|
|
elif self.config.schema == "bigbio_te": |
|
features = entailment_features |
|
|
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=features, |
|
homepage=_HOMEPAGE, |
|
license=str(_LICENSE), |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
|
|
urls = _URLS[_DATASETNAME] |
|
data_dir = dl_manager.download_and_extract(urls) |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"filepath": os.path.join( |
|
data_dir, "SciTailV1.1", "tsv_format", "scitail_1.0_train.tsv" |
|
), |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
gen_kwargs={ |
|
"filepath": os.path.join( |
|
data_dir, "SciTailV1.1", "tsv_format", "scitail_1.0_test.tsv" |
|
), |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
gen_kwargs={ |
|
"filepath": os.path.join( |
|
data_dir, "SciTailV1.1", "tsv_format", "scitail_1.0_dev.tsv" |
|
), |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, filepath): |
|
|
|
|
|
data = pd.read_csv( |
|
filepath, sep="\t", names=["premise", "hypothesis", "label"], quoting=3 |
|
) |
|
data["id"] = data.index |
|
|
|
if self.config.schema == "source": |
|
for _, row in data.iterrows(): |
|
yield row["id"], row.to_dict() |
|
|
|
elif self.config.schema == "bigbio_te": |
|
|
|
data["label"] = data["label"].apply(lambda x: LABEL_MAP[x]) |
|
for _, row in data.iterrows(): |
|
yield row["id"], row.to_dict() |
|
|