|
import datasets |
|
import pandas as pd |
|
import os |
|
|
|
|
|
class MyDataset(datasets.GeneratorBasedBuilder): |
|
def _info(self): |
|
|
|
return datasets.DatasetInfo( |
|
description="DESCRIPTION", |
|
features=datasets.Features( |
|
{"domain": datasets.Value("string"), "label": datasets.Value("string")} |
|
), |
|
supervised_keys=("domain", "label"), |
|
homepage="_HOMEPAGE", |
|
) |
|
|
|
|
|
def _split_generators(self, dl_manager: DownloadConfig): |
|
|
|
csv_path = "https://huggingface.co/datasets/harpomaxx/dga-detection/raw/main/argencon.csv.gz" |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=split, |
|
gen_kwargs={ |
|
"filepath": csv_path, |
|
"split": split, |
|
}, |
|
) |
|
for split in ["train", "test", "validation"] |
|
] |
|
|
|
def _generate_examples_old( |
|
self, |
|
filepath: str, |
|
split: str, |
|
): |
|
|
|
dataset = pd.read_csv(filepath) |
|
|
|
|
|
dataset = dataset[dataset["split"] == split] |
|
|
|
for index, row in dataset.iterrows(): |
|
yield index, { |
|
"domain": row["domain"], |
|
"label": row["label"], |
|
} |
|
|
|
|
|
def _generate_examples( |
|
self, |
|
filepath: str, |
|
split: str, |
|
): |
|
|
|
dataset = pd.read_csv(filepath) |
|
|
|
|
|
total_rows = len(dataset) |
|
|
|
|
|
train_ratio = 0.7 |
|
test_ratio = 0.2 |
|
|
|
|
|
train_end = int(train_ratio * total_rows) |
|
test_end = train_end + int(test_ratio * total_rows) |
|
|
|
|
|
if split == "train": |
|
dataset = dataset.iloc[:train_end] |
|
elif split == "test": |
|
dataset = dataset.iloc[train_end:test_end] |
|
elif split == "validation": |
|
dataset = dataset.iloc[test_end:] |
|
|
|
|
|
for index, row in dataset.iterrows(): |
|
yield index, { |
|
"domain": row["domain"], |
|
"label": row["label"], |
|
} |
|
|
|
|