# 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()