kasnerz commited on
Commit
b3b9cb3
1 Parent(s): b250f64

Upload _logicnlg.py

Browse files
Files changed (1) hide show
  1. _logicnlg.py +84 -0
_logicnlg.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+
3
+ """
4
+ The script used to load the dataset from the original source.
5
+ """
6
+
7
+ import json
8
+ import datasets
9
+ import glob
10
+ import os
11
+
12
+ _CITATION = """\
13
+ @inproceedings{chen2020logical,
14
+ title={Logical Natural Language Generation from Open-Domain Tables},
15
+ author={Chen, Wenhu and Chen, Jianshu and Su, Yu and Chen, Zhiyu and Wang, William Yang},
16
+ booktitle={Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics},
17
+ pages={7929--7942},
18
+ year={2020}
19
+ }
20
+ """
21
+ _DESCRIPTION = """\
22
+ LogicNLG is a dataset for natural language generation from open-domain tables.
23
+ LogicNLG is based on TabFact (Chen et al., 2019), which is a table-based fact-checking dataset with rich logical inferences in the annotated statements.
24
+ """
25
+
26
+ _URL = "https://github.com/wenhuchen/LogicNLG"
27
+ _LICENSE = "MIT"
28
+
29
+ class LogicNLG(datasets.GeneratorBasedBuilder):
30
+ VERSION = "1.0.0"
31
+ def _info(self):
32
+ return datasets.DatasetInfo(
33
+ description=_DESCRIPTION,
34
+ features=datasets.Features({
35
+ 'table': datasets.Value(dtype='large_string'),
36
+ "ref": datasets.Value(dtype='string'),
37
+ "linked_columns": datasets.Value(dtype='string'),
38
+ "title": datasets.Value(dtype='string'),
39
+ "template": datasets.Value(dtype='string'),
40
+ "table_id": datasets.Value(dtype='string'),
41
+ }),
42
+ supervised_keys=None,
43
+ homepage="https://wenhuchen.github.io/logicnlg.github.io/",
44
+ citation=_CITATION,
45
+ license=_LICENSE,
46
+ )
47
+
48
+ def _split_generators(self, dl_manager):
49
+ """Returns SplitGenerators."""
50
+ return [
51
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": "data", "split" : "train"}),
52
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": "data", "split" : "dev"}),
53
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": "data", "split" : "test"}),
54
+ ]
55
+
56
+ def _generate_examples(self, filepath, split):
57
+ filename = split if split != "dev" else "val"
58
+ data = []
59
+
60
+ with open(os.path.join(filepath, f"{filename}_lm.json")) as f:
61
+ j = json.load(f)
62
+
63
+ for i, (table_id, examples) in enumerate(j.items()):
64
+ table = []
65
+ with open(os.path.join(filepath, "all_csv", table_id)) as f:
66
+ for line in f.readlines():
67
+ table.append(line.rstrip("\n").split("#"))
68
+
69
+ for example in examples:
70
+ data.append({
71
+ "table": table,
72
+ "ref": example[0],
73
+ "linked_columns": example[1],
74
+ "title": example[2],
75
+ "template": example[3],
76
+ "table_id": table_id,
77
+ })
78
+ for example_idx, entry in enumerate(data):
79
+ yield example_idx, {key: str(value) for key, value in entry.items()}
80
+
81
+
82
+ if __name__ == '__main__':
83
+ dataset = datasets.load_dataset(__file__)
84
+ dataset.push_to_hub("kasnerz/logicnlg")