Add custom processor
Browse filesAdd a custom processor to parse HTML.
- added_tokens.json +4 -0
- merges.txt +0 -0
- preprocessor_config.json +7 -0
- processor.py +96 -0
- processor_config.json +6 -0
- special_tokens_map.json +51 -0
- tokenizer.json +0 -0
- tokenizer_config.json +299 -0
- vocab.json +0 -0
added_tokens.json
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"<end-of-node>": 50266,
|
3 |
+
"[empty-title]": 50265
|
4 |
+
}
|
merges.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
preprocessor_config.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"auto_map": {
|
3 |
+
"AutoProcessor": "processor.MarkupLMPhishProcessor"
|
4 |
+
},
|
5 |
+
"feature_extractor_type": "MarkupLMFeatureExtractor",
|
6 |
+
"processor_class": "MarkupLMPhishProcessor"
|
7 |
+
}
|
processor.py
ADDED
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Optional, Union
|
2 |
+
|
3 |
+
import transformers
|
4 |
+
from bs4 import BeautifulSoup
|
5 |
+
|
6 |
+
|
7 |
+
class MarkupLMPhishProcessor(transformers.MarkupLMProcessor):
|
8 |
+
def __init__(self, *args, **kwargs):
|
9 |
+
super().__init__(*args, **kwargs)
|
10 |
+
self.keep_tags_ctx = [
|
11 |
+
"html",
|
12 |
+
"head",
|
13 |
+
"body",
|
14 |
+
"h1",
|
15 |
+
"h2",
|
16 |
+
"h3",
|
17 |
+
"h4",
|
18 |
+
"h5",
|
19 |
+
"h6",
|
20 |
+
"p",
|
21 |
+
"a",
|
22 |
+
"button",
|
23 |
+
"span",
|
24 |
+
"div",
|
25 |
+
"iframe",
|
26 |
+
"table",
|
27 |
+
]
|
28 |
+
|
29 |
+
def _preprocess(self, html_string: str):
|
30 |
+
# Most webpages are huge. BERT's "attention" is limited to 512 tokens.
|
31 |
+
# In order to give the model more context to work with, we strip extraneous
|
32 |
+
# tags/content from the page to help with the binary classification task.
|
33 |
+
soup = BeautifulSoup(html_string, "html.parser")
|
34 |
+
for tag in soup.find_all(True):
|
35 |
+
if tag.name in ("style", "script"):
|
36 |
+
# keep the meaning of the tag, but remove its contents to save space
|
37 |
+
tag.string = ""
|
38 |
+
elif tag.name not in self.keep_tags_ctx:
|
39 |
+
# remove tag, but keep its contents
|
40 |
+
tag.unwrap()
|
41 |
+
return str(soup)
|
42 |
+
|
43 |
+
def __call__(
|
44 |
+
self,
|
45 |
+
html_strings=None,
|
46 |
+
nodes=None,
|
47 |
+
xpaths=None,
|
48 |
+
node_labels=None,
|
49 |
+
questions=None,
|
50 |
+
add_special_tokens: bool = True,
|
51 |
+
padding: Union[bool, str, transformers.utils.generic.PaddingStrategy] = False,
|
52 |
+
truncation: Union[
|
53 |
+
bool, str, transformers.tokenization_utils_base.TruncationStrategy
|
54 |
+
] = None,
|
55 |
+
max_length: Optional[int] = None,
|
56 |
+
stride: int = 0,
|
57 |
+
pad_to_multiple_of: Optional[int] = None,
|
58 |
+
return_token_type_ids: Optional[bool] = None,
|
59 |
+
return_attention_mask: Optional[bool] = None,
|
60 |
+
return_overflowing_tokens: bool = False,
|
61 |
+
return_special_tokens_mask: bool = False,
|
62 |
+
return_offsets_mapping: bool = False,
|
63 |
+
return_length: bool = False,
|
64 |
+
verbose: bool = True,
|
65 |
+
return_tensors: Union[str, transformers.utils.generic.TensorType] = None,
|
66 |
+
**kwargs,
|
67 |
+
) -> transformers.tokenization_utils_base.BatchEncoding:
|
68 |
+
# custom html_strings preprocessing
|
69 |
+
if html_strings is not None:
|
70 |
+
if isinstance(html_strings, list):
|
71 |
+
html_strings = [self._preprocess(hs) for hs in html_strings]
|
72 |
+
elif isinstance(html_strings, str):
|
73 |
+
html_strings = self._preprocess(html_strings)
|
74 |
+
# invoke the parent method
|
75 |
+
return super().__call__(
|
76 |
+
html_strings,
|
77 |
+
nodes,
|
78 |
+
xpaths,
|
79 |
+
node_labels,
|
80 |
+
questions,
|
81 |
+
add_special_tokens,
|
82 |
+
padding,
|
83 |
+
truncation,
|
84 |
+
max_length,
|
85 |
+
stride,
|
86 |
+
pad_to_multiple_of,
|
87 |
+
return_token_type_ids,
|
88 |
+
return_attention_mask,
|
89 |
+
return_overflowing_tokens,
|
90 |
+
return_special_tokens_mask,
|
91 |
+
return_offsets_mapping,
|
92 |
+
return_length,
|
93 |
+
verbose,
|
94 |
+
return_tensors,
|
95 |
+
**kwargs,
|
96 |
+
)
|
processor_config.json
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"auto_map": {
|
3 |
+
"AutoProcessor": "processor.MarkupLMPhishProcessor"
|
4 |
+
},
|
5 |
+
"processor_class": "MarkupLMPhishProcessor"
|
6 |
+
}
|
special_tokens_map.json
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bos_token": {
|
3 |
+
"content": "<s>",
|
4 |
+
"lstrip": false,
|
5 |
+
"normalized": false,
|
6 |
+
"rstrip": false,
|
7 |
+
"single_word": false
|
8 |
+
},
|
9 |
+
"cls_token": {
|
10 |
+
"content": "<s>",
|
11 |
+
"lstrip": false,
|
12 |
+
"normalized": false,
|
13 |
+
"rstrip": false,
|
14 |
+
"single_word": false
|
15 |
+
},
|
16 |
+
"eos_token": {
|
17 |
+
"content": "</s>",
|
18 |
+
"lstrip": false,
|
19 |
+
"normalized": false,
|
20 |
+
"rstrip": false,
|
21 |
+
"single_word": false
|
22 |
+
},
|
23 |
+
"mask_token": {
|
24 |
+
"content": "<mask>",
|
25 |
+
"lstrip": true,
|
26 |
+
"normalized": false,
|
27 |
+
"rstrip": false,
|
28 |
+
"single_word": false
|
29 |
+
},
|
30 |
+
"pad_token": {
|
31 |
+
"content": "<pad>",
|
32 |
+
"lstrip": false,
|
33 |
+
"normalized": false,
|
34 |
+
"rstrip": false,
|
35 |
+
"single_word": false
|
36 |
+
},
|
37 |
+
"sep_token": {
|
38 |
+
"content": "</s>",
|
39 |
+
"lstrip": false,
|
40 |
+
"normalized": false,
|
41 |
+
"rstrip": false,
|
42 |
+
"single_word": false
|
43 |
+
},
|
44 |
+
"unk_token": {
|
45 |
+
"content": "<unk>",
|
46 |
+
"lstrip": false,
|
47 |
+
"normalized": false,
|
48 |
+
"rstrip": false,
|
49 |
+
"single_word": false
|
50 |
+
}
|
51 |
+
}
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
ADDED
@@ -0,0 +1,299 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"add_prefix_space": false,
|
3 |
+
"added_tokens_decoder": {
|
4 |
+
"0": {
|
5 |
+
"content": "<s>",
|
6 |
+
"lstrip": false,
|
7 |
+
"normalized": false,
|
8 |
+
"rstrip": false,
|
9 |
+
"single_word": false,
|
10 |
+
"special": true
|
11 |
+
},
|
12 |
+
"1": {
|
13 |
+
"content": "<pad>",
|
14 |
+
"lstrip": false,
|
15 |
+
"normalized": false,
|
16 |
+
"rstrip": false,
|
17 |
+
"single_word": false,
|
18 |
+
"special": true
|
19 |
+
},
|
20 |
+
"2": {
|
21 |
+
"content": "</s>",
|
22 |
+
"lstrip": false,
|
23 |
+
"normalized": false,
|
24 |
+
"rstrip": false,
|
25 |
+
"single_word": false,
|
26 |
+
"special": true
|
27 |
+
},
|
28 |
+
"3": {
|
29 |
+
"content": "<unk>",
|
30 |
+
"lstrip": false,
|
31 |
+
"normalized": false,
|
32 |
+
"rstrip": false,
|
33 |
+
"single_word": false,
|
34 |
+
"special": true
|
35 |
+
},
|
36 |
+
"50264": {
|
37 |
+
"content": "<mask>",
|
38 |
+
"lstrip": true,
|
39 |
+
"normalized": false,
|
40 |
+
"rstrip": false,
|
41 |
+
"single_word": false,
|
42 |
+
"special": true
|
43 |
+
},
|
44 |
+
"50265": {
|
45 |
+
"content": "[empty-title]",
|
46 |
+
"lstrip": false,
|
47 |
+
"normalized": true,
|
48 |
+
"rstrip": false,
|
49 |
+
"single_word": false,
|
50 |
+
"special": false
|
51 |
+
},
|
52 |
+
"50266": {
|
53 |
+
"content": "<end-of-node>",
|
54 |
+
"lstrip": false,
|
55 |
+
"normalized": true,
|
56 |
+
"rstrip": false,
|
57 |
+
"single_word": false,
|
58 |
+
"special": false
|
59 |
+
}
|
60 |
+
},
|
61 |
+
"auto_map": {
|
62 |
+
"AutoProcessor": "processor.MarkupLMPhishProcessor"
|
63 |
+
},
|
64 |
+
"bos_token": "<s>",
|
65 |
+
"clean_up_tokenization_spaces": true,
|
66 |
+
"cls_token": "<s>",
|
67 |
+
"eos_token": "</s>",
|
68 |
+
"errors": "replace",
|
69 |
+
"mask_token": "<mask>",
|
70 |
+
"max_depth": 50,
|
71 |
+
"max_width": 1000,
|
72 |
+
"model_max_length": 512,
|
73 |
+
"only_label_first_subword": true,
|
74 |
+
"pad_token": "<pad>",
|
75 |
+
"pad_token_label": -100,
|
76 |
+
"pad_width": 1001,
|
77 |
+
"processor_class": "MarkupLMPhishProcessor",
|
78 |
+
"sep_token": "</s>",
|
79 |
+
"tags_dict": {
|
80 |
+
"a": 0,
|
81 |
+
"abbr": 1,
|
82 |
+
"acronym": 2,
|
83 |
+
"address": 3,
|
84 |
+
"altGlyph": 4,
|
85 |
+
"altGlyphDef": 5,
|
86 |
+
"altGlyphItem": 6,
|
87 |
+
"animate": 7,
|
88 |
+
"animateColor": 8,
|
89 |
+
"animateMotion": 9,
|
90 |
+
"animateTransform": 10,
|
91 |
+
"applet": 11,
|
92 |
+
"area": 12,
|
93 |
+
"article": 13,
|
94 |
+
"aside": 14,
|
95 |
+
"audio": 15,
|
96 |
+
"b": 16,
|
97 |
+
"base": 17,
|
98 |
+
"basefont": 18,
|
99 |
+
"bdi": 19,
|
100 |
+
"bdo": 20,
|
101 |
+
"bgsound": 21,
|
102 |
+
"big": 22,
|
103 |
+
"blink": 23,
|
104 |
+
"blockquote": 24,
|
105 |
+
"body": 25,
|
106 |
+
"br": 26,
|
107 |
+
"button": 27,
|
108 |
+
"canvas": 28,
|
109 |
+
"caption": 29,
|
110 |
+
"center": 30,
|
111 |
+
"circle": 31,
|
112 |
+
"cite": 32,
|
113 |
+
"clipPath": 33,
|
114 |
+
"code": 34,
|
115 |
+
"col": 35,
|
116 |
+
"colgroup": 36,
|
117 |
+
"color-profile": 37,
|
118 |
+
"content": 38,
|
119 |
+
"cursor": 39,
|
120 |
+
"data": 40,
|
121 |
+
"datalist": 41,
|
122 |
+
"dd": 42,
|
123 |
+
"defs": 43,
|
124 |
+
"del": 44,
|
125 |
+
"desc": 45,
|
126 |
+
"details": 46,
|
127 |
+
"dfn": 47,
|
128 |
+
"dialog": 48,
|
129 |
+
"dir": 49,
|
130 |
+
"div": 50,
|
131 |
+
"dl": 51,
|
132 |
+
"dt": 52,
|
133 |
+
"ellipse": 53,
|
134 |
+
"em": 54,
|
135 |
+
"embed": 55,
|
136 |
+
"feBlend": 56,
|
137 |
+
"feColorMatrix": 57,
|
138 |
+
"feComponentTransfer": 58,
|
139 |
+
"feComposite": 59,
|
140 |
+
"feConvolveMatrix": 60,
|
141 |
+
"feDiffuseLighting": 61,
|
142 |
+
"feDisplacementMap": 62,
|
143 |
+
"feDistantLight": 63,
|
144 |
+
"feFlood": 64,
|
145 |
+
"feFuncA": 65,
|
146 |
+
"feFuncB": 66,
|
147 |
+
"feFuncG": 67,
|
148 |
+
"feFuncR": 68,
|
149 |
+
"feGaussianBlur": 69,
|
150 |
+
"feImage": 70,
|
151 |
+
"feMerge": 71,
|
152 |
+
"feMergeNode": 72,
|
153 |
+
"feMorphology": 73,
|
154 |
+
"feOffset": 74,
|
155 |
+
"fePointLight": 75,
|
156 |
+
"feSpecularLighting": 76,
|
157 |
+
"feSpotLight": 77,
|
158 |
+
"feTile": 78,
|
159 |
+
"feTurbulence": 79,
|
160 |
+
"fieldset": 80,
|
161 |
+
"figcaption": 81,
|
162 |
+
"figure": 82,
|
163 |
+
"filter": 83,
|
164 |
+
"font": 89,
|
165 |
+
"font-face": 88,
|
166 |
+
"font-face-format": 84,
|
167 |
+
"font-face-name": 85,
|
168 |
+
"font-face-src": 86,
|
169 |
+
"font-face-uri": 87,
|
170 |
+
"footer": 90,
|
171 |
+
"foreignObject": 91,
|
172 |
+
"form": 92,
|
173 |
+
"frame": 93,
|
174 |
+
"frameset": 94,
|
175 |
+
"g": 95,
|
176 |
+
"glyph": 96,
|
177 |
+
"glyphRef": 97,
|
178 |
+
"h1": 98,
|
179 |
+
"h2": 99,
|
180 |
+
"h3": 100,
|
181 |
+
"h4": 101,
|
182 |
+
"h5": 102,
|
183 |
+
"h6": 103,
|
184 |
+
"head": 104,
|
185 |
+
"header": 105,
|
186 |
+
"hgroup": 106,
|
187 |
+
"hkern": 107,
|
188 |
+
"hr": 108,
|
189 |
+
"html": 109,
|
190 |
+
"i": 110,
|
191 |
+
"iframe": 111,
|
192 |
+
"image": 112,
|
193 |
+
"img": 113,
|
194 |
+
"input": 114,
|
195 |
+
"ins": 115,
|
196 |
+
"kbd": 116,
|
197 |
+
"keygen": 117,
|
198 |
+
"label": 118,
|
199 |
+
"legend": 119,
|
200 |
+
"li": 120,
|
201 |
+
"line": 121,
|
202 |
+
"linearGradient": 122,
|
203 |
+
"link": 123,
|
204 |
+
"main": 124,
|
205 |
+
"map": 125,
|
206 |
+
"mark": 126,
|
207 |
+
"marker": 127,
|
208 |
+
"marquee": 128,
|
209 |
+
"mask": 129,
|
210 |
+
"math": 130,
|
211 |
+
"menu": 131,
|
212 |
+
"menuitem": 132,
|
213 |
+
"meta": 133,
|
214 |
+
"metadata": 134,
|
215 |
+
"meter": 135,
|
216 |
+
"missing-glyph": 136,
|
217 |
+
"mpath": 137,
|
218 |
+
"nav": 138,
|
219 |
+
"nobr": 139,
|
220 |
+
"noembed": 140,
|
221 |
+
"noframes": 141,
|
222 |
+
"noscript": 142,
|
223 |
+
"object": 143,
|
224 |
+
"ol": 144,
|
225 |
+
"optgroup": 145,
|
226 |
+
"option": 146,
|
227 |
+
"output": 147,
|
228 |
+
"p": 148,
|
229 |
+
"param": 149,
|
230 |
+
"path": 150,
|
231 |
+
"pattern": 151,
|
232 |
+
"picture": 152,
|
233 |
+
"plaintext": 153,
|
234 |
+
"polygon": 154,
|
235 |
+
"polyline": 155,
|
236 |
+
"portal": 156,
|
237 |
+
"pre": 157,
|
238 |
+
"progress": 158,
|
239 |
+
"q": 159,
|
240 |
+
"radialGradient": 160,
|
241 |
+
"rb": 161,
|
242 |
+
"rect": 162,
|
243 |
+
"rp": 163,
|
244 |
+
"rt": 164,
|
245 |
+
"rtc": 165,
|
246 |
+
"ruby": 166,
|
247 |
+
"s": 167,
|
248 |
+
"samp": 168,
|
249 |
+
"script": 169,
|
250 |
+
"section": 170,
|
251 |
+
"select": 171,
|
252 |
+
"set": 172,
|
253 |
+
"shadow": 173,
|
254 |
+
"slot": 174,
|
255 |
+
"small": 175,
|
256 |
+
"source": 176,
|
257 |
+
"spacer": 177,
|
258 |
+
"span": 178,
|
259 |
+
"stop": 179,
|
260 |
+
"strike": 180,
|
261 |
+
"strong": 181,
|
262 |
+
"style": 182,
|
263 |
+
"sub": 183,
|
264 |
+
"summary": 184,
|
265 |
+
"sup": 185,
|
266 |
+
"svg": 186,
|
267 |
+
"switch": 187,
|
268 |
+
"symbol": 188,
|
269 |
+
"table": 189,
|
270 |
+
"tbody": 190,
|
271 |
+
"td": 191,
|
272 |
+
"template": 192,
|
273 |
+
"text": 193,
|
274 |
+
"textPath": 194,
|
275 |
+
"textarea": 195,
|
276 |
+
"tfoot": 196,
|
277 |
+
"th": 197,
|
278 |
+
"thead": 198,
|
279 |
+
"time": 199,
|
280 |
+
"title": 200,
|
281 |
+
"tr": 201,
|
282 |
+
"track": 202,
|
283 |
+
"tref": 203,
|
284 |
+
"tspan": 204,
|
285 |
+
"tt": 205,
|
286 |
+
"u": 206,
|
287 |
+
"ul": 207,
|
288 |
+
"use": 208,
|
289 |
+
"var": 209,
|
290 |
+
"video": 210,
|
291 |
+
"view": 211,
|
292 |
+
"vkern": 212,
|
293 |
+
"wbr": 213,
|
294 |
+
"xmp": 214
|
295 |
+
},
|
296 |
+
"tokenizer_class": "MarkupLMTokenizer",
|
297 |
+
"trim_offsets": false,
|
298 |
+
"unk_token": "<unk>"
|
299 |
+
}
|
vocab.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|