|
import json |
|
import os |
|
|
|
import datasets |
|
|
|
class ViznetConfig(datasets.BuilderConfig): |
|
|
|
def __init__(self, features, data_url, **kwargs): |
|
super(ViznetConfig, self).__init__(**kwargs) |
|
self.features = features |
|
self.data_url = data_url |
|
|
|
class Viznet(datasets.GeneratorBasedBuilder): |
|
|
|
BUILDER_CONFIGS = [ |
|
ViznetConfig( |
|
name="pairs", |
|
features={ |
|
"source": datasets.Value("string"), |
|
"label": datasets.Value("string"), |
|
}, |
|
data_url="https://huggingface.co/datasets/matchbench/viznet/resolve/main/viznet.zip" |
|
), |
|
] |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
features=datasets.Features(self.config.features) |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
if self.config.name == "pairs": |
|
path = dl_manager.download_and_extract(self.config.data_url) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=split, |
|
gen_kwargs={ |
|
"source": os.path.join(path, |
|
f"viznet/{split}-source.json"), |
|
"label": os.path.join(path, |
|
f"viznet/{split}-source.json") |
|
} |
|
) |
|
for split in [ |
|
datasets.Split.TRAIN, |
|
datasets.Split.VALIDATION, |
|
datasets.Split.TEST |
|
] |
|
] |
|
|
|
def _generate_examples(self, source, label): |
|
if self.config.name == "pairs": |
|
with open(source, "r") as f: |
|
source = json.load(f) |
|
with open(label, "r") as f: |
|
label = json.load(f) |
|
assert len(source) == len(label) |
|
for i in range(len(source)): |
|
yield i, { |
|
"source": json.dumps(source[i]), |
|
"label": json.dumps(label[i]), |
|
} |