zhsy commited on
Commit
ba93def
1 Parent(s): 37c81c9

Upload viznet.py

Browse files
Files changed (1) hide show
  1. viznet.py +65 -0
viznet.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+
4
+ import datasets
5
+
6
+ class ViznetConfig(datasets.BuilderConfig):
7
+
8
+ def __init__(self, features, data_url, **kwargs):
9
+ super(ViznetConfig, self).__init__(**kwargs)
10
+ self.features = features
11
+ self.data_url = data_url
12
+
13
+ class Viznet(datasets.GeneratorBasedBuilder):
14
+
15
+ BUILDER_CONFIGS = [
16
+ ViznetConfig(
17
+ name="pairs",
18
+ features={
19
+ "source": datasets.Value("string"),
20
+ "label": datasets.Value("string"),
21
+ },
22
+ data_url="https://huggingface.co/datasets/matchbench/viznet/resolve/main/viznet.tar.gz"
23
+ ),
24
+ ViznetConfig(name="source", features={"column1": datasets.Value("string")}, data_url=None),
25
+ ViznetConfig(name="target", features={"column1": datasets.Value("string")}, data_url=None),
26
+ ]
27
+
28
+ def _info(self):
29
+ return datasets.DatasetInfo(
30
+ features=datasets.Features(self.config.features)
31
+ )
32
+
33
+ def _split_generators(self, dl_manager):
34
+ if self.config.name == "pairs":
35
+ path = dl_manager.download_and_extract(self.config.data_url)
36
+ return [
37
+ datasets.SplitGenerator(
38
+ name=split,
39
+ gen_kwargs={
40
+ "source": os.path.join(path,
41
+ f"viznet/{split}-source.json"),
42
+ "label": os.path.join(path,
43
+ f"viznet/{split}-source.json")
44
+ }
45
+ )
46
+ for split in [
47
+ datasets.Split.TRAIN,
48
+ datasets.Split.VALIDATION,
49
+ datasets.Split.TEST
50
+ ]
51
+ ]
52
+ return []
53
+
54
+ def _generate_examples(self, source, label):
55
+ if self.config.name == "pairs":
56
+ with open(source, "r") as f:
57
+ source = json.load(f)
58
+ with open(label, "r") as f:
59
+ label = json.load(f)
60
+ assert len(source) == len(label)
61
+ for i in range(len(source)):
62
+ yield i, {
63
+ "source": json.dumps(source[i]),
64
+ "label": json.dumps(label[i]),
65
+ }