Create hitab.py
Browse files
hitab.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""HiTab : A Hierarchical Table Dataset for Question Answering and Natural Language Generation"""
|
| 2 |
+
|
| 3 |
+
import json
|
| 4 |
+
import datasets
|
| 5 |
+
|
| 6 |
+
_CITATION = """\
|
| 7 |
+
@article{cheng2021hitab,
|
| 8 |
+
title={HiTab: A Hierarchical Table Dataset for Question Answering and Natural Language Generation},
|
| 9 |
+
author={Cheng, Zhoujun and Dong, Haoyu and Wang, Zhiruo and Jia, Ran and Guo, Jiaqi and Gao, Yan and Han, Shi and Lou, Jian-Guang and Zhang, Dongmei},
|
| 10 |
+
journal={arXiv preprint arXiv:2108.06712},
|
| 11 |
+
year={2021}
|
| 12 |
+
}
|
| 13 |
+
"""
|
| 14 |
+
_DESCRIPTION = """\
|
| 15 |
+
HiTab is a dataset for question answering and data-to-text over hierarchical tables . It contains 10,672 samples and 3,597 tables from statistical reports (StatCan, NSF) and Wikipedia (ToTTo). 98.1% of the tables in HiTab are with hierarchies.
|
| 16 |
+
"""
|
| 17 |
+
|
| 18 |
+
_URL = "https://github.com/microsoft/HiTab"
|
| 19 |
+
|
| 20 |
+
class HiTab(datasets.GeneratorBasedBuilder):
|
| 21 |
+
def _info(self):
|
| 22 |
+
return datasets.DatasetInfo(
|
| 23 |
+
description=_DESCRIPTION,
|
| 24 |
+
supervised_keys=None,
|
| 25 |
+
homepage="https://www.microsoft.com/en-us/research/publication/hitab-a-hierarchical-table-dataset-for-question-answering-and-natural-language-generation/",
|
| 26 |
+
citation=_CITATION,
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
def _split_generators(self, dl_manager):
|
| 30 |
+
"""Returns SplitGenerators."""
|
| 31 |
+
return [
|
| 32 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": "./train.jsonl"}),
|
| 33 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": "./dev.jsonl"}),
|
| 34 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": "./test.jsonl"}),
|
| 35 |
+
]
|
| 36 |
+
|
| 37 |
+
def _generate_examples(self, filepath):
|
| 38 |
+
with open(filepath, encoding="utf-8") as f:
|
| 39 |
+
for line in f.readlines():
|
| 40 |
+
j = json.loads(line)
|
| 41 |
+
yield example_idx, j
|