blnewman-uw commited on
Commit
52e72e5
1 Parent(s): 44d0d19

Added custom data loader and added arxiv ids to data

Browse files
Files changed (3) hide show
  1. arxivDIGESTables.py +198 -0
  2. tables.jsonl +2 -2
  3. tables_medium_quality.jsonl +2 -2
arxivDIGESTables.py ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # TODO: Address all TODOs and remove all explanatory comments
15
+ """TODO: Add a description here."""
16
+
17
+
18
+ import csv
19
+ import json
20
+ import os
21
+ from typing import List, Dict
22
+
23
+ import datasets
24
+
25
+
26
+ # TODO: Add BibTeX citation
27
+ # Find for instance the citation on arxiv or on the dataset repo/website
28
+ _CITATION = """\
29
+ @InProceedings{huggingface:dataset,
30
+ title = {A great new dataset},
31
+ author={huggingface, Inc.
32
+ },
33
+ year={2020}
34
+ }
35
+ """
36
+
37
+ # TODO: Add description of the dataset here
38
+ # You can copy an official description
39
+ _DESCRIPTION = """\
40
+ ArxivDIGESTables: A dataset of tables from ArXiv papers along with captions, in-text references and associated full-texts."""
41
+
42
+ # TODO: Add a link to an official homepage for the dataset here
43
+ _HOMEPAGE = "https://github.com/bnewm0609/arxivDIGESTables"
44
+
45
+ # TODO: Add the licence for the dataset here if you can find it
46
+ _LICENSE = ""
47
+
48
+ # TODO: Add link to the official dataset URLs here
49
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
50
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
51
+ _URLS = {
52
+ "high_quality": "/Users/blnewman/Documents/research/projects/paper_comparison/arxivDIGESTables_hf_data/tables.jsonl", # "https://huggingface.co/datasets/blnewman/arxivDIGESTables/resolve/main/tables.jsonl",
53
+ "medium_quality": "/Users/blnewman/Documents/research/projects/paper_comparison/arxivDIGESTables_hf_data/tables_medium_quality.jsonl", # "https://huggingface.co/datasets/blnewman/arxivDIGESTables/resolve/main/tables_medium_quality.jsonl",
54
+ }
55
+
56
+
57
+ # TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
58
+ class ArxivDIGESTables(datasets.GeneratorBasedBuilder):
59
+ """TODO: Short description of my dataset."""
60
+
61
+ VERSION = datasets.Version("1.1.0")
62
+
63
+ # This is an example of a dataset with multiple configurations.
64
+ # If you don't want/need to define several sub-sets in your dataset,
65
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
66
+
67
+ # If you need to make complex sub-parts in the datasets with configurable options
68
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
69
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
70
+
71
+ # You will be able to load one or the other configurations in the following list with
72
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
73
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
74
+ BUILDER_CONFIGS = [
75
+ datasets.BuilderConfig(name="high_quality", version=VERSION, description="High quality, manually corrected tables."),
76
+ datasets.BuilderConfig(name="medium_quality", version=VERSION, description="Medium quality tables."),
77
+ ]
78
+
79
+ DEFAULT_CONFIG_NAME = "high_quality" # It's not mandatory to have a default configuration. Just use one if it make sense.
80
+
81
+ def _info(self):
82
+ # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
83
+ if self.config.name == "high_quality": # This is the name of the configuration selected in BUILDER_CONFIGS above
84
+ features = datasets.Features(
85
+ {
86
+ "tabid": datasets.Value("string"),
87
+ "table": datasets.Value("string"),
88
+ "row_bib_map": [{
89
+ "bib_hash_or_arxiv_id": datasets.Value("string"),
90
+ "row": datasets.Value("int64"),
91
+ "corpus_id": datasets.Value("int64"),
92
+ "type": datasets.Value("string"),
93
+ "title": datasets.Value("string"),
94
+ "abstract": datasets.Value("string"),
95
+ }],
96
+ "caption": datasets.Value("string"),
97
+ "in_text_ref": [{
98
+ "section": datasets.Value("string"),
99
+ "sec_number": datasets.Value("string"),
100
+ "sec_type": datasets.Value("string"),
101
+ "content_type": datasets.Value("string"),
102
+ "text": datasets.Value("string"),
103
+ "cite_spans": [{
104
+ "start": datasets.Value("int64"),
105
+ "end": datasets.Value("int64"),
106
+ "text": datasets.Value("string"),
107
+ "ref_id": datasets.Value("string"),
108
+ }],
109
+ "ref_spans": [{
110
+ "start": datasets.Value("int64"),
111
+ "end": datasets.Value("int64"),
112
+ "text": datasets.Value("string"),
113
+ "ref_id": datasets.Value("string"),
114
+ }],
115
+ }],
116
+ "arxiv_id": datasets.Value("string"),
117
+ # These are the features of your dataset like images, labels ...
118
+ }
119
+ )
120
+ else: # This is an example to show how to have different features for "first_domain" and "second_domain"
121
+ features = datasets.Features(
122
+ {
123
+ "tabid": datasets.Value("string"),
124
+ "table": datasets.Value("string"),
125
+ "row_bib_map": [{
126
+ "bib_hash_or_arxiv_id": datasets.Value("string"),
127
+ "row": datasets.Value("int64"),
128
+ "corpus_id": datasets.Value("int64"),
129
+ "type": datasets.Value("string"),
130
+ "title": datasets.Value("string"),
131
+ "abstract": datasets.Value("string"),
132
+ }],
133
+ "arxiv_id": datasets.Value("string"),
134
+ # These are the features of your dataset like images, labels ...
135
+ }
136
+ )
137
+ return datasets.DatasetInfo(
138
+ # This is the description that will appear on the datasets page.
139
+ description=_DESCRIPTION,
140
+ # This defines the different columns of the dataset and their types
141
+ features=features, # Here we define them above because they are different between the two configurations
142
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
143
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
144
+ # supervised_keys=("sentence", "label"),
145
+ # Homepage of the dataset for documentation
146
+ homepage=_HOMEPAGE,
147
+ # License for the dataset if available
148
+ license=_LICENSE,
149
+ # Citation for the dataset
150
+ citation=_CITATION,
151
+ )
152
+
153
+ def _split_generators(self, dl_manager):
154
+ print("hi", flush=True)
155
+ # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
156
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
157
+
158
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
159
+ # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
160
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
161
+ urls = _URLS[self.config.name]
162
+ # data_path = dl_manager.download_and_extract(urls)
163
+ print(urls)
164
+ data_path = urls
165
+ return [
166
+ datasets.SplitGenerator(
167
+ name=datasets.Split.VALIDATION,
168
+ # These kwargs will be passed to _generate_examples
169
+ gen_kwargs={
170
+ "filepath": data_path,
171
+ "split": "dev",
172
+ },
173
+ ),
174
+ ]
175
+
176
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
177
+ def _generate_examples(self, filepath, split):
178
+ # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
179
+ # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
180
+ with open(filepath, encoding="utf-8") as f:
181
+ for key, row in enumerate(f):
182
+ data = json.loads(row)
183
+ data["table"] = json.dumps(data["table"])
184
+ # print(data.k)
185
+ yield key, data
186
+ # if self.config.name == "first_domain":
187
+ # # Yields examples as (key, example) tuples
188
+ # yield key, {
189
+ # "sentence": data["sentence"],
190
+ # "option1": data["option1"],
191
+ # "answer": "" if split == "test" else data["answer"],
192
+ # }
193
+ # else:
194
+ # yield key, {
195
+ # "sentence": data["sentence"],
196
+ # "option2": data["option2"],
197
+ # "second_domain_answer": "" if split == "test" else data["second_domain_answer"],
198
+ # }
tables.jsonl CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:2b1d5debd14a8de6df3d43d3b6d60bac30c57395db7592b3371fa0dda7be554b
3
- size 26098654
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:90a80e645e3050041e635c188ac64c666a6debc533fb8bcc6b041dc3045f18d1
3
+ size 26161029
tables_medium_quality.jsonl CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:94e90635af89ab03af528d6de69ae7d13baf720ec2e6c20423141a9b1c18f855
3
- size 252909684
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c282060e6403027f4e3491adc6564172007c54cc94d9436e16b1813ca60a699f
3
+ size 253533544