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