cloverhxy commited on
Commit
2092edb
·
1 Parent(s): 86e8c7b

Create Beer.py

Browse files
Files changed (1) hide show
  1. Beer.py +86 -0
Beer.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import datasets
3
+ import pandas as pd
4
+
5
+ class BeerConfig(datasets.BuilderConfig):
6
+ def __init__(self, features, data_url, **kwargs):
7
+ super(BeerConfig, self).__init__(**kwargs)
8
+ self.features = features
9
+ self.data_url = data_url
10
+
11
+ class Beer(datasets.GeneratorBasedBuilder):
12
+ BUILDER_CONFIGS = [
13
+ BeerConfig(
14
+ name="pairs",
15
+ features={
16
+ "ltable_id":datasets.Value("string"),
17
+ "rtable_id":datasets.Value("string"),
18
+ "label":datasets.Value("string"),
19
+ },
20
+ data_url="https://huggingface.co/datasets/matchbench/Beer/resolve/main/",
21
+ ),
22
+ BeerConfig(
23
+ name="source",
24
+ features={
25
+ "id":datasets.Value("string"),
26
+ "Beer_Name":datasets.Value("string"),
27
+ "Brew_Factory_Name":datasets.Value("string"),
28
+ "Style":datasets.Value("string"),
29
+ "ABV":datasets.Value("string"),
30
+ },
31
+ data_url="https://huggingface.co/datasets/matchbench/Beer/resolve/main/tableA.csv",
32
+ ),
33
+ BeerConfig(
34
+ name="target",
35
+ features={
36
+ "id":datasets.Value("string"),
37
+ "Beer_Name":datasets.Value("string"),
38
+ "Brew_Factory_Name":datasets.Value("string"),
39
+ "Style":datasets.Value("string"),
40
+ "ABV":datasets.Value("string"),
41
+ },
42
+ data_url="https://huggingface.co/datasets/matchbench/Beer/resolve/main/tableB.csv",
43
+ ),
44
+ ]
45
+
46
+ def _info(self):
47
+ return datasets.DatasetInfo(
48
+ features=datasets.Features(self.config.features)
49
+ )
50
+
51
+ def _split_generators(self, dl_manager):
52
+ if self.config.name == "pairs":
53
+ return [
54
+ datasets.SplitGenerator(
55
+ name=split,
56
+ gen_kwargs={
57
+ "path_file": dl_manager.download_and_extract(os.path.join(self.config.data_url, f"{split}.csv")),
58
+ "split":split,
59
+ }
60
+ )
61
+ for split in ["train", "valid", "test"]
62
+ ]
63
+ if self.config.name == "source":
64
+ return [ datasets.SplitGenerator(name="source",gen_kwargs={"path_file":dl_manager.download_and_extract(self.config.data_url), "split":"source",})]
65
+ if self.config.name == "target":
66
+ return [ datasets.SplitGenerator(name="target",gen_kwargs={"path_file":dl_manager.download_and_extract(self.config.data_url), "split":"target",})]
67
+
68
+
69
+
70
+ def _generate_examples(self, path_file, split):
71
+ file = pd.read_csv(path_file)
72
+ for i, row in file.iterrows():
73
+ if split not in ['source', 'target']:
74
+ yield i, {
75
+ "ltable_id": row["ltable_id"],
76
+ "rtable_id": row["rtable_id"],
77
+ "label": row["label"],
78
+ }
79
+ else:
80
+ yield i, {
81
+ "id": row["id"],
82
+ "Beer_Name": row["Beer_Name"],
83
+ "Brew_Factory_Name": row["Brew_Factory_Name"],
84
+ "Style": row["Style"],
85
+ "ABV": row["ABV"],
86
+ }