File size: 2,197 Bytes
ba93def
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fa9315a
ba93def
c518be3
ba93def
fa9315a
 
ba93def
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fa9315a
ba93def
 
 
5c76090
 
 
ba93def
 
fa9315a
ba93def
 
 
 
 
 
 
 
 
 
fa9315a
 
ba93def
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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.Sequence(datasets.Value("string")),     
            },
            data_url="https://huggingface.co/datasets/matchbench/viznet/resolve/main/viznet.zip"
        ),
        ViznetConfig(name="source", features={"column1": datasets.Value("string")}, data_url=None),
        ViznetConfig(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"viznet/{split}-source.json"),
                        "label": os.path.join(path,
                                               f"viznet/{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],
                }