Datasets:
Upload build_dataset.py
Browse files- build_dataset.py +15 -23
build_dataset.py
CHANGED
@@ -41,14 +41,16 @@ This dataset is from the EMBER 2018 Malware Analysis dataset
|
|
41 |
_HOMEPAGE = "https://github.com/elastic/ember"
|
42 |
_LICENSE = ""
|
43 |
_URLS = {
|
44 |
-
"text_classification": "https://huggingface.co/datasets/cw1521/ember2018-malware/blob/main/data/"
|
|
|
45 |
}
|
46 |
|
47 |
|
48 |
class EMBERConfig(datasets.GeneratorBasedBuilder):
|
49 |
VERSION = datasets.Version("1.1.0")
|
50 |
BUILDER_CONFIGS = [
|
51 |
-
datasets.BuilderConfig(name="text_classification", version=VERSION, description="This part of my dataset covers
|
|
|
52 |
]
|
53 |
|
54 |
DEFAULT_CONFIG_NAME = "text_classification"
|
@@ -89,55 +91,45 @@ class EMBERConfig(datasets.GeneratorBasedBuilder):
|
|
89 |
license=_LICENSE,
|
90 |
citation=_CITATION,
|
91 |
)
|
|
|
|
|
92 |
|
93 |
def _split_generators(self, dl_manager):
|
94 |
urls = _URLS[self.config.name]
|
95 |
-
|
96 |
-
file_urls = {
|
97 |
-
"train": [f"{urls[0]}/{file}" for file in file_list["train"]],
|
98 |
-
"test": [f"{urls[0]}/{file}" for file in file_list["test"]]
|
99 |
-
}
|
100 |
-
data_dir = dl_manager.download_and_extract(file_urls)
|
101 |
return [
|
102 |
datasets.SplitGenerator(
|
103 |
name=datasets.Split.TRAIN,
|
104 |
gen_kwargs={
|
105 |
-
"
|
106 |
-
"local_datafiles": data_dir["train"],
|
107 |
"split": "train",
|
108 |
},
|
109 |
),
|
110 |
# datasets.SplitGenerator(
|
111 |
# name=datasets.Split.VALIDATION,
|
112 |
# gen_kwargs={
|
113 |
-
# "
|
114 |
-
# "split": "
|
115 |
# },
|
116 |
# ),
|
117 |
datasets.SplitGenerator(
|
118 |
name=datasets.Split.TEST,
|
119 |
gen_kwargs={
|
120 |
-
"
|
121 |
-
"local_datafiles": data_dir["test"],
|
122 |
"split": "test"
|
123 |
},
|
124 |
-
)
|
125 |
]
|
126 |
|
127 |
|
128 |
-
def _generate_examples(self,
|
129 |
key = 0
|
130 |
-
for id,
|
131 |
-
|
132 |
-
# The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
|
133 |
-
|
134 |
-
local_path = os.path.join(local_datafiles[id], path)
|
135 |
-
with open(local_path, encoding="utf-8") as f:
|
136 |
data_list = json.load(f)
|
137 |
for data in data_list["data"]:
|
138 |
key += 1
|
139 |
if self.config.name == "text_classification":
|
140 |
-
# Yields examples as (key, example) tuples
|
141 |
yield key, {
|
142 |
"x": data["x"],
|
143 |
"y": data["y"],
|
|
|
41 |
_HOMEPAGE = "https://github.com/elastic/ember"
|
42 |
_LICENSE = ""
|
43 |
_URLS = {
|
44 |
+
"text_classification": "https://huggingface.co/datasets/cw1521/ember2018-malware/blob/main/data/",
|
45 |
+
"test": "https://huggingface.co/datasets/cw1521/ember2018-malware/blob/main/data/*_train_1.jsonl"
|
46 |
}
|
47 |
|
48 |
|
49 |
class EMBERConfig(datasets.GeneratorBasedBuilder):
|
50 |
VERSION = datasets.Version("1.1.0")
|
51 |
BUILDER_CONFIGS = [
|
52 |
+
datasets.BuilderConfig(name="text_classification", version=VERSION, description="This part of my dataset covers text classification"),
|
53 |
+
datasets.BuilderConfig(name="test", version=VERSION, description="This part of my dataset is for testing")
|
54 |
]
|
55 |
|
56 |
DEFAULT_CONFIG_NAME = "text_classification"
|
|
|
91 |
license=_LICENSE,
|
92 |
citation=_CITATION,
|
93 |
)
|
94 |
+
# "*_train_*.jsonl"
|
95 |
+
# "*_test_*.jsonl"
|
96 |
|
97 |
def _split_generators(self, dl_manager):
|
98 |
urls = _URLS[self.config.name]
|
99 |
+
data_dir = dl_manager.download_and_extract(urls)
|
|
|
|
|
|
|
|
|
|
|
100 |
return [
|
101 |
datasets.SplitGenerator(
|
102 |
name=datasets.Split.TRAIN,
|
103 |
gen_kwargs={
|
104 |
+
"filepaths": os.path.join(data_dir, "*_train_*.jsonl"),
|
|
|
105 |
"split": "train",
|
106 |
},
|
107 |
),
|
108 |
# datasets.SplitGenerator(
|
109 |
# name=datasets.Split.VALIDATION,
|
110 |
# gen_kwargs={
|
111 |
+
# "filepaths": os.path.join(data_dir, "*_valid_*.jsonl"),
|
112 |
+
# "split": "valid",
|
113 |
# },
|
114 |
# ),
|
115 |
datasets.SplitGenerator(
|
116 |
name=datasets.Split.TEST,
|
117 |
gen_kwargs={
|
118 |
+
"filepaths": os.path.join(data_dir, "*_test_*.jsonl"),
|
|
|
119 |
"split": "test"
|
120 |
},
|
121 |
+
)
|
122 |
]
|
123 |
|
124 |
|
125 |
+
def _generate_examples(self, filepaths, split):
|
126 |
key = 0
|
127 |
+
for id, filepath in enumerate(filepaths[split]):
|
128 |
+
with open(filepath[id], encoding="utf-8") as f:
|
|
|
|
|
|
|
|
|
129 |
data_list = json.load(f)
|
130 |
for data in data_list["data"]:
|
131 |
key += 1
|
132 |
if self.config.name == "text_classification":
|
|
|
133 |
yield key, {
|
134 |
"x": data["x"],
|
135 |
"y": data["y"],
|