zhsy commited on
Commit
04701b9
·
1 Parent(s): f6ec737

Upload Amazon-Google-SM.py

Browse files
Files changed (1) hide show
  1. Amazon-Google-SM.py +84 -0
Amazon-Google-SM.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ import datasets
4
+ import pandas as pd
5
+
6
+ class AmazonGoogleSMConfig(datasets.BuilderConfig):
7
+
8
+ def __init__(self, features, data_url, **kwargs):
9
+ super(AmazonGoogleSMConfig, self).__init__(**kwargs)
10
+ self.features = features
11
+ self.data_url = data_url
12
+
13
+ class AmazonGoogleSM(datasets.GeneratorBasedBuilder):
14
+
15
+ BUILDER_CONFIGS = [
16
+ AmazonGoogleSMConfig(
17
+ name="pairs",
18
+ features={
19
+ "column1": datasets.Value("string"),
20
+ "column2": datasets.Value("string"),
21
+ "label" : datasets.Value("bool")
22
+ },
23
+ data_url="https://huggingface.co/datasets/matchbench/Amazon-Google-SM/resolve/main/matches.txt"
24
+ ),
25
+ AmazonGoogleSMConfig(
26
+ name="source",
27
+ features={
28
+ "json": datasets.Value("string")
29
+ },
30
+ data_url="https://huggingface.co/datasets/matchbench/Amazon-Google-SM/resolve/main/amazon_google-master-sm-1.csv"
31
+ ),
32
+ AmazonGoogleSMConfig(
33
+ name="target",
34
+ features={
35
+ "json": datasets.Value("string")
36
+ },
37
+ data_url="https://huggingface.co/datasets/matchbench/Amazon-Google-SM/resolve/main/amazon_google-master-sm-2.csv"
38
+ ),
39
+ ]
40
+
41
+ def _info(self):
42
+ return datasets.DatasetInfo(
43
+ features=datasets.Features(self.config.features)
44
+ )
45
+
46
+ def _split_generators(self, dl_manager):
47
+ path = dl_manager.download(self.config.data_url)
48
+ return [
49
+ datasets.SplitGenerator(
50
+ name=split,
51
+ gen_kwargs={
52
+ "file_path": path
53
+ }
54
+ )
55
+ for split in [
56
+ datasets.Split.TEST
57
+ ]
58
+ ]
59
+
60
+ def _generate_examples(self, file_path):
61
+ if self.config.name == "pairs":
62
+ with open(file_path, "r") as f:
63
+ md = {}
64
+ for _, line in enumerate(f):
65
+ t = line.strip().split(',')
66
+ if t[0] not in md:
67
+ md[t[0]] = {t[1]}
68
+ else:
69
+ md[t[0]].add(t[1])
70
+ id = -1
71
+ for k, v in md.items():
72
+ for i in v:
73
+ id = id + 1
74
+ yield id, {"column1": k, "column2": i, "label": True}
75
+ elif self.config.name == "source":
76
+ with open(file_path, "r") as f:
77
+ source = pd.read_csv(file_path)
78
+ source = source.to_json()
79
+ yield 0, {"json": source}
80
+ elif self.config.name == "target":
81
+ with open(file_path, "r") as f:
82
+ target = pd.read_csv(file_path)
83
+ target = target.to_json()
84
+ yield 0, {"json": target}