File size: 7,345 Bytes
00e441e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d81f894
66e1546
 
00e441e
 
5241e61
00e441e
 
 
7b34cb1
 
 
 
 
 
 
 
 
 
 
00e441e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5241e61
00e441e
 
 
 
 
a8ac55e
00e441e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a8ac55e
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
# coding=utf-8
# Copyright 2022 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.

"""
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 .bigbiohub import entailment_features
from .bigbiohub import BigBioConfig
from .bigbiohub import Tasks


_LANGUAGES = ["English"]
_PUBMED = False
_LOCAL = False
_CITATION = """\
@article{
    Khot_Sabharwal_Clark_2018,
    title={SciTaiL: A Textual Entailment Dataset from Science Question Answering},
    volume={32},
    url={https://ojs.aaai.org/index.php/AAAI/article/view/12022}, DOI={10.1609/aaai.v32i1.12022},
    abstractNote={ <p> We present a new dataset and model for textual entailment, derived from treating multiple-choice question-answering as an entailment problem. SciTail is the first entailment set that is created solely from natural sentences that already exist independently ``in the wild’’ rather than sentences authored specifically for the entailment task. Different from existing entailment datasets, we create hypotheses from science questions and the corresponding answer candidates, and premises from relevant web sentences retrieved from a large corpus. These sentences are often linguistically challenging. This, combined with the high lexical similarity of premise and hypothesis for both entailed and non-entailed pairs, makes this new entailment task particularly difficult. The resulting challenge is evidenced by state-of-the-art textual entailment systems achieving mediocre performance on SciTail, especially in comparison to a simple majority class baseline. As a step forward, we demonstrate that one can improve accuracy on SciTail by 5% using a new neural model that exploits linguistic structure. </p> },
    number={1},
    journal={Proceedings of the AAAI Conference on Artificial Intelligence},
    author={Khot, Tushar and Sabharwal, Ashish and Clark, Peter},
    year={2018},
    month={Apr.}
}
"""

_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 = "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):
        # since examples can contain quotes mid text set quoting to QUOTE_NONE (3) when reading tsv
        # e.g.: ... and apply specific "tools" to examples and ...
        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":
            # normalize labels
            data["label"] = data["label"].apply(lambda x: LABEL_MAP[x])
            for _, row in data.iterrows():
                yield row["id"], row.to_dict()