Datasets:
taisazero
commited on
Commit
·
c3315c6
1
Parent(s):
e512c02
updated loader name:
Browse files- Shellcode_IA32.py +207 -0
Shellcode_IA32.py
ADDED
@@ -0,0 +1,207 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
3 |
+
#
|
4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
+
# you may not use this file except in compliance with the License.
|
6 |
+
# You may obtain a copy of the License at
|
7 |
+
#
|
8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
+
#
|
10 |
+
# Unless required by applicable law or agreed to in writing, software
|
11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
+
# See the License for the specific language governing permissions and
|
14 |
+
# limitations under the License.
|
15 |
+
"""TODO: Add a description here."""
|
16 |
+
|
17 |
+
|
18 |
+
import csv
|
19 |
+
import json
|
20 |
+
import os
|
21 |
+
import pandas as pd
|
22 |
+
import datasets
|
23 |
+
|
24 |
+
|
25 |
+
# TODO: Add BibTeX citation
|
26 |
+
# Find for instance the citation on arxiv or on the dataset repo/website
|
27 |
+
_CITATION = """\
|
28 |
+
@InProceedings{huggingface:dataset,
|
29 |
+
title = {A great new dataset},
|
30 |
+
author={huggingface, Inc.
|
31 |
+
},
|
32 |
+
year={2020}
|
33 |
+
}
|
34 |
+
"""
|
35 |
+
|
36 |
+
# TODO: Add description of the dataset here
|
37 |
+
# You can copy an official description
|
38 |
+
_DESCRIPTION = """\
|
39 |
+
This new dataset is designed to solve this great NLP task and is crafted with a lot of care.
|
40 |
+
"""
|
41 |
+
|
42 |
+
# TODO: Add a link to an official homepage for the dataset here
|
43 |
+
_HOMEPAGE = "https://github.com/dessertlab/Shellcode_IA32"
|
44 |
+
|
45 |
+
# TODO: Add the licence for the dataset here if you can find it
|
46 |
+
_LICENSE = "GNU GENERAL PUBLIC LICENSE"
|
47 |
+
|
48 |
+
# TODO: Add link to the official dataset URLs here
|
49 |
+
# The HuggingFace dataset library don't host the datasets but only point to the original files
|
50 |
+
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
|
51 |
+
_URLs = {
|
52 |
+
'default': "https://raw.githubusercontent.com/dessertlab/Shellcode_IA32/main/Shellcode_IA32.tsv",
|
53 |
+
}
|
54 |
+
|
55 |
+
|
56 |
+
# TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
|
57 |
+
class Shellcode_IA32(datasets.GeneratorBasedBuilder):
|
58 |
+
"""Shellcode_IA32 a dataset for shellcode generation"""
|
59 |
+
|
60 |
+
VERSION = datasets.Version("1.1.0")
|
61 |
+
|
62 |
+
# This is an example of a dataset with multiple configurations.
|
63 |
+
# If you don't want/need to define several sub-sets in your dataset,
|
64 |
+
# just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
|
65 |
+
|
66 |
+
# If you need to make complex sub-parts in the datasets with configurable options
|
67 |
+
# You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
|
68 |
+
# BUILDER_CONFIG_CLASS = MyBuilderConfig
|
69 |
+
|
70 |
+
# You will be able to load one or the other configurations in the following list with
|
71 |
+
# data = datasets.load_dataset('my_dataset', 'first_domain')
|
72 |
+
# data = datasets.load_dataset('my_dataset', 'second_domain')
|
73 |
+
BUILDER_CONFIGS = [
|
74 |
+
datasets.BuilderConfig(name="default", version=VERSION, description="This part of my dataset covers the default train/test split"),
|
75 |
+
#datasets.BuilderConfig(name="second_domain", version=VERSION, description="This part of my dataset covers a second domain"),
|
76 |
+
]
|
77 |
+
|
78 |
+
DEFAULT_CONFIG_NAME = "default" # It's not mandatory to have a default configuration. Just use one if it make sense.
|
79 |
+
|
80 |
+
def _info(self):
|
81 |
+
# TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
|
82 |
+
|
83 |
+
features = datasets.Features(
|
84 |
+
{
|
85 |
+
"intent": datasets.Value("string"),
|
86 |
+
"snippet": datasets.Value("string"),
|
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."""
|
109 |
+
# TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
|
110 |
+
# If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
|
111 |
+
|
112 |
+
# dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLs
|
113 |
+
# It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
|
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 |
+
),
|
153 |
+
datasets.SplitGenerator(
|
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 |
+
),
|
161 |
+
datasets.SplitGenerator(
|
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 |
+
),
|
169 |
+
]
|
170 |
+
|
171 |
+
def _generate_examples(
|
172 |
+
self, filepath, split # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
173 |
+
):
|
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, {
|
194 |
+
"snippet": row["SNIPPETS"],
|
195 |
+
"intent": row["INTENTS"],
|
196 |
+
|
197 |
+
}
|
198 |
+
# with open(filepath, encoding="utf-8") as f:
|
199 |
+
# reader = csv.DictReader(f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
200 |
+
# reader =
|
201 |
+
# for idx, row in enumerate(reader):
|
202 |
+
#
|
203 |
+
# yield idx, {
|
204 |
+
# "snippet": row["SNIPPETS"],
|
205 |
+
# "intent": row["INTENTS"],
|
206 |
+
#
|
207 |
+
# }
|