|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""The Multi-Genre NLI Corpus.""" |
|
|
|
|
|
import json |
|
import os |
|
|
|
import datasets |
|
|
|
|
|
_CITATION = """\ |
|
@InProceedings{N18-1101, |
|
author = {Williams, Adina |
|
and Nangia, Nikita |
|
and Bowman, Samuel}, |
|
title = {A Broad-Coverage Challenge Corpus for |
|
Sentence Understanding through Inference}, |
|
booktitle = {Proceedings of the 2018 Conference of |
|
the North American Chapter of the |
|
Association for Computational Linguistics: |
|
Human Language Technologies, Volume 1 (Long |
|
Papers)}, |
|
year = {2018}, |
|
publisher = {Association for Computational Linguistics}, |
|
pages = {1112--1122}, |
|
location = {New Orleans, Louisiana}, |
|
url = {http://aclweb.org/anthology/N18-1101} |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
The Multi-Genre Natural Language Inference (MultiNLI) corpus is a |
|
crowd-sourced collection of 433k sentence pairs annotated with textual |
|
entailment information. The corpus is modeled on the SNLI corpus, but differs in |
|
that covers a range of genres of spoken and written text, and supports a |
|
distinctive cross-genre generalization evaluation. The corpus served as the |
|
basis for the shared task of the RepEval 2017 Workshop at EMNLP in Copenhagen. |
|
""" |
|
|
|
|
|
class MultiNLIWithBiasSplits(datasets.GeneratorBasedBuilder): |
|
"""MultiNLI: The Stanford Question Answering Dataset. Version 1.1.""" |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features( |
|
{ |
|
"promptID": datasets.Value("int32"), |
|
"pairID": datasets.Value("string"), |
|
"premise": datasets.Value("string"), |
|
"premise_binary_parse": datasets.Value("string"), |
|
"premise_parse": datasets.Value("string"), |
|
"hypothesis": datasets.Value("string"), |
|
"hypothesis_binary_parse": datasets.Value("string"), |
|
"hypothesis_parse": datasets.Value( |
|
"string" |
|
), |
|
"genre": datasets.Value("string"), |
|
"label": datasets.features.ClassLabel(names=["entailment", "neutral", "contradiction"]), |
|
} |
|
), |
|
|
|
|
|
supervised_keys=None, |
|
homepage="https://www.nyu.edu/projects/bowman/multinli/", |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
|
|
|
|
|
|
mnli_path = "/mnt/sda/Labs/DatasetDistillationNLP/cached_datasets/multi_nli_with_bias_split/multinli_1.0" |
|
|
|
|
|
|
|
train_lex = os.path.join(mnli_path, "multinli_1.0_train_lex.jsonl") |
|
matched_validation_lex = os.path.join(mnli_path, "multinli_1.0_dev_matched_lex.jsonl") |
|
mismatched_validation_lex = os.path.join(mnli_path, "multinli_1.0_dev_mismatched_lex.jsonl") |
|
|
|
|
|
return [ |
|
|
|
|
|
|
|
datasets.SplitGenerator(name="train_lex", gen_kwargs={"filepath": train_lex}), |
|
datasets.SplitGenerator(name="validation_matched_lex", gen_kwargs={"filepath": matched_validation_lex}), |
|
datasets.SplitGenerator(name="validation_mismatched_lex", gen_kwargs={"filepath": mismatched_validation_lex}), |
|
] |
|
|
|
def _generate_examples(self, filepath): |
|
"""Generate mnli examples""" |
|
|
|
with open(filepath, encoding="utf-8") as f: |
|
for id_, row in enumerate(f): |
|
data = json.loads(row) |
|
if data["gold_label"] == "-": |
|
continue |
|
yield id_, { |
|
"promptID": data["promptID"], |
|
"pairID": data["pairID"], |
|
"premise": data["sentence1"], |
|
"premise_binary_parse": data["sentence1_binary_parse"], |
|
"premise_parse": data["sentence1_parse"], |
|
"hypothesis": data["sentence2"], |
|
"hypothesis_binary_parse": data["sentence2_binary_parse"], |
|
"hypothesis_parse": data["sentence2_parse"], |
|
"genre": data["genre"], |
|
"label": data["gold_label"], |
|
} |
|
|