Delete markushgrapher-datasets.py
Browse files- markushgrapher-datasets.py +0 -100
markushgrapher-datasets.py
DELETED
|
@@ -1,100 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
from datasets import (
|
| 3 |
-
DatasetInfo,
|
| 4 |
-
GeneratorBasedBuilder,
|
| 5 |
-
SplitGenerator,
|
| 6 |
-
Split,
|
| 7 |
-
BuilderConfig,
|
| 8 |
-
Features,
|
| 9 |
-
Value,
|
| 10 |
-
Sequence,
|
| 11 |
-
Image,
|
| 12 |
-
Dataset
|
| 13 |
-
)
|
| 14 |
-
import datasets
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
class MarkushGrapherConfig(BuilderConfig):
|
| 18 |
-
def __init__(self, **kwargs):
|
| 19 |
-
super().__init__(**kwargs)
|
| 20 |
-
|
| 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):
|
| 31 |
-
if self.config.name in ["m2s", "uspto-markush"]:
|
| 32 |
-
return DatasetInfo(
|
| 33 |
-
features=Features({
|
| 34 |
-
"id": Value("int64"),
|
| 35 |
-
"image_name": Value("string"),
|
| 36 |
-
"page_image": Image(decode=True),
|
| 37 |
-
"description": Value("string"),
|
| 38 |
-
"annotation": Value("string"),
|
| 39 |
-
"mol": Value("string"),
|
| 40 |
-
"cxsmiles_dataset": Value("string"),
|
| 41 |
-
"cxsmiles": Value("string"),
|
| 42 |
-
"cxsmiles_opt": Value("string"),
|
| 43 |
-
"keypoints": Value("null"),
|
| 44 |
-
"cells": Sequence({
|
| 45 |
-
"bbox": Sequence(Value("float64")),
|
| 46 |
-
"text": Value("string"),
|
| 47 |
-
}),
|
| 48 |
-
}),
|
| 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 |
-
)
|
| 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"]:
|
| 80 |
-
split_path = os.path.join(config_path, split)
|
| 81 |
-
if os.path.exists(split_path):
|
| 82 |
-
splits.append(SplitGenerator(
|
| 83 |
-
name=Split.TRAIN if split == "train" else Split.TEST,
|
| 84 |
-
gen_kwargs={"data_dir": split_path},
|
| 85 |
-
))
|
| 86 |
-
|
| 87 |
-
return splits
|
| 88 |
-
|
| 89 |
-
def _generate_examples(self, data_dir):
|
| 90 |
-
print(f"[DEBUG] LOADING CONFIG: {self.config.name}")
|
| 91 |
-
print(f"[DEBUG] Looking for arrow files under: {data_dir}")
|
| 92 |
-
|
| 93 |
-
for root, _, files in os.walk(data_dir):
|
| 94 |
-
for fname in files:
|
| 95 |
-
if fname.endswith(".arrow"):
|
| 96 |
-
fpath = os.path.join(root, fname)
|
| 97 |
-
print(f"[DEBUG] Reading file: {fpath}") # <--- KEY
|
| 98 |
-
dataset = Dataset.from_file(fpath)
|
| 99 |
-
for i, row in enumerate(dataset):
|
| 100 |
-
yield f"{fpath}_{i}", row
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|