Datasets:
taisazero commited on
Commit ·
3a6663d
1
Parent(s): 0681993
fixed data loader
Browse files- shellcode_ia32.py +61 -34
shellcode_ia32.py
CHANGED
|
@@ -54,7 +54,7 @@ _URLs = {
|
|
| 54 |
|
| 55 |
|
| 56 |
# TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
|
| 57 |
-
class
|
| 58 |
"""Shellcode_IA32 a dataset for shellcode generation"""
|
| 59 |
|
| 60 |
VERSION = datasets.Version("1.1.0")
|
|
@@ -87,22 +87,22 @@ class Shellcode_IA32(datasets.GeneratorBasedBuilder):
|
|
| 87 |
|
| 88 |
}
|
| 89 |
)
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
|
| 107 |
def _split_generators(self, dl_manager):
|
| 108 |
"""Returns SplitGenerators."""
|
|
@@ -114,12 +114,39 @@ class Shellcode_IA32(datasets.GeneratorBasedBuilder):
|
|
| 114 |
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
|
| 115 |
my_urls = _URLs[self.config.name]
|
| 116 |
data_dir = dl_manager.download_and_extract(my_urls)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
return [
|
| 118 |
datasets.SplitGenerator(
|
| 119 |
name=datasets.Split.TRAIN,
|
| 120 |
# These kwargs will be passed to _generate_examples
|
| 121 |
gen_kwargs={
|
| 122 |
-
"filepath": os.path.join(data_dir
|
| 123 |
"split": "train",
|
| 124 |
},
|
| 125 |
),
|
|
@@ -127,7 +154,7 @@ class Shellcode_IA32(datasets.GeneratorBasedBuilder):
|
|
| 127 |
name=datasets.Split.TEST,
|
| 128 |
# These kwargs will be passed to _generate_examples
|
| 129 |
gen_kwargs={
|
| 130 |
-
"filepath": os.path.join(data_dir
|
| 131 |
"split": "test"
|
| 132 |
},
|
| 133 |
),
|
|
@@ -135,7 +162,7 @@ class Shellcode_IA32(datasets.GeneratorBasedBuilder):
|
|
| 135 |
name=datasets.Split.VALIDATION,
|
| 136 |
# These kwargs will be passed to _generate_examples
|
| 137 |
gen_kwargs={
|
| 138 |
-
"filepath": os.path.join(data_dir
|
| 139 |
"split": "dev",
|
| 140 |
},
|
| 141 |
),
|
|
@@ -147,20 +174,20 @@ class Shellcode_IA32(datasets.GeneratorBasedBuilder):
|
|
| 147 |
""" Yields examples as (key, example) tuples. """
|
| 148 |
# This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
|
| 149 |
# The `key` is here for legacy reason (tfds) and is not important in itself.
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
|
| 165 |
for idx, row in data.iterrows():
|
| 166 |
yield idx, {
|
|
|
|
| 54 |
|
| 55 |
|
| 56 |
# TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
|
| 57 |
+
class ShellcodeIA32(datasets.GeneratorBasedBuilder):
|
| 58 |
"""Shellcode_IA32 a dataset for shellcode generation"""
|
| 59 |
|
| 60 |
VERSION = datasets.Version("1.1.0")
|
|
|
|
| 87 |
|
| 88 |
}
|
| 89 |
)
|
| 90 |
+
return datasets.DatasetInfo(
|
| 91 |
+
# This is the description that will appear on the datasets page.
|
| 92 |
+
description=_DESCRIPTION,
|
| 93 |
+
# This defines the different columns of the dataset and their types
|
| 94 |
+
features=features, # Here we define them above because they are different between the two configurations
|
| 95 |
+
# If there's a common (input, target) tuple from the features,
|
| 96 |
+
# specify them here. They'll be used if as_supervised=True in
|
| 97 |
+
# builder.as_dataset.
|
| 98 |
+
supervised_keys=None,
|
| 99 |
+
# Homepage of the dataset for documentation
|
| 100 |
+
homepage=_HOMEPAGE,
|
| 101 |
+
# License for the dataset if available
|
| 102 |
+
license=_LICENSE,
|
| 103 |
+
# Citation for the dataset
|
| 104 |
+
citation=_CITATION,
|
| 105 |
+
)
|
| 106 |
|
| 107 |
def _split_generators(self, dl_manager):
|
| 108 |
"""Returns SplitGenerators."""
|
|
|
|
| 114 |
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
|
| 115 |
my_urls = _URLs[self.config.name]
|
| 116 |
data_dir = dl_manager.download_and_extract(my_urls)
|
| 117 |
+
# return [
|
| 118 |
+
# datasets.SplitGenerator(
|
| 119 |
+
# name=datasets.Split.TRAIN,
|
| 120 |
+
# # These kwargs will be passed to _generate_examples
|
| 121 |
+
# gen_kwargs={
|
| 122 |
+
# "filepath": os.path.join(data_dir, "Shellcode_IA32.tsv"),
|
| 123 |
+
# "split": "train",
|
| 124 |
+
# },
|
| 125 |
+
# ),
|
| 126 |
+
# datasets.SplitGenerator(
|
| 127 |
+
# name=datasets.Split.TEST,
|
| 128 |
+
# # These kwargs will be passed to _generate_examples
|
| 129 |
+
# gen_kwargs={
|
| 130 |
+
# "filepath": os.path.join(data_dir, "Shellcode_IA32.tsv"),
|
| 131 |
+
# "split": "test"
|
| 132 |
+
# },
|
| 133 |
+
# ),
|
| 134 |
+
# datasets.SplitGenerator(
|
| 135 |
+
# name=datasets.Split.VALIDATION,
|
| 136 |
+
# # These kwargs will be passed to _generate_examples
|
| 137 |
+
# gen_kwargs={
|
| 138 |
+
# "filepath": os.path.join(data_dir, "Shellcode_IA32.tsv"),
|
| 139 |
+
# "split": "dev",
|
| 140 |
+
# },
|
| 141 |
+
# ),
|
| 142 |
+
# ]
|
| 143 |
+
|
| 144 |
return [
|
| 145 |
datasets.SplitGenerator(
|
| 146 |
name=datasets.Split.TRAIN,
|
| 147 |
# These kwargs will be passed to _generate_examples
|
| 148 |
gen_kwargs={
|
| 149 |
+
"filepath": os.path.join(data_dir),
|
| 150 |
"split": "train",
|
| 151 |
},
|
| 152 |
),
|
|
|
|
| 154 |
name=datasets.Split.TEST,
|
| 155 |
# These kwargs will be passed to _generate_examples
|
| 156 |
gen_kwargs={
|
| 157 |
+
"filepath": os.path.join(data_dir),
|
| 158 |
"split": "test"
|
| 159 |
},
|
| 160 |
),
|
|
|
|
| 162 |
name=datasets.Split.VALIDATION,
|
| 163 |
# These kwargs will be passed to _generate_examples
|
| 164 |
gen_kwargs={
|
| 165 |
+
"filepath": os.path.join(data_dir),
|
| 166 |
"split": "dev",
|
| 167 |
},
|
| 168 |
),
|
|
|
|
| 174 |
""" Yields examples as (key, example) tuples. """
|
| 175 |
# This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
|
| 176 |
# The `key` is here for legacy reason (tfds) and is not important in itself.
|
| 177 |
+
"""This function returns the examples in the raw (text) form."""
|
| 178 |
+
|
| 179 |
+
df = pd.read_csv(filepath, delimiter = '\t')
|
| 180 |
+
train = df.sample(frac = 0.8, random_state = 0)
|
| 181 |
+
test = df.drop(train.index)
|
| 182 |
+
dev = test.sample(frac = 0.5, random_state = 0)
|
| 183 |
+
test = test.drop(dev.index)
|
| 184 |
+
|
| 185 |
+
if split == 'train':
|
| 186 |
+
data = train
|
| 187 |
+
elif split == 'dev':
|
| 188 |
+
data = dev
|
| 189 |
+
elif split == 'test':
|
| 190 |
+
data = test
|
| 191 |
|
| 192 |
for idx, row in data.iterrows():
|
| 193 |
yield idx, {
|