|
''' |
|
Author: Xiang Pan |
|
Date: 2021-09-20 01:38:55 |
|
LastEditTime: 2021-09-20 01:45:46 |
|
LastEditors: Xiang Pan |
|
Description: |
|
FilePath: /SNLI_OOD/cached_datasets/snli_break/snli_break.py |
|
xiangpan@nyu.edu |
|
''' |
|
import csv |
|
import os |
|
|
|
import datasets |
|
|
|
_DESCRIPTION = """\ |
|
The SNLI corpus (version 1.0) is a collection of 570k human-written English |
|
sentence pairs manually labeled for balanced classification with the labels |
|
entailment, contradiction, and neutral, supporting the task of natural language |
|
inference (NLI), also known as recognizing textual entailment (RTE). |
|
""" |
|
|
|
|
|
|
|
|
|
class snli_break(datasets.GeneratorBasedBuilder): |
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig( |
|
name="plain_text", |
|
version=datasets.Version("1.0.0", ""), |
|
description="Plain text import of SNLI", |
|
) |
|
] |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
|
|
data_dir = ("./") |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, gen_kwargs={"filepath": os.path.join(data_dir, "dataset.jsonl")} |
|
), |
|
|
|
|
|
|
|
|
|
|
|
|
|
] |
|
|
|
def _generate_examples(self, filepath): |
|
"""This function returns the examples in the raw (text) form.""" |
|
with open(filepath, encoding="utf-8") as f: |
|
reader = csv.DictReader(f, delimiter="\t", quoting=csv.QUOTE_NONE) |
|
for idx, row in enumerate(reader): |
|
label = -1 if row["gold_label"] == "-" else row["gold_label"] |
|
yield idx, { |
|
"premise": row["sentence1"], |
|
"hypothesis": row["sentence2"], |
|
"label": label, |
|
} |