File size: 2,668 Bytes
c812221 679bbb4 c812221 2d34974 c812221 ae30820 c812221 b3083dc c812221 420b7be 2c4d03d c812221 2c4d03d c812221 2c4d03d c812221 2c4d03d c812221 559a199 1c264e0 934a699 c812221 0049bc5 c812221 2d34974 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
import os
from pdb import set_trace
import datasets
import pandas as pd
_CITATION = """\
Put your dataset citation here.
"""
_DESCRIPTION = """\
Description of your dataset goes here.
"""
_HOMEPAGE = "https://your-dataset-homepage.com"
_LICENSE = "License information goes here."
class Test(datasets.GeneratorBasedBuilder):
"""Your dataset description"""
BUILDER_CONFIGS = [
datasets.BuilderConfig(
name="customers",
version=datasets.Version("1.0.0"),
description="This is subset A"),
datasets.BuilderConfig(
name="products",
version=datasets.Version("1.0.0"),
description="This is subset B"),
]
def _info(self):
# set_trace()
if self.config.name == "customers":
features = datasets.Features(
{
"customer_id": datasets.Value("int64"),
"name": datasets.Value("string"),
"age": datasets.Value("int64"),
}
)
elif self.config.name == "products":
features = datasets.Features(
{
"product_id": datasets.Value("int64"),
"name": datasets.Value("string"),
"price": datasets.Value("double"),
}
)
else:
raise ValueError(f"Unknown subset: {self.config.name}")
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
supervised_keys=None,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
data_dir = dl_manager.manual_dir or "./"
data_dir = os.path.join(data_dir, self.config.name)
print(data_dir)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={"filepath": os.path.join(data_dir, "train.csv")},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={"filepath": os.path.join(data_dir, "val.csv")},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={"filepath": os.path.join(data_dir, "test.csv")},
),
]
def _generate_examples(self, filepath):
# set_trace()
with open(filepath, encoding="utf-8") as f:
df = pd.read_csv(filepath, index_col=0)
for id_, item in df.iterrows():
yield id_, item.to_dict() |