kasnerz commited on
Commit
e21130a
·
1 Parent(s): a5e9506

Upload _wikitabletext.py

Browse files
Files changed (1) hide show
  1. _wikitabletext.py +85 -0
_wikitabletext.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+
3
+ """
4
+ The script used to load the dataset from the original source.
5
+ """
6
+
7
+
8
+ import os
9
+ from collections import defaultdict
10
+
11
+ import json
12
+ import datasets
13
+
14
+ _CITATION = """\
15
+ @inproceedings{bao2018table,
16
+ title={Table-to-Text: Describing Table Region with Natural Language},
17
+ author={Junwei Bao and Duyu Tang and Nan Duan and Zhao Yan and Yuanhua Lv and Ming Zhou and Tiejun Zhao},
18
+ booktitle={AAAI},
19
+ url={https://www.aaai.org/ocs/index.php/AAAI/AAAI18/paper/download/16138/16782},
20
+ year={2018}
21
+ }
22
+ """
23
+
24
+ _DESCRIPTION = """\
25
+ WikiTableText contains 5,000 tables from Wikipedia, each of which has at least 3 rows and 2 columns.
26
+ For each table, three rows are selected resulting in 15,000 rows that are further used for manual annotation."""
27
+
28
+ _URL = "https://github.com/msra-nlc/Table2Text"
29
+ _LICENSE = "CC BY 4.0"
30
+
31
+ class WikiTableText(datasets.GeneratorBasedBuilder):
32
+ VERSION = datasets.Version("1.0.0")
33
+
34
+ def _info(self):
35
+ return datasets.DatasetInfo(
36
+ description=_DESCRIPTION,
37
+ features=datasets.Features({
38
+ "headers": datasets.Value("string"),
39
+ "content": datasets.Value("string"),
40
+ "row_number": datasets.Value("string"),
41
+ "reference": datasets.Value("string"),
42
+ }),
43
+ supervised_keys=None,
44
+ homepage=_URL,
45
+ citation=_CITATION,
46
+ license=_LICENSE,
47
+ )
48
+
49
+ def _split_generators(self, dl_manager):
50
+ """Returns SplitGenerators."""
51
+ return [
52
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"split" : "train"}),
53
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"split" : "dev"}),
54
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"split" : "test"}),
55
+ ]
56
+
57
+ def _normalize(self, lst):
58
+ lst = lst.split("_||_")
59
+ lst = [x.replace("_$$_", " ") for x in lst]
60
+ lst = [x.replace("_", "").strip() for x in lst]
61
+
62
+ return lst
63
+
64
+ def _generate_examples(self, split):
65
+ """Yields examples."""
66
+ id_ = 0
67
+
68
+ with open(f"MSRA_NLC.Table2Text.{split}") as f:
69
+ for line in f.readlines():
70
+ items = line.split("\t")
71
+ e = {
72
+ "row_number" : items[0],
73
+ "headers" : self._normalize(items[1]),
74
+ "content" : self._normalize(items[2]),
75
+ "reference" : self._normalize(items[3])[0],
76
+ }
77
+
78
+ id_ += 1
79
+ yield id_, e
80
+
81
+
82
+
83
+ if __name__ == '__main__':
84
+ dataset = datasets.load_dataset(__file__)
85
+ dataset.push_to_hub("kasnerz/wikitabletext")