Update semi-heter.py
Browse files- semi-heter.py +38 -7
semi-heter.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import os
|
2 |
import datasets
|
3 |
import pandas as pd
|
|
|
4 |
|
5 |
|
6 |
class semiHeterConfig(datasets.BuilderConfig):
|
@@ -21,6 +22,21 @@ class semiHeter(datasets.GeneratorBasedBuilder):
|
|
21 |
},
|
22 |
data_url="https://huggingface.co/datasets/matchbench/semi-heter/resolve/main/",
|
23 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
]
|
25 |
|
26 |
def _info(self):
|
@@ -42,13 +58,28 @@ class semiHeter(datasets.GeneratorBasedBuilder):
|
|
42 |
for split in ["train", "valid", "test"]
|
43 |
]
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
def _generate_examples(self, path_file, split):
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
49 |
yield i, {
|
50 |
-
"
|
51 |
-
"rtable_id": row["rtable_id"],
|
52 |
-
"label": row["label"],
|
53 |
}
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
import datasets
|
3 |
import pandas as pd
|
4 |
+
import json
|
5 |
|
6 |
|
7 |
class semiHeterConfig(datasets.BuilderConfig):
|
|
|
22 |
},
|
23 |
data_url="https://huggingface.co/datasets/matchbench/semi-heter/resolve/main/",
|
24 |
),
|
25 |
+
semiHeterConfig(
|
26 |
+
name="source",
|
27 |
+
features={
|
28 |
+
"content": datasets.Value("string"),
|
29 |
+
},
|
30 |
+
data_url="https://huggingface.co/datasets/matchbench/rel-text/resolve/main/left.json",
|
31 |
+
),
|
32 |
+
|
33 |
+
semiHeterConfig(
|
34 |
+
name="target",
|
35 |
+
features={
|
36 |
+
"content": datasets.Value("string"),
|
37 |
+
},
|
38 |
+
data_url="https://huggingface.co/datasets/matchbench/rel-text/resolve/main/right.json",
|
39 |
+
),
|
40 |
]
|
41 |
|
42 |
def _info(self):
|
|
|
58 |
for split in ["train", "valid", "test"]
|
59 |
]
|
60 |
|
61 |
+
if self.config.name == "source":
|
62 |
+
return [datasets.SplitGenerator(name="source", gen_kwargs={
|
63 |
+
"path_file": dl_manager.download_and_extract(self.config.data_url), "split": "source", })]
|
64 |
+
|
65 |
+
if self.config.name == "target":
|
66 |
+
return [datasets.SplitGenerator(name="target", gen_kwargs={
|
67 |
+
"path_file": dl_manager.download_and_extract(self.config.data_url), "split": "target", })]
|
68 |
+
|
69 |
def _generate_examples(self, path_file, split):
|
70 |
+
if split in ['source','target']:
|
71 |
+
with open(path_file, "r") as f:
|
72 |
+
file = json.load(f)
|
73 |
+
for i in range(len(file)):
|
74 |
yield i, {
|
75 |
+
"content": file[i]
|
|
|
|
|
76 |
}
|
77 |
+
else:
|
78 |
+
file = pd.read_csv(path_file)
|
79 |
+
for i, row in file.iterrows():
|
80 |
+
yield i, {
|
81 |
+
"ltable_id": row["ltable_id"],
|
82 |
+
"rtable_id": row["rtable_id"],
|
83 |
+
"label": row["label"],
|
84 |
+
}
|
85 |
+
|