Upload _numericnlg.py
Browse files- _numericnlg.py +88 -0
_numericnlg.py
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
|
3 |
+
"""
|
4 |
+
The script used to load the dataset from the original source.
|
5 |
+
"""
|
6 |
+
|
7 |
+
|
8 |
+
import json
|
9 |
+
import datasets
|
10 |
+
import glob
|
11 |
+
import os
|
12 |
+
|
13 |
+
_CITATION = """\
|
14 |
+
@inproceedings{suadaa-etal-2021-towards,
|
15 |
+
title = "Towards Table-to-Text Generation with Numerical Reasoning",
|
16 |
+
author = "Suadaa, Lya Hulliyyatus and
|
17 |
+
Kamigaito, Hidetaka and
|
18 |
+
Funakoshi, Kotaro and
|
19 |
+
Okumura, Manabu and
|
20 |
+
Takamura, Hiroya",
|
21 |
+
booktitle = "Proceedings of the 59th Annual Meeting of the Association for Computational Linguistics and the 11th International Joint Conference on Natural Language Processing (Volume 1: Long Papers)",
|
22 |
+
month = aug,
|
23 |
+
year = "2021",
|
24 |
+
address = "Online",
|
25 |
+
publisher = "Association for Computational Linguistics",
|
26 |
+
url = "https://aclanthology.org/2021.acl-long.115",
|
27 |
+
doi = "10.18653/v1/2021.acl-long.115",
|
28 |
+
pages = "1451--1465"
|
29 |
+
}
|
30 |
+
"""
|
31 |
+
_DESCRIPTION = """\
|
32 |
+
NumericNLG is a dataset for table-totext generation focusing on numerical reasoning.
|
33 |
+
The dataset consists of textual descriptions of numerical tables from scientific papers.
|
34 |
+
"""
|
35 |
+
|
36 |
+
_URL = "https://github.com/titech-nlp/numeric-nlg"
|
37 |
+
_LICENSE = "CC BY-SA 4.0"
|
38 |
+
|
39 |
+
class NumericNLG(datasets.GeneratorBasedBuilder):
|
40 |
+
VERSION = "1.0.0"
|
41 |
+
def _info(self):
|
42 |
+
return datasets.DatasetInfo(
|
43 |
+
description=_DESCRIPTION,
|
44 |
+
features=datasets.Features({
|
45 |
+
"table_id_paper": datasets.Value(dtype='string'),
|
46 |
+
"caption": datasets.Value(dtype='string'),
|
47 |
+
"row_header_level" : datasets.Value(dtype='int32'),
|
48 |
+
"row_headers" : datasets.Value(dtype='large_string'),
|
49 |
+
"column_header_level": datasets.Value(dtype='int32'),
|
50 |
+
"column_headers" : datasets.Value(dtype='large_string'),
|
51 |
+
"contents" : datasets.Value(dtype='large_string'),
|
52 |
+
"metrics_loc" : datasets.Value(dtype='string'),
|
53 |
+
"metrics_type" : datasets.Value(dtype='large_string'),
|
54 |
+
"target_entity": datasets.Value(dtype='large_string'),
|
55 |
+
"table_html_clean": datasets.Value(dtype='large_string'),
|
56 |
+
"table_name": datasets.Value(dtype='string'),
|
57 |
+
"table_id": datasets.Value(dtype='string'),
|
58 |
+
"paper_id": datasets.Value(dtype='string'),
|
59 |
+
"page_no": datasets.Value(dtype='int32'),
|
60 |
+
"dir": datasets.Value(dtype='string'),
|
61 |
+
"valid": datasets.Value(dtype='int32'),
|
62 |
+
}),
|
63 |
+
supervised_keys=None,
|
64 |
+
homepage="https://github.com/titech-nlp/numeric-nlg",
|
65 |
+
citation=_CITATION,
|
66 |
+
license=_LICENSE,
|
67 |
+
)
|
68 |
+
|
69 |
+
def _split_generators(self, dl_manager):
|
70 |
+
"""Returns SplitGenerators."""
|
71 |
+
return [
|
72 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": "data", "split" : "train"}),
|
73 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": "data", "split" : "dev"}),
|
74 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": "data", "split" : "test"}),
|
75 |
+
]
|
76 |
+
|
77 |
+
def _generate_examples(self, filepath, split):
|
78 |
+
filename = split if split != "dev" else "val"
|
79 |
+
|
80 |
+
with open(os.path.join(filepath, f"table_{filename}.json")) as f:
|
81 |
+
j = json.load(f)
|
82 |
+
|
83 |
+
for example_idx, entry in enumerate(j):
|
84 |
+
yield example_idx, {key: str(value) for key, value in entry.items()}
|
85 |
+
|
86 |
+
if __name__ == '__main__':
|
87 |
+
dataset = datasets.load_dataset(__file__)
|
88 |
+
dataset.push_to_hub("kasnerz/numericnlg")
|