staghado commited on
Commit
d7e417e
1 Parent(s): 741ed71

Create arxiv_tables.py

Browse files
Files changed (1) hide show
  1. arxiv_tables.py +47 -0
arxiv_tables.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import datasets
3
+
4
+ class ArxivTables(datasets.GeneratorBasedBuilder):
5
+ VERSION = datasets.Version("1.0.0")
6
+
7
+ def _info(self):
8
+ return datasets.DatasetInfo(
9
+ description="Arxiv-tables Dataset",
10
+ features=datasets.Features({
11
+ "id": datasets.Value("int32"),
12
+ "page": datasets.Value("int32"),
13
+ "bounding_box": datasets.Sequence(datasets.Value("float32"), length=4),
14
+ "latex_content": datasets.Value("string"),
15
+ "extracted_content": datasets.Value("string"),
16
+ "similarity_score": datasets.Value("float32"),
17
+ "table_image": datasets.Image(),
18
+ "page_image": datasets.Image(),
19
+ }),
20
+ )
21
+
22
+ def _split_generators(self, dl_manager):
23
+ return [
24
+ datasets.SplitGenerator(
25
+ name=datasets.Split.TRAIN,
26
+ gen_kwargs={"path": "arxiv_tables"},
27
+ ),
28
+ ]
29
+
30
+ def _generate_examples(self, path):
31
+ for arxiv_id in os.listdir(path):
32
+ arxiv_path = os.path.join(path, arxiv_id)
33
+ for table_dir in os.listdir(arxiv_path):
34
+ table_path = os.path.join(arxiv_path, table_dir)
35
+ with open(os.path.join(table_path, "metadata.json"), "r") as f:
36
+ metadata = json.load(f)
37
+
38
+ yield metadata["id"], {
39
+ "id": metadata["id"],
40
+ "page": metadata["page"],
41
+ "bounding_box": metadata["bounding_box"],
42
+ "latex_content": metadata["latex_content"],
43
+ "extracted_content": metadata["extracted_content"],
44
+ "similarity_score": metadata["similarity_score"],
45
+ "table_image": os.path.join(table_path, "table_image.png"),
46
+ "page_image": os.path.join(table_path, "page_image.png"),
47
+ }