sileod commited on
Commit
89c050a
1 Parent(s): 02d799b

Create defeasible-nli.py

Browse files
Files changed (1) hide show
  1. defeasible-nli.py +60 -0
defeasible-nli.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datasets
2
+ import json
3
+ import os
4
+
5
+ citation='''
6
+ @inproceedings{rudinger-etal-2020-thinking,
7
+ title = "Thinking Like a Skeptic: Defeasible Inference in Natural Language",
8
+ author = "Rudinger, Rachel and
9
+ Shwartz, Vered and
10
+ Hwang, Jena D. and
11
+ Bhagavatula, Chandra and
12
+ Forbes, Maxwell and
13
+ Le Bras, Ronan and
14
+ Smith, Noah A. and
15
+ Choi, Yejin",
16
+ booktitle = "Findings of the Association for Computational Linguistics: EMNLP 2020",
17
+ month = nov,
18
+ year = "2020",
19
+ address = "Online",
20
+ publisher = "Association for Computational Linguistics",
21
+ url = "https://www.aclweb.org/anthology/2020.findings-emnlp.418",
22
+ doi = "10.18653/v1/2020.findings-emnlp.418",
23
+ pages = "4661--4675"
24
+ }
25
+ '''
26
+
27
+ class DefeasibleNLIConfig(datasets.BuilderConfig):
28
+ citation=citation
29
+
30
+ configs = ['atomic','snli','social']
31
+ splits=['train', 'test', 'dev']
32
+ _URLs = {(f,s):f"https://huggingface.co/datasets/metaeval/defeasible-nli/resolve/main/{f}_{s}.jsonl" for f in configs for s in splits}
33
+
34
+ class DefeasibleNLI(datasets.GeneratorBasedBuilder):
35
+
36
+ BUILDER_CONFIGS = [
37
+ DefeasibleNLIConfig(
38
+ name=n,
39
+ data_dir=n
40
+ ) for n in configs
41
+ ]
42
+
43
+ def _split_generators(self, dl_manager: datasets.DownloadManager):
44
+ path = lambda split: dl_manager.download(_URLs[self.config.name,split])
45
+ return [ datasets.SplitGenerator(name=name, gen_kwargs={'path':path(split),'split':split})
46
+ for name,split in zip([datasets.Split.TRAIN,datasets.Split.VALIDATION,datasets.Split.TEST],
47
+ ['train','dev','test'])]
48
+
49
+ def _info(self):
50
+ return datasets.DatasetInfo()
51
+
52
+ def _generate_examples(self,path,split):
53
+ """Yields examples."""
54
+ with open(path, "r", encoding="utf-8") as f:
55
+ for id_, line in enumerate(f):
56
+ line_dict = json.loads(line)
57
+ if not line_dict['UpdateTypeImpossible']:
58
+ fields = ["Premise","Hypothesis","Update","UpdateType"]#,"UpdateTypeImpossible","UpdateTypeImpossibleReason"]
59
+ line_dict = {k:v for k,v in line_dict.items() if k in fields}
60
+ yield id_, line_dict