semi-text-c / semi-text-c.py
ScHh0625's picture
Upload 6 files
3bde5bd
raw
history blame
1.72 kB
import os
import datasets
import pandas as pd
class semiTextcConfig(datasets.BuilderConfig):
def __init__(self, features, data_url, **kwargs):
super(semiTextcConfig, self).__init__(**kwargs)
self.features = features
self.data_url = data_url
class semiTextc(datasets.GeneratorBasedBuilder):
BUILDER_CONFIGS = [
semiTextcConfig(
name="pairs",
features={
"ltable_id": datasets.Value("string"),
"rtable_id": datasets.Value("string"),
"label": datasets.Value("string"),
},
data_url="https://huggingface.co/datasets/matchbench/semi-Textc/resolve/main/",
),
]
def _info(self):
return datasets.DatasetInfo(
features=datasets.Features(self.config.features)
)
def _split_generators(self, dl_manager):
if self.config.name == "pairs":
return [
datasets.SplitGenerator(
name=split,
gen_kwargs={
"path_file": dl_manager.download_and_extract(
os.path.join(self.config.data_url, f"{split}.csv")),
"split": split,
}
)
for split in ["train", "valid", "test"]
]
def _generate_examples(self, path_file, split):
file = pd.read_csv(path_file)
for i, row in file.iterrows():
if split in ['train', 'valid','test']:
yield i, {
"ltable_id": row["ltable_id"],
"rtable_id": row["rtable_id"],
"label": row["label"],
}