maxkordn commited on
Commit
b70d64d
·
verified ·
1 Parent(s): 20a01e1

Delete loading script

Browse files
Files changed (1) hide show
  1. wikitablequestions.py +0 -184
wikitablequestions.py DELETED
@@ -1,184 +0,0 @@
1
- # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- """The WikiTableQuestions dataset is a large-scale dataset for the task of question answering on semi-structured tables."""
15
-
16
- import os
17
-
18
- import datasets
19
-
20
-
21
- # Find for instance the citation on arxiv or on the dataset repo/website
22
- _CITATION = """\
23
- @inproceedings{pasupat-liang-2015-compositional,
24
- title = "Compositional Semantic Parsing on Semi-Structured Tables",
25
- author = "Pasupat, Panupong and Liang, Percy",
26
- booktitle = "Proceedings of the 53rd Annual Meeting of the Association for Computational Linguistics and the 7th International Joint Conference on Natural Language Processing (Volume 1: Long Papers)",
27
- month = jul,
28
- year = "2015",
29
- address = "Beijing, China",
30
- publisher = "Association for Computational Linguistics",
31
- url = "https://aclanthology.org/P15-1142",
32
- doi = "10.3115/v1/P15-1142",
33
- pages = "1470--1480",
34
- }
35
- """
36
-
37
- # You can copy an official description
38
- _DESCRIPTION = """\
39
- This WikiTableQuestions dataset is a large-scale dataset for the task of question answering on semi-structured tables.
40
- """
41
-
42
- _HOMEPAGE = "https://nlp.stanford.edu/software/sempre/wikitable"
43
-
44
- _LICENSE = "Creative Commons Attribution Share Alike 4.0 International"
45
-
46
- # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
47
- # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
48
- _DATA_URL = (
49
- "https://github.com/ppasupat/WikiTableQuestions/releases/download/v1.0.2/WikiTableQuestions-1.0.2-compact.zip"
50
- )
51
-
52
-
53
- class WikiTableQuestions(datasets.GeneratorBasedBuilder):
54
- """WikiTableQuestions: a large-scale dataset for the task of question answering on semi-structured tables."""
55
-
56
- VERSION = datasets.Version("1.0.2")
57
-
58
- # This is an example of a dataset with multiple configurations.
59
- # If you don't want/need to define several sub-sets in your dataset,
60
- # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
61
-
62
- # If you need to make complex sub-parts in the datasets with configurable options
63
- # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
64
- # BUILDER_CONFIG_CLASS = MyBuilderConfig
65
-
66
- # You will be able to load one or the other configurations in the following list with
67
- # data = datasets.load_dataset('my_dataset', 'first_domain')
68
- # data = datasets.load_dataset('my_dataset', 'second_domain')
69
- BUILDER_CONFIGS = [
70
- datasets.BuilderConfig(
71
- name="random-split-1",
72
- version=VERSION,
73
- description="The random-split-1-train/dev.tsv and pristine-unseen-tables.tsv",
74
- ),
75
- datasets.BuilderConfig(
76
- name="random-split-2",
77
- version=VERSION,
78
- description="The random-split-2-train/dev.tsv and pristine-unseen-tables.tsv",
79
- ),
80
- datasets.BuilderConfig(
81
- name="random-split-3",
82
- version=VERSION,
83
- description="The random-split-3-train/dev.tsv and pristine-unseen-tables.tsv",
84
- ),
85
- datasets.BuilderConfig(
86
- name="random-split-4",
87
- version=VERSION,
88
- description="The random-split-4-train/dev.tsv and pristine-unseen-tables.tsv",
89
- ),
90
- datasets.BuilderConfig(
91
- name="random-split-5",
92
- version=VERSION,
93
- description="The random-split-5-train/dev.tsv and pristine-unseen-tables.tsv",
94
- ),
95
- ]
96
-
97
- DEFAULT_CONFIG_NAME = (
98
- "random-split-1" # It's not mandatory to have a default configuration. Just use one if it make sense.
99
- )
100
-
101
- def _info(self):
102
- features = datasets.Features(
103
- {
104
- "id": datasets.Value("string"),
105
- "question": datasets.Value("string"),
106
- "answers": datasets.features.Sequence(datasets.Value("string")),
107
- "table": {
108
- "header": datasets.features.Sequence(datasets.Value("string")),
109
- "rows": datasets.features.Sequence(datasets.features.Sequence(datasets.Value("string"))),
110
- "name": datasets.Value("string"),
111
- },
112
- }
113
- )
114
- return datasets.DatasetInfo(
115
- # This is the description that will appear on the datasets page.
116
- description=_DESCRIPTION,
117
- # This defines the different columns of the dataset and their types
118
- features=features, # Here we define them above because they are different between the two configurations
119
- # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
120
- # specify them. They'll be used if as_supervised=True in builder.as_dataset.
121
- # supervised_keys=("sentence", "label"),
122
- # Homepage of the dataset for documentation
123
- homepage=_HOMEPAGE,
124
- # License for the dataset if available
125
- license=_LICENSE,
126
- # Citation for the dataset
127
- citation=_CITATION,
128
- )
129
-
130
- def _split_generators(self, dl_manager):
131
- train_file = "{}-train.tsv".format(self.config.name)
132
- dev_file = "{}-dev.tsv".format(self.config.name)
133
- test_file = "pristine-unseen-tables.tsv"
134
- # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
135
- urls = _DATA_URL
136
- root_dir = os.path.join(dl_manager.download_and_extract(urls), "WikiTableQuestions")
137
- return [
138
- datasets.SplitGenerator(
139
- name=datasets.Split.TRAIN,
140
- # These kwargs will be passed to _generate_examples
141
- gen_kwargs={"main_filepath": os.path.join(root_dir, "data", train_file), "root_dir": root_dir},
142
- ),
143
- datasets.SplitGenerator(
144
- name=datasets.Split.TEST,
145
- # These kwargs will be passed to _generate_examples
146
- gen_kwargs={"main_filepath": os.path.join(root_dir, "data", test_file), "root_dir": root_dir},
147
- ),
148
- datasets.SplitGenerator(
149
- name=datasets.Split.VALIDATION,
150
- # These kwargs will be passed to _generate_examples
151
- gen_kwargs={"main_filepath": os.path.join(root_dir, "data", dev_file), "root_dir": root_dir},
152
- ),
153
- ]
154
-
155
- def _read_table_from_file(self, table_name: str, root_dir: str):
156
- def _extract_table_content(_line: str):
157
- _vals = [_.replace("\n", " ").strip() for _ in _line.strip("\n").split("\t")]
158
- return _vals
159
-
160
- rows = []
161
- # assert ".csv" in _wtq_table_name
162
- # use the normalized table file
163
- table_name = table_name.replace(".csv", ".tsv")
164
- with open(os.path.join(root_dir, table_name), "r", encoding="utf8") as table_f:
165
- table_lines = table_f.readlines()
166
- # the first line is header
167
- header = _extract_table_content(table_lines[0])
168
- for line in table_lines[1:]:
169
- rows.append(_extract_table_content(line))
170
- return {"header": header, "rows": rows, "name": table_name}
171
-
172
- # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
173
- def _generate_examples(self, main_filepath, root_dir):
174
- # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
175
- with open(main_filepath, encoding="utf-8") as f:
176
- # skip the first line since it is the tsv header
177
- next(f)
178
- for idx, line in enumerate(f):
179
- example_id, question, table_name, answer = line.strip("\n").split("\t")
180
- answer = answer.split("|")
181
- # must contain rows and header keys
182
- table_content = self._read_table_from_file(table_name, root_dir)
183
-
184
- yield idx, {"id": example_id, "question": question, "answers": answer, "table": table_content}