Update markushgrapher-datasets.py
Browse files- markushgrapher-datasets.py +57 -20
markushgrapher-datasets.py
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
-
from datasets import DatasetInfo, GeneratorBasedBuilder, SplitGenerator, Split, BuilderConfig, Features, Value, Array2D, Array3D, Sequence, Image, DatasetDict
|
| 3 |
import datasets
|
| 4 |
|
| 5 |
class MarkushGrapherConfig(BuilderConfig):
|
|
@@ -16,23 +27,50 @@ class MarkushGrapherDataset(GeneratorBasedBuilder):
|
|
| 16 |
]
|
| 17 |
|
| 18 |
def _info(self):
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
def _split_generators(self, dl_manager):
|
| 38 |
data_dir = dl_manager.download_and_extract(self.config.name)
|
|
@@ -49,9 +87,8 @@ class MarkushGrapherDataset(GeneratorBasedBuilder):
|
|
| 49 |
return splits
|
| 50 |
|
| 51 |
def _generate_examples(self, data_dir):
|
| 52 |
-
# Automatically loads .arrow files
|
| 53 |
arrow_files = [os.path.join(data_dir, f) for f in os.listdir(data_dir) if f.endswith(".arrow")]
|
| 54 |
for file in arrow_files:
|
| 55 |
-
dataset =
|
| 56 |
for i, row in enumerate(dataset):
|
| 57 |
yield f"{file}_{i}", row
|
|
|
|
| 1 |
+
from datasets import (
|
| 2 |
+
DatasetInfo,
|
| 3 |
+
GeneratorBasedBuilder,
|
| 4 |
+
SplitGenerator,
|
| 5 |
+
Split,
|
| 6 |
+
BuilderConfig,
|
| 7 |
+
Features,
|
| 8 |
+
Value,
|
| 9 |
+
Sequence,
|
| 10 |
+
Image,
|
| 11 |
+
Dataset
|
| 12 |
+
)
|
| 13 |
import os
|
|
|
|
| 14 |
import datasets
|
| 15 |
|
| 16 |
class MarkushGrapherConfig(BuilderConfig):
|
|
|
|
| 27 |
]
|
| 28 |
|
| 29 |
def _info(self):
|
| 30 |
+
if self.config.name in ["m2s", "uspto-markush"]:
|
| 31 |
+
return DatasetInfo(
|
| 32 |
+
features=Features({
|
| 33 |
+
"id": Value("int64"),
|
| 34 |
+
"image_name": Value("string"),
|
| 35 |
+
"page_image": Image(decode=True),
|
| 36 |
+
"description": Value("string"),
|
| 37 |
+
"annotation": Value("string"),
|
| 38 |
+
"mol": Value("string"),
|
| 39 |
+
"cxsmiles_dataset": Value("string"),
|
| 40 |
+
"cxsmiles": Value("string"),
|
| 41 |
+
"cxsmiles_opt": Value("string"),
|
| 42 |
+
"keypoints": Value("null"),
|
| 43 |
+
"cells": Sequence({
|
| 44 |
+
"bbox": Sequence(Value("float64")),
|
| 45 |
+
"text": Value("string"),
|
| 46 |
+
}),
|
| 47 |
+
}),
|
| 48 |
+
supervised_keys=None,
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
elif self.config.name in ["markushgrapher-synthetic", "markushgrapher-synthetic-training"]:
|
| 52 |
+
return DatasetInfo(
|
| 53 |
+
features=Features({
|
| 54 |
+
"id": Value("int64"),
|
| 55 |
+
"page_image_path": Value("string"),
|
| 56 |
+
"description": Value("string"),
|
| 57 |
+
"annotation": Value("string"),
|
| 58 |
+
"mol": Value("string"),
|
| 59 |
+
"cxsmiles_dataset": Value("string"),
|
| 60 |
+
"cxsmiles": Value("string"),
|
| 61 |
+
"cxsmiles_opt": Value("string"),
|
| 62 |
+
"keypoints": Sequence(Sequence(Value("float64"))),
|
| 63 |
+
"cells": Sequence({
|
| 64 |
+
"bbox": Sequence(Value("float64")),
|
| 65 |
+
"text": Value("string"),
|
| 66 |
+
}),
|
| 67 |
+
"page_image": Image(decode=True),
|
| 68 |
+
}),
|
| 69 |
+
supervised_keys=None,
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
else:
|
| 73 |
+
raise ValueError(f"Unsupported config: {self.config.name}")
|
| 74 |
|
| 75 |
def _split_generators(self, dl_manager):
|
| 76 |
data_dir = dl_manager.download_and_extract(self.config.name)
|
|
|
|
| 87 |
return splits
|
| 88 |
|
| 89 |
def _generate_examples(self, data_dir):
|
|
|
|
| 90 |
arrow_files = [os.path.join(data_dir, f) for f in os.listdir(data_dir) if f.endswith(".arrow")]
|
| 91 |
for file in arrow_files:
|
| 92 |
+
dataset = Dataset.from_file(file)
|
| 93 |
for i, row in enumerate(dataset):
|
| 94 |
yield f"{file}_{i}", row
|