Commit
•
6bcf0d7
1
Parent(s):
ab48154
Delete loading script
Browse files
anli.py
DELETED
@@ -1,152 +0,0 @@
|
|
1 |
-
# coding=utf-8
|
2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
3 |
-
#
|
4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
-
# you may not use this file except in compliance with the License.
|
6 |
-
# You may obtain a copy of the License at
|
7 |
-
#
|
8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
-
#
|
10 |
-
# Unless required by applicable law or agreed to in writing, software
|
11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
-
# See the License for the specific language governing permissions and
|
14 |
-
# limitations under the License.
|
15 |
-
|
16 |
-
# Lint as: python3
|
17 |
-
"""The Adversarial NLI Corpus."""
|
18 |
-
|
19 |
-
|
20 |
-
import json
|
21 |
-
import os
|
22 |
-
|
23 |
-
import datasets
|
24 |
-
|
25 |
-
|
26 |
-
_CITATION = """\
|
27 |
-
@InProceedings{nie2019adversarial,
|
28 |
-
title={Adversarial NLI: A New Benchmark for Natural Language Understanding},
|
29 |
-
author={Nie, Yixin
|
30 |
-
and Williams, Adina
|
31 |
-
and Dinan, Emily
|
32 |
-
and Bansal, Mohit
|
33 |
-
and Weston, Jason
|
34 |
-
and Kiela, Douwe},
|
35 |
-
booktitle = "Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics",
|
36 |
-
year = "2020",
|
37 |
-
publisher = "Association for Computational Linguistics",
|
38 |
-
}
|
39 |
-
"""
|
40 |
-
|
41 |
-
_DESCRIPTION = """\
|
42 |
-
The Adversarial Natural Language Inference (ANLI) is a new large-scale NLI benchmark dataset,
|
43 |
-
The dataset is collected via an iterative, adversarial human-and-model-in-the-loop procedure.
|
44 |
-
ANLI is much more difficult than its predecessors including SNLI and MNLI.
|
45 |
-
It contains three rounds. Each round has train/dev/test splits.
|
46 |
-
"""
|
47 |
-
|
48 |
-
stdnli_label = {
|
49 |
-
"e": "entailment",
|
50 |
-
"n": "neutral",
|
51 |
-
"c": "contradiction",
|
52 |
-
}
|
53 |
-
|
54 |
-
|
55 |
-
class ANLIConfig(datasets.BuilderConfig):
|
56 |
-
"""BuilderConfig for ANLI."""
|
57 |
-
|
58 |
-
def __init__(self, **kwargs):
|
59 |
-
"""BuilderConfig for ANLI.
|
60 |
-
|
61 |
-
Args:
|
62 |
-
.
|
63 |
-
**kwargs: keyword arguments forwarded to super.
|
64 |
-
"""
|
65 |
-
super(ANLIConfig, self).__init__(version=datasets.Version("0.1.0", ""), **kwargs)
|
66 |
-
|
67 |
-
|
68 |
-
class ANLI(datasets.GeneratorBasedBuilder):
|
69 |
-
"""ANLI: The ANLI Dataset."""
|
70 |
-
|
71 |
-
BUILDER_CONFIGS = [
|
72 |
-
ANLIConfig(
|
73 |
-
name="plain_text",
|
74 |
-
description="Plain text",
|
75 |
-
),
|
76 |
-
]
|
77 |
-
|
78 |
-
def _info(self):
|
79 |
-
return datasets.DatasetInfo(
|
80 |
-
description=_DESCRIPTION,
|
81 |
-
features=datasets.Features(
|
82 |
-
{
|
83 |
-
"uid": datasets.Value("string"),
|
84 |
-
"premise": datasets.Value("string"),
|
85 |
-
"hypothesis": datasets.Value("string"),
|
86 |
-
"label": datasets.features.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
87 |
-
"reason": datasets.Value("string"),
|
88 |
-
}
|
89 |
-
),
|
90 |
-
# No default supervised_keys (as we have to pass both premise
|
91 |
-
# and hypothesis as input).
|
92 |
-
supervised_keys=None,
|
93 |
-
homepage="https://github.com/facebookresearch/anli/",
|
94 |
-
citation=_CITATION,
|
95 |
-
)
|
96 |
-
|
97 |
-
def _vocab_text_gen(self, filepath):
|
98 |
-
for _, ex in self._generate_examples(filepath):
|
99 |
-
yield " ".join([ex["premise"], ex["hypothesis"]])
|
100 |
-
|
101 |
-
def _split_generators(self, dl_manager):
|
102 |
-
|
103 |
-
downloaded_dir = dl_manager.download_and_extract("https://dl.fbaipublicfiles.com/anli/anli_v0.1.zip")
|
104 |
-
|
105 |
-
anli_path = os.path.join(downloaded_dir, "anli_v0.1")
|
106 |
-
|
107 |
-
path_dict = dict()
|
108 |
-
for round_tag in ["R1", "R2", "R3"]:
|
109 |
-
path_dict[round_tag] = dict()
|
110 |
-
for split_name in ["train", "dev", "test"]:
|
111 |
-
path_dict[round_tag][split_name] = os.path.join(anli_path, round_tag, f"{split_name}.jsonl")
|
112 |
-
|
113 |
-
return [
|
114 |
-
# Round 1
|
115 |
-
datasets.SplitGenerator(name="train_r1", gen_kwargs={"filepath": path_dict["R1"]["train"]}),
|
116 |
-
datasets.SplitGenerator(name="dev_r1", gen_kwargs={"filepath": path_dict["R1"]["dev"]}),
|
117 |
-
datasets.SplitGenerator(name="test_r1", gen_kwargs={"filepath": path_dict["R1"]["test"]}),
|
118 |
-
# Round 2
|
119 |
-
datasets.SplitGenerator(name="train_r2", gen_kwargs={"filepath": path_dict["R2"]["train"]}),
|
120 |
-
datasets.SplitGenerator(name="dev_r2", gen_kwargs={"filepath": path_dict["R2"]["dev"]}),
|
121 |
-
datasets.SplitGenerator(name="test_r2", gen_kwargs={"filepath": path_dict["R2"]["test"]}),
|
122 |
-
# Round 3
|
123 |
-
datasets.SplitGenerator(name="train_r3", gen_kwargs={"filepath": path_dict["R3"]["train"]}),
|
124 |
-
datasets.SplitGenerator(name="dev_r3", gen_kwargs={"filepath": path_dict["R3"]["dev"]}),
|
125 |
-
datasets.SplitGenerator(name="test_r3", gen_kwargs={"filepath": path_dict["R3"]["test"]}),
|
126 |
-
]
|
127 |
-
|
128 |
-
def _generate_examples(self, filepath):
|
129 |
-
"""Generate mnli examples.
|
130 |
-
|
131 |
-
Args:
|
132 |
-
filepath: a string
|
133 |
-
|
134 |
-
Yields:
|
135 |
-
dictionaries containing "premise", "hypothesis" and "label" strings
|
136 |
-
"""
|
137 |
-
for idx, line in enumerate(open(filepath, "rb")):
|
138 |
-
if line is not None:
|
139 |
-
line = line.strip().decode("utf-8")
|
140 |
-
item = json.loads(line)
|
141 |
-
|
142 |
-
reason_text = ""
|
143 |
-
if "reason" in item:
|
144 |
-
reason_text = item["reason"]
|
145 |
-
|
146 |
-
yield item["uid"], {
|
147 |
-
"uid": item["uid"],
|
148 |
-
"premise": item["context"],
|
149 |
-
"hypothesis": item["hypothesis"],
|
150 |
-
"label": stdnli_label[item["label"]],
|
151 |
-
"reason": reason_text,
|
152 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|