Datasets:
edited build_database
Browse files- build_database.py +99 -1
build_database.py
CHANGED
|
@@ -1 +1,99 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
import datasets
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
_CITATION = """\
|
| 9 |
+
@InProceedings{huggingface:dataset,
|
| 10 |
+
title = {Ember2018-malware-v2},
|
| 11 |
+
author=Christian Williams
|
| 12 |
+
},
|
| 13 |
+
year={2024}
|
| 14 |
+
}
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
_DESCRIPTION = """\
|
| 18 |
+
This dataset is based on the EMBER 2018 Malware Analysis dataset that was uploaded to kaggle
|
| 19 |
+
"""
|
| 20 |
+
_HOMEPAGE = "https://www.kaggle.com/datasets/dhoogla/ember-2018-v2-features"
|
| 21 |
+
|
| 22 |
+
_LICENSE = ""
|
| 23 |
+
|
| 24 |
+
class EMBERConfig(datasets.GeneratorBasedBuilder):
|
| 25 |
+
VERSION = datasets.Version("1.1.0")
|
| 26 |
+
BUILDER_CONFIGS = [
|
| 27 |
+
datasets.BuilderConfig(
|
| 28 |
+
name="text_classification",
|
| 29 |
+
version=VERSION,
|
| 30 |
+
description="This part of my dataset can be used to train LLMs for text classification",
|
| 31 |
+
license=""
|
| 32 |
+
)
|
| 33 |
+
]
|
| 34 |
+
|
| 35 |
+
DEFAULT_CONFIG_NAME = "text_classification"
|
| 36 |
+
|
| 37 |
+
def _info(self):
|
| 38 |
+
if self.config.name == "text_classification":
|
| 39 |
+
features = datasets.Features(
|
| 40 |
+
{
|
| 41 |
+
"input": datasets.Value("string"),
|
| 42 |
+
"label": datasets.Value("string"),
|
| 43 |
+
}
|
| 44 |
+
)
|
| 45 |
+
else:
|
| 46 |
+
features = datasets.Features(
|
| 47 |
+
{
|
| 48 |
+
"input": datasets.Value("string"),
|
| 49 |
+
"label": datasets.Value("string"),
|
| 50 |
+
}
|
| 51 |
+
)
|
| 52 |
+
return datasets.DatasetInfo(
|
| 53 |
+
description=_DESCRIPTION,
|
| 54 |
+
features=features,
|
| 55 |
+
homepage=_HOMEPAGE,
|
| 56 |
+
license=_LICENSE,
|
| 57 |
+
citation=_CITATION,
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
def _split_generators(self, dl_manager):
|
| 61 |
+
_URLS = "https://huggingface.co/datasets/cw1521/ember2018-malware-v2/tree/main/data"
|
| 62 |
+
urls = _URLS[self.config.name]
|
| 63 |
+
data_dir = dl_manager.download_and_extract(urls)
|
| 64 |
+
return [
|
| 65 |
+
datasets.SplitGenerator(
|
| 66 |
+
name=datasets.Split.TRAIN,
|
| 67 |
+
gen_kwargs={
|
| 68 |
+
"filepaths": os.path.join(data_dir, "ember2018-train_*.jsonl"),
|
| 69 |
+
"split": "train",
|
| 70 |
+
},
|
| 71 |
+
),
|
| 72 |
+
datasets.SplitGenerator(
|
| 73 |
+
name=datasets.Split.TEST,
|
| 74 |
+
gen_kwargs={
|
| 75 |
+
"filepaths": os.path.join(data_dir, "ember2018-test_*.jsonl"),
|
| 76 |
+
"split": "test"
|
| 77 |
+
},
|
| 78 |
+
)
|
| 79 |
+
]
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def _generate_examples(self, filepaths, split):
|
| 83 |
+
key = 0
|
| 84 |
+
for id, filepath in enumerate(filepaths[split]):
|
| 85 |
+
key += 1
|
| 86 |
+
with open(filepath[id], encoding="utf-8") as f:
|
| 87 |
+
data_list = json.load(f)
|
| 88 |
+
for data in data_list:
|
| 89 |
+
if self.config.name == "text_classification":
|
| 90 |
+
data.remove
|
| 91 |
+
yield key, {
|
| 92 |
+
"input": data["input"],
|
| 93 |
+
"label": data["label"]
|
| 94 |
+
}
|
| 95 |
+
else:
|
| 96 |
+
yield key, {
|
| 97 |
+
"input": data["input"],
|
| 98 |
+
"label": data["label"]
|
| 99 |
+
}
|