Update markushgrapher-datasets.py
Browse files- markushgrapher-datasets.py +14 -18
markushgrapher-datasets.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
from datasets import (
|
| 2 |
DatasetInfo,
|
| 3 |
GeneratorBasedBuilder,
|
|
@@ -10,9 +11,9 @@ from datasets import (
|
|
| 10 |
Image,
|
| 11 |
Dataset
|
| 12 |
)
|
| 13 |
-
import os
|
| 14 |
import datasets
|
| 15 |
|
|
|
|
| 16 |
class MarkushGrapherConfig(BuilderConfig):
|
| 17 |
def __init__(self, **kwargs):
|
| 18 |
super().__init__(**kwargs)
|
|
@@ -20,10 +21,10 @@ class MarkushGrapherConfig(BuilderConfig):
|
|
| 20 |
|
| 21 |
class MarkushGrapherDataset(GeneratorBasedBuilder):
|
| 22 |
BUILDER_CONFIGS = [
|
| 23 |
-
MarkushGrapherConfig(name="
|
| 24 |
-
MarkushGrapherConfig(name="
|
| 25 |
-
MarkushGrapherConfig(name="markushgrapher-synthetic", description="Synthetic
|
| 26 |
-
MarkushGrapherConfig(name="
|
| 27 |
]
|
| 28 |
|
| 29 |
def _info(self):
|
|
@@ -45,7 +46,6 @@ class MarkushGrapherDataset(GeneratorBasedBuilder):
|
|
| 45 |
"text": Value("string"),
|
| 46 |
}),
|
| 47 |
}),
|
| 48 |
-
supervised_keys=None,
|
| 49 |
)
|
| 50 |
|
| 51 |
elif self.config.name in ["markushgrapher-synthetic", "markushgrapher-synthetic-training"]:
|
|
@@ -66,15 +66,14 @@ class MarkushGrapherDataset(GeneratorBasedBuilder):
|
|
| 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 |
-
|
| 77 |
-
config_path =
|
| 78 |
|
| 79 |
splits = []
|
| 80 |
for split in ["train", "test"]:
|
|
@@ -88,13 +87,10 @@ class MarkushGrapherDataset(GeneratorBasedBuilder):
|
|
| 88 |
return splits
|
| 89 |
|
| 90 |
def _generate_examples(self, data_dir):
|
| 91 |
-
arrow_files = []
|
| 92 |
for root, _, files in os.walk(data_dir):
|
| 93 |
-
for
|
| 94 |
-
if
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
for i, row in enumerate(dataset):
|
| 100 |
-
yield f"{file}_{i}", row
|
|
|
|
| 1 |
+
import os
|
| 2 |
from datasets import (
|
| 3 |
DatasetInfo,
|
| 4 |
GeneratorBasedBuilder,
|
|
|
|
| 11 |
Image,
|
| 12 |
Dataset
|
| 13 |
)
|
|
|
|
| 14 |
import datasets
|
| 15 |
|
| 16 |
+
|
| 17 |
class MarkushGrapherConfig(BuilderConfig):
|
| 18 |
def __init__(self, **kwargs):
|
| 19 |
super().__init__(**kwargs)
|
|
|
|
| 21 |
|
| 22 |
class MarkushGrapherDataset(GeneratorBasedBuilder):
|
| 23 |
BUILDER_CONFIGS = [
|
| 24 |
+
MarkushGrapherConfig(name="m2s", description="Molecule-to-SMILES synthetic subset"),
|
| 25 |
+
MarkushGrapherConfig(name="uspto-markush", description="Real Markush structures from USPTO patents"),
|
| 26 |
+
MarkushGrapherConfig(name="markushgrapher-synthetic", description="Synthetic Markush subset"),
|
| 27 |
+
MarkushGrapherConfig(name="markushgrapher-synthetic-training", description="Training set with synthetic Markush structures"),
|
| 28 |
]
|
| 29 |
|
| 30 |
def _info(self):
|
|
|
|
| 46 |
"text": Value("string"),
|
| 47 |
}),
|
| 48 |
}),
|
|
|
|
| 49 |
)
|
| 50 |
|
| 51 |
elif self.config.name in ["markushgrapher-synthetic", "markushgrapher-synthetic-training"]:
|
|
|
|
| 66 |
}),
|
| 67 |
"page_image": Image(decode=True),
|
| 68 |
}),
|
|
|
|
| 69 |
)
|
| 70 |
|
| 71 |
else:
|
| 72 |
raise ValueError(f"Unsupported config: {self.config.name}")
|
| 73 |
|
| 74 |
def _split_generators(self, dl_manager):
|
| 75 |
+
# Point directly to the config subfolder
|
| 76 |
+
config_path = dl_manager.download_and_extract(self.config.name)
|
| 77 |
|
| 78 |
splits = []
|
| 79 |
for split in ["train", "test"]:
|
|
|
|
| 87 |
return splits
|
| 88 |
|
| 89 |
def _generate_examples(self, data_dir):
|
|
|
|
| 90 |
for root, _, files in os.walk(data_dir):
|
| 91 |
+
for fname in files:
|
| 92 |
+
if fname.endswith(".arrow"):
|
| 93 |
+
fpath = os.path.join(root, fname)
|
| 94 |
+
dataset = Dataset.from_file(fpath)
|
| 95 |
+
for i, row in enumerate(dataset):
|
| 96 |
+
yield f"{fpath}_{i}", row
|
|
|
|
|
|