Datasets:
File size: 5,184 Bytes
ee2b54f 8e5d807 ee2b54f 8e5d807 ee2b54f 8e5d807 ee2b54f 6d6dae5 ee2b54f 988385d ee2b54f |
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 |
# coding=utf-8
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
#
# 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.
# Lint as: python3
"""The Adversarial NLI Corpus."""
import json
import os
import datasets
_CITATION = """\
@InProceedings{nie2019adversarial,
title={Adversarial NLI: A New Benchmark for Natural Language Understanding},
author={Nie, Yixin
and Williams, Adina
and Dinan, Emily
and Bansal, Mohit
and Weston, Jason
and Kiela, Douwe},
booktitle = "Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics",
year = "2020",
publisher = "Association for Computational Linguistics",
}
"""
_DESCRIPTION = """\
The Adversarial Natural Language Inference (ANLI) is a new large-scale NLI benchmark dataset,
The dataset is collected via an iterative, adversarial human-and-model-in-the-loop procedure.
ANLI is much more difficult than its predecessors including SNLI and MNLI.
It contains three rounds. Each round has train/dev/test splits.
"""
class ANLIConfig(datasets.BuilderConfig):
"""BuilderConfig for ANLI."""
def __init__(self, **kwargs):
"""BuilderConfig for ANLI.
Args:
.
**kwargs: keyword arguments forwarded to super.
"""
super(ANLIConfig, self).__init__(version=datasets.Version("0.1.0", ""), **kwargs)
class ANLI(datasets.GeneratorBasedBuilder):
"""ANLI: The ANLI Dataset."""
BUILDER_CONFIGS = [
ANLIConfig(
name=bias_amplified_splits_type,
description="",
) for bias_amplified_splits_type in ["minority_examples", "partial_input"]
]
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"round": datasets.Value("string"),
"uid": datasets.Value("string"),
"premise": datasets.Value("string"),
"hypothesis": datasets.Value("string"),
"label": datasets.features.ClassLabel(names=["entailment", "neutral", "contradiction"]),
"reason": datasets.Value("string"),
}
),
# No default supervised_keys (as we have to pass both premise
# and hypothesis as input).
supervised_keys=None,
homepage="https://github.com/facebookresearch/anli/",
citation=_CITATION,
)
def _vocab_text_gen(self, filepath):
for _, ex in self._generate_examples(filepath):
yield " ".join([ex["premise"], ex["hypothesis"]])
def _split_generators(self, dl_manager):
return [
datasets.SplitGenerator(name="train.biased", gen_kwargs={"filepath": dl_manager.download(os.path.join(self.config.name, "train.biased.jsonl"))}),
datasets.SplitGenerator(name="train.anti_biased", gen_kwargs={"filepath": dl_manager.download(os.path.join(self.config.name, "train.anti_biased.jsonl"))}),
datasets.SplitGenerator(name="validation.biased", gen_kwargs={"filepath": dl_manager.download(os.path.join(self.config.name, "validation.biased.jsonl"))}),
datasets.SplitGenerator(name="validation.anti_biased", gen_kwargs={"filepath": dl_manager.download(os.path.join(self.config.name, "validation.anti_biased.jsonl"))}),
datasets.SplitGenerator(name="test.biased", gen_kwargs={"filepath": dl_manager.download(os.path.join(self.config.name, "test.biased.jsonl"))}),
datasets.SplitGenerator(name="test.anti_biased", gen_kwargs={"filepath": dl_manager.download(os.path.join(self.config.name, "test.anti_biased.jsonl"))})
]
def _generate_examples(self, filepath):
"""Generate examples.
Args:
filepath: a string
Yields:
dictionaries containing "premise", "hypothesis" and "label" strings
"""
for idx, line in enumerate(open(filepath, "rb")):
if line is not None:
line = line.strip().decode("utf-8")
item = json.loads(line)
reason_text = ""
if "reason" in item:
reason_text = item["reason"]
yield f'{item["round"]}-{item["uid"]}', {
"round": item["round"],
"uid": item["uid"],
"premise": item["premise"],
"hypothesis": item["hypothesis"],
"label": item["label"],
"reason": reason_text,
}
|