| import json |
| import os |
|
|
| import datasets |
|
|
| class T2Dv2Config(datasets.BuilderConfig): |
|
|
| def __init__(self, features, data_url, **kwargs): |
| super(T2Dv2Config, self).__init__(**kwargs) |
| self.features = features |
| self.data_url = data_url |
|
|
| class T2Dv2(datasets.GeneratorBasedBuilder): |
|
|
| BUILDER_CONFIGS = [ |
| T2Dv2Config( |
| name="pairs", |
| features={ |
| "source": datasets.Value("string"), |
| "label": datasets.Sequence(datasets.Value("string")), |
| }, |
| data_url="https://huggingface.co/datasets/matchbench/T2Dv2/resolve/main/t2dv2.zip" |
| ), |
| T2Dv2Config(name="source", features={"column1": datasets.Value("string")}, data_url=None), |
| T2Dv2Config(name="target", features={"column1": datasets.Value("string")}, data_url=None), |
| ] |
|
|
| 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"t2dv2/{split}-source.json"), |
| "label": os.path.join(path, |
| f"t2dv2/{split}-label.json") |
| } |
| ) |
| for split in [ |
| "train", |
| "valid", |
| "test" |
| ] |
| ] |
| return [] |
|
|
| 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": source[i], |
| "label": label[i], |
| } |
|
|