zhsy commited on
Commit
6ad8d9a
·
1 Parent(s): a4bddf2

Create efthymiou.py

Browse files
Files changed (1) hide show
  1. efthymiou.py +65 -0
efthymiou.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+
4
+ import datasets
5
+
6
+ class EfthymiouConfig(datasets.BuilderConfig):
7
+
8
+ def __init__(self, features, data_url, **kwargs):
9
+ super(EfthymiouConfig, self).__init__(**kwargs)
10
+ self.features = features
11
+ self.data_url = data_url
12
+
13
+ class Efthymiou(datasets.GeneratorBasedBuilder):
14
+
15
+ BUILDER_CONFIGS = [
16
+ EfthymiouConfig(
17
+ name="pairs",
18
+ features={
19
+ "source": datasets.Value("string"),
20
+ "label": datasets.Sequence(datasets.Value("string")),
21
+ },
22
+ data_url="https://huggingface.co/datasets/matchbench/efthymiou/resolve/main/efthymiou.zip"
23
+ ),
24
+ EfthymiouConfig(name="source", features={"column1": datasets.Value("string")}, data_url=None),
25
+ EfthymiouConfig(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"efthymiou/{split}-source.json"),
42
+ "label": os.path.join(path,
43
+ f"efthymiou/{split}-label.json")
44
+ }
45
+ )
46
+ for split in [
47
+ "train",
48
+ "valid",
49
+ "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": source[i],
64
+ "label": label[i],
65
+ }