kasnerz commited on
Commit
1a6b880
·
1 Parent(s): 002c13d

Upload _scigen.py

Browse files
Files changed (1) hide show
  1. _scigen.py +67 -0
_scigen.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Scigen: dataset for reasoning-aware data-to-text generation from scientific tables"""
2
+
3
+ import json
4
+ import datasets
5
+ import glob
6
+ import os
7
+
8
+ _CITATION = """\
9
+ @article{moosavi:2021:SciGen,
10
+ author = {Nafise Sadat Moosavi, Andreas R{\"u}ckl{\'e}, Dan Roth, Iryna Gurevych},
11
+ title = {Learning to Reason for Text Generation from Scientific Tables},
12
+ journal = {arXiv preprint arXiv:2104.08296},
13
+ year = {2021},
14
+ url = {https://arxiv.org/abs/2104.08296}
15
+ }
16
+ """
17
+ _DESCRIPTION = """\
18
+ SciGen is dataset for the task of reasoning-aware data-to-text generation consisting of tables from scientific articles and their corresponding descriptions.
19
+ """
20
+
21
+ _URL = "https://github.com/UKPLab/SciGen"
22
+ _LICENSE = "CC BY-NC-SA 4.0"
23
+
24
+ class SciGen(datasets.GeneratorBasedBuilder):
25
+ VERSION = "1.0.0"
26
+ def _info(self):
27
+ return datasets.DatasetInfo(
28
+ description=_DESCRIPTION,
29
+ features=datasets.Features({
30
+ 'paper': datasets.Value(dtype='string'),
31
+ 'paper_id': datasets.Value(dtype='string'),
32
+ 'table_caption': datasets.Value(dtype='string'),
33
+ 'table_column_names': datasets.Value(dtype='large_string'),
34
+ 'table_content_values': datasets.Value(dtype='large_string'),
35
+ 'text' : datasets.Value(dtype='large_string'),
36
+ }),
37
+ supervised_keys=None,
38
+ homepage=_URL,
39
+ citation=_CITATION,
40
+ license=_LICENSE
41
+ )
42
+
43
+ def _split_generators(self, dl_manager):
44
+ """Returns SplitGenerators."""
45
+ return [
46
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": "dataset", "split" : "train"}),
47
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": "dataset", "split" : "dev"}),
48
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": "dataset", "split" : "test"}),
49
+ ]
50
+
51
+ def _generate_examples(self, filepath, split):
52
+ data_dir = "development" if split == "dev" else split
53
+
54
+ if split in ["train", "dev"]:
55
+ file_path = os.path.join(filepath, data_dir, "medium", f"{split}.json")
56
+ else:
57
+ # there is also "test-Other.json", should be looked into
58
+ file_path = os.path.join(filepath, data_dir, f"test-CL.json")
59
+
60
+ with open(file_path) as f:
61
+ j = json.load(f)
62
+ for example_idx, entry in enumerate(list(j.values())):
63
+ yield example_idx, {key: str(value) for key, value in entry.items()}
64
+
65
+ if __name__ == '__main__':
66
+ dataset = datasets.load_dataset(__file__)
67
+ dataset.push_to_hub("kasnerz/scigen")