defeasible-nli / defeasible-nli.py
sileod's picture
Create defeasible-nli.py
89c050a
raw
history blame
2.32 kB
import datasets
import json
import os
citation='''
@inproceedings{rudinger-etal-2020-thinking,
title = "Thinking Like a Skeptic: Defeasible Inference in Natural Language",
author = "Rudinger, Rachel and
Shwartz, Vered and
Hwang, Jena D. and
Bhagavatula, Chandra and
Forbes, Maxwell and
Le Bras, Ronan and
Smith, Noah A. and
Choi, Yejin",
booktitle = "Findings of the Association for Computational Linguistics: EMNLP 2020",
month = nov,
year = "2020",
address = "Online",
publisher = "Association for Computational Linguistics",
url = "https://www.aclweb.org/anthology/2020.findings-emnlp.418",
doi = "10.18653/v1/2020.findings-emnlp.418",
pages = "4661--4675"
}
'''
class DefeasibleNLIConfig(datasets.BuilderConfig):
citation=citation
configs = ['atomic','snli','social']
splits=['train', 'test', 'dev']
_URLs = {(f,s):f"https://huggingface.co/datasets/metaeval/defeasible-nli/resolve/main/{f}_{s}.jsonl" for f in configs for s in splits}
class DefeasibleNLI(datasets.GeneratorBasedBuilder):
BUILDER_CONFIGS = [
DefeasibleNLIConfig(
name=n,
data_dir=n
) for n in configs
]
def _split_generators(self, dl_manager: datasets.DownloadManager):
path = lambda split: dl_manager.download(_URLs[self.config.name,split])
return [ datasets.SplitGenerator(name=name, gen_kwargs={'path':path(split),'split':split})
for name,split in zip([datasets.Split.TRAIN,datasets.Split.VALIDATION,datasets.Split.TEST],
['train','dev','test'])]
def _info(self):
return datasets.DatasetInfo()
def _generate_examples(self,path,split):
"""Yields examples."""
with open(path, "r", encoding="utf-8") as f:
for id_, line in enumerate(f):
line_dict = json.loads(line)
if not line_dict['UpdateTypeImpossible']:
fields = ["Premise","Hypothesis","Update","UpdateType"]#,"UpdateTypeImpossible","UpdateTypeImpossibleReason"]
line_dict = {k:v for k,v in line_dict.items() if k in fields}
yield id_, line_dict