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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
2 |
+
#
|
3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
# you may not use this file except in compliance with the License.
|
5 |
+
# You may obtain a copy of the License at
|
6 |
+
#
|
7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
#
|
9 |
+
# Unless required by applicable law or agreed to in writing, software
|
10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
# See the License for the specific language governing permissions and
|
13 |
+
# limitations under the License.
|
14 |
+
import csv
|
15 |
+
import json
|
16 |
+
import os
|
17 |
+
|
18 |
+
import datasets
|
19 |
+
|
20 |
+
_DESCRIPTION="This labelled PII dataset consists of protocol traces (JSON, SQL (PostgreSQL, MySQL), HTML, and XML) generated from OpenAPI specifications and includes 60+ PII types."
|
21 |
+
_CITATION="""
|
22 |
+
@online{WinNT,
|
23 |
+
author = {Benjamin Kilimnik},
|
24 |
+
title = {{Privy} Synthetic PII Protocol Trace Dataset},
|
25 |
+
year = 2022,
|
26 |
+
url = {https://huggingface.co/datasets/beki/privy},
|
27 |
+
}
|
28 |
+
"""
|
29 |
+
|
30 |
+
_HOMEPAGE = "https://github.com/pixie-io/pixie/tree/main/src/datagen/pii/privy/privy"
|
31 |
+
|
32 |
+
_LICENSE = "MIT"
|
33 |
+
|
34 |
+
class NewDataset(datasets.GeneratorBasedBuilder):
|
35 |
+
VERSION = datasets.Version("1.0.0")
|
36 |
+
|
37 |
+
# You will be able to load one or the other configurations in the following list with
|
38 |
+
# data = datasets.load_dataset('my_dataset', 'first_domain')
|
39 |
+
# data = datasets.load_dataset('my_dataset', 'second_domain')
|
40 |
+
BUILDER_CONFIGS = [
|
41 |
+
datasets.BuilderConfig(name="small", version=VERSION, description="Privy small"),
|
42 |
+
datasets.BuilderConfig(name="large", version=VERSION, description="Privy large"),
|
43 |
+
]
|
44 |
+
|
45 |
+
DEFAULT_CONFIG_NAME = "small"
|
46 |
+
|
47 |
+
def _info(self):
|
48 |
+
features = datasets.Features(
|
49 |
+
{
|
50 |
+
"full_text": datasets.Value("string"),
|
51 |
+
"masked": datasets.Value("string"),
|
52 |
+
"spans": datasets.Sequence(datasets.Value("string")),
|
53 |
+
"tags": datasets.Sequence(
|
54 |
+
datasets.features.ClassLabel(
|
55 |
+
names=[
|
56 |
+
"O",
|
57 |
+
"B-O",
|
58 |
+
"I-O",
|
59 |
+
"L-O",
|
60 |
+
"U-O",
|
61 |
+
|
62 |
+
"B-PER",
|
63 |
+
"I-PER",
|
64 |
+
"L-PER",
|
65 |
+
"U-PER",
|
66 |
+
|
67 |
+
"B-LOC",
|
68 |
+
"I-LOC",
|
69 |
+
"L-LOC",
|
70 |
+
"U-LOC",
|
71 |
+
|
72 |
+
"B-ORG",
|
73 |
+
"I-ORG",
|
74 |
+
"L-ORG",
|
75 |
+
"U-ORG",
|
76 |
+
|
77 |
+
"B-NRP",
|
78 |
+
"I-NRP",
|
79 |
+
"L-NRP",
|
80 |
+
"U-NRP",
|
81 |
+
|
82 |
+
"B-DATE_TIME",
|
83 |
+
"I-DATE_TIME",
|
84 |
+
"L-DATE_TIME",
|
85 |
+
"U-DATE_TIME",
|
86 |
+
|
87 |
+
"B-CREDIT_CARD",
|
88 |
+
"I-CREDIT_CARD",
|
89 |
+
"L-CREDIT_CARD",
|
90 |
+
"U-CREDIT_CARD",
|
91 |
+
|
92 |
+
"B-URL",
|
93 |
+
"I-URL",
|
94 |
+
"L-URL",
|
95 |
+
"U-URL",
|
96 |
+
|
97 |
+
"B-IBAN_CODE",
|
98 |
+
"I-IBAN_CODE",
|
99 |
+
"L-IBAN_CODE",
|
100 |
+
"U-IBAN_CODE",
|
101 |
+
|
102 |
+
"B-US_BANK_NUMBER",
|
103 |
+
"I-US_BANK_NUMBER",
|
104 |
+
"L-US_BANK_NUMBER",
|
105 |
+
"U-US_BANK_NUMBER",
|
106 |
+
|
107 |
+
"B-PHONE_NUMBER",
|
108 |
+
"I-PHONE_NUMBER",
|
109 |
+
"L-PHONE_NUMBER",
|
110 |
+
"U-PHONE_NUMBER",
|
111 |
+
|
112 |
+
"B-US_SSN",
|
113 |
+
"I-US_SSN",
|
114 |
+
"L-US_SSN",
|
115 |
+
"U-US_SSN",
|
116 |
+
|
117 |
+
"B-US_PASSPORT",
|
118 |
+
"I-US_PASSPORT",
|
119 |
+
"L-US_PASSPORT",
|
120 |
+
"U-US_PASSPORT",
|
121 |
+
|
122 |
+
"B-US_DRIVER_LICENSE",
|
123 |
+
"I-US_DRIVER_LICENSE",
|
124 |
+
"L-US_DRIVER_LICENSE",
|
125 |
+
"U-US_DRIVER_LICENSE",
|
126 |
+
|
127 |
+
"B-US_LICENSE_PLATE",
|
128 |
+
"I-US_LICENSE_PLATE",
|
129 |
+
"L-US_LICENSE_PLATE",
|
130 |
+
"U-US_LICENSE_PLATE",
|
131 |
+
|
132 |
+
"B-IP_ADDRESS",
|
133 |
+
"I-IP_ADDRESS",
|
134 |
+
"L-IP_ADDRESS",
|
135 |
+
"U-IP_ADDRESS",
|
136 |
+
|
137 |
+
"B-US_ITIN",
|
138 |
+
"I-US_ITIN",
|
139 |
+
"L-US_ITIN",
|
140 |
+
"U-US_ITIN",
|
141 |
+
|
142 |
+
"B-EMAIL_ADDRESS",
|
143 |
+
"I-EMAIL_ADDRESS",
|
144 |
+
"L-EMAIL_ADDRESS",
|
145 |
+
"U-EMAIL_ADDRESS",
|
146 |
+
|
147 |
+
"B-ORGANIZATION",
|
148 |
+
"I-ORGANIZATION",
|
149 |
+
"L-ORGANIZATION",
|
150 |
+
"U-ORGANIZATION",
|
151 |
+
|
152 |
+
"B-TITLE",
|
153 |
+
"I-TITLE",
|
154 |
+
"L-TITLE",
|
155 |
+
"U-TITLE",
|
156 |
+
|
157 |
+
"B-COORDINATE",
|
158 |
+
"I-COORDINATE",
|
159 |
+
"L-COORDINATE",
|
160 |
+
"U-COORDINATE",
|
161 |
+
|
162 |
+
"B-IMEI",
|
163 |
+
"I-IMEI",
|
164 |
+
"L-IMEI",
|
165 |
+
"U-IMEI",
|
166 |
+
|
167 |
+
"B-PASSWORD",
|
168 |
+
"I-PASSWORD",
|
169 |
+
"L-PASSWORD",
|
170 |
+
"U-PASSWORD",
|
171 |
+
|
172 |
+
"B-LICENSE_PLATE",
|
173 |
+
"I-LICENSE_PLATE",
|
174 |
+
"L-LICENSE_PLATE",
|
175 |
+
"U-LICENSE_PLATE",
|
176 |
+
|
177 |
+
"B-CURRENCY",
|
178 |
+
"I-CURRENCY",
|
179 |
+
"L-CURRENCY",
|
180 |
+
"U-CURRENCY",
|
181 |
+
|
182 |
+
"B-FINANCIAL",
|
183 |
+
"I-FINANCIAL",
|
184 |
+
"L-FINANCIAL",
|
185 |
+
"U-FINANCIAL",
|
186 |
+
|
187 |
+
"B-ROUTING_NUMBER",
|
188 |
+
"I-ROUTING_NUMBER",
|
189 |
+
"L-ROUTING_NUMBER",
|
190 |
+
"U-ROUTING_NUMBER",
|
191 |
+
|
192 |
+
"B-SWIFT_CODE",
|
193 |
+
"I-SWIFT_CODE",
|
194 |
+
"L-SWIFT_CODE",
|
195 |
+
"U-SWIFT_CODE",
|
196 |
+
|
197 |
+
"B-MAC_ADDRESS",
|
198 |
+
"I-MAC_ADDRESS",
|
199 |
+
"L-MAC_ADDRESS",
|
200 |
+
"U-MAC_ADDRESS",
|
201 |
+
|
202 |
+
"B-AGE",
|
203 |
+
"I-AGE",
|
204 |
+
"L-AGE",
|
205 |
+
"U-AGE",
|
206 |
+
]
|
207 |
+
)
|
208 |
+
),
|
209 |
+
"tokens": datasets.Sequence(datasets.Value("string")),
|
210 |
+
"template_id": datasets.Value("int32"),
|
211 |
+
"metadata": datasets.Value("int32"),
|
212 |
+
}
|
213 |
+
)
|
214 |
+
|
215 |
+
return datasets.DatasetInfo(
|
216 |
+
description=_DESCRIPTION,
|
217 |
+
features=features,
|
218 |
+
# supervised_keys=("sentence", "label"),
|
219 |
+
# Homepage of the dataset for documentation
|
220 |
+
homepage=_HOMEPAGE,
|
221 |
+
# License for the dataset if available
|
222 |
+
license=_LICENSE,
|
223 |
+
# Citation for the dataset
|
224 |
+
citation=_CITATION,
|
225 |
+
)
|
226 |
+
|
227 |
+
def _split_generators(self, dl_manager):
|
228 |
+
data_dir = "./"
|
229 |
+
size = "small"
|
230 |
+
if self.config.name == "large": # This is the name of the configuration selected in BUILDER_CONFIGS above
|
231 |
+
size = "large"
|
232 |
+
return [
|
233 |
+
datasets.SplitGenerator(
|
234 |
+
name=datasets.Split.TRAIN,
|
235 |
+
# These kwargs will be passed to _generate_examples
|
236 |
+
gen_kwargs={
|
237 |
+
"filepath": os.path.join(data_dir, f"train-{size}.json"),
|
238 |
+
"split": "train",
|
239 |
+
},
|
240 |
+
),
|
241 |
+
datasets.SplitGenerator(
|
242 |
+
name=datasets.Split.VALIDATION,
|
243 |
+
# These kwargs will be passed to _generate_examples
|
244 |
+
gen_kwargs={
|
245 |
+
"filepath": os.path.join(data_dir, f"dev-{size}.json"),
|
246 |
+
"split": "dev",
|
247 |
+
},
|
248 |
+
),
|
249 |
+
datasets.SplitGenerator(
|
250 |
+
name=datasets.Split.TEST,
|
251 |
+
# These kwargs will be passed to _generate_examples
|
252 |
+
gen_kwargs={
|
253 |
+
"filepath": os.path.join(data_dir, f"test-{size}.json"),
|
254 |
+
"split": "test"
|
255 |
+
},
|
256 |
+
),
|
257 |
+
]
|
258 |
+
|
259 |
+
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
260 |
+
def _generate_examples(self, filepath, split):
|
261 |
+
# The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
|
262 |
+
with open(filepath, encoding="utf-8") as f:
|
263 |
+
dataset = json.load(f)
|
264 |
+
for key, row in enumerate(dataset):
|
265 |
+
# Yields examples as (key, example) tuples
|
266 |
+
yield key, {
|
267 |
+
"tokens": row["tokens"],
|
268 |
+
"tags": row["tags"],
|
269 |
+
"full_text": row["full_text"],
|
270 |
+
"spans": row["spans"],
|
271 |
+
"masked": row["masked"],
|
272 |
+
"template_id": row["template_id"],
|
273 |
+
"metadata": row["metadata"],
|
274 |
+
}
|