dungeon29 commited on
Commit
d6eb8ec
·
verified ·
1 Parent(s): 49ead36

Upload custom DeBERTa+LSTM model trained for Phishing Detection

Browse files
config.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "attention_probs_dropout_prob": 0.1,
3
+ "dtype": "float32",
4
+ "hidden_act": "gelu",
5
+ "hidden_dropout_prob": 0.1,
6
+ "hidden_size": 768,
7
+ "initializer_range": 0.02,
8
+ "intermediate_size": 3072,
9
+ "layer_norm_eps": 1e-07,
10
+ "legacy": true,
11
+ "max_position_embeddings": 512,
12
+ "max_relative_positions": -1,
13
+ "model_type": "deberta",
14
+ "num_attention_heads": 12,
15
+ "num_hidden_layers": 12,
16
+ "pad_token_id": 0,
17
+ "pooler_dropout": 0,
18
+ "pooler_hidden_act": "gelu",
19
+ "pooler_hidden_size": 768,
20
+ "pos_att_type": [
21
+ "c2p",
22
+ "p2c"
23
+ ],
24
+ "position_biased_input": false,
25
+ "relative_attention": true,
26
+ "transformers_version": "4.57.1",
27
+ "type_vocab_size": 0,
28
+ "vocab_size": 50265
29
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model_class.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import torch
3
+ import torch.nn as nn
4
+ import torch.nn.functional as F
5
+ from transformers import AutoModel
6
+
7
+ class DeBERTaLSTMClassifier(nn.Module):
8
+ def __init__(self, hidden_dim=128, num_labels=2):
9
+ super().__init__()
10
+
11
+ self.deberta = AutoModel.from_pretrained("microsoft/deberta-base")
12
+ for param in self.deberta.parameters():
13
+ param.requires_grad = False # freeze DeBERTa (as we don't have enough resources, we will not train DeBERTa in this model)
14
+
15
+ self.lstm = nn.LSTM(
16
+ input_size=self.deberta.config.hidden_size,
17
+ hidden_size=hidden_dim,
18
+ batch_first=True,
19
+ bidirectional=True
20
+ )
21
+
22
+ self.fc = nn.Linear(hidden_dim * 2, num_labels)
23
+
24
+ # Attention layer để tính token importance
25
+ self.attention = nn.Linear(hidden_dim * 2, 1)
26
+
27
+ def forward(self, input_ids, attention_mask, return_attention=False):
28
+ with torch.no_grad():
29
+ outputs = self.deberta(input_ids=input_ids, attention_mask=attention_mask, output_attentions=True)
30
+
31
+ lstm_out, _ = self.lstm(outputs.last_hidden_state) # shape: [batch, seq_len, hidden*2]
32
+
33
+ if return_attention:
34
+ # Tính attention weights cho từng token
35
+ attention_weights = self.attention(lstm_out) # [batch, seq_len, 1]
36
+ attention_weights = F.softmax(attention_weights.squeeze(-1), dim=-1) # [batch, seq_len]
37
+
38
+ # Apply attention mask
39
+ attention_weights = attention_weights * attention_mask.float()
40
+ attention_weights = attention_weights / (attention_weights.sum(dim=-1, keepdim=True) + 1e-8)
41
+
42
+ # Weighted sum of LSTM outputs
43
+ attended_output = torch.sum(lstm_out * attention_weights.unsqueeze(-1), dim=1)
44
+ logits = self.fc(attended_output)
45
+
46
+ return logits, attention_weights, outputs.attentions
47
+ else:
48
+ final_hidden = lstm_out[:, -1, :] # last token output
49
+ logits = self.fc(final_hidden)
50
+ return logits
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c3d00725e0888899c3f84d074260d32f67daddf565111194a3426c9b1c8431e7
3
+ size 558172799
special_tokens_map.json ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "[CLS]",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "cls_token": {
10
+ "content": "[CLS]",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "eos_token": {
17
+ "content": "[SEP]",
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": true,
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": "[SEP]",
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,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": false,
3
+ "add_prefix_space": false,
4
+ "added_tokens_decoder": {
5
+ "0": {
6
+ "content": "[PAD]",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "1": {
14
+ "content": "[CLS]",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "2": {
22
+ "content": "[SEP]",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false,
27
+ "special": true
28
+ },
29
+ "3": {
30
+ "content": "[UNK]",
31
+ "lstrip": false,
32
+ "normalized": false,
33
+ "rstrip": false,
34
+ "single_word": false,
35
+ "special": true
36
+ },
37
+ "50264": {
38
+ "content": "[MASK]",
39
+ "lstrip": true,
40
+ "normalized": true,
41
+ "rstrip": false,
42
+ "single_word": false,
43
+ "special": true
44
+ }
45
+ },
46
+ "bos_token": "[CLS]",
47
+ "clean_up_tokenization_spaces": false,
48
+ "cls_token": "[CLS]",
49
+ "do_lower_case": false,
50
+ "eos_token": "[SEP]",
51
+ "errors": "replace",
52
+ "extra_special_tokens": {},
53
+ "mask_token": "[MASK]",
54
+ "model_max_length": 1000000000000000019884624838656,
55
+ "pad_token": "[PAD]",
56
+ "sep_token": "[SEP]",
57
+ "tokenizer_class": "DebertaTokenizer",
58
+ "unk_token": "[UNK]",
59
+ "vocab_type": "gpt2"
60
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff