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