|
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"), |
|
} |