hplisiecki
commited on
Commit
•
42c8d28
1
Parent(s):
d0056ce
Upload 8 files
Browse files- config.json +27 -0
- model.safetensors +3 -0
- model_script.py +46 -0
- pytorch_model.bin +3 -0
- special_tokens_map.json +7 -0
- tokenizer.json +0 -0
- tokenizer_config.json +58 -0
- vocab.txt +0 -0
config.json
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "nghuyong/ernie-2.0-en",
|
3 |
+
"architectures": [
|
4 |
+
"ErnieModel"
|
5 |
+
],
|
6 |
+
"attention_probs_dropout_prob": 0.1,
|
7 |
+
"classifier_dropout": null,
|
8 |
+
"hidden_act": "gelu",
|
9 |
+
"hidden_dropout_prob": 0.1,
|
10 |
+
"hidden_size": 768,
|
11 |
+
"initializer_range": 0.02,
|
12 |
+
"intermediate_size": 3072,
|
13 |
+
"layer_norm_eps": 1e-05,
|
14 |
+
"max_position_embeddings": 512,
|
15 |
+
"model_type": "ernie",
|
16 |
+
"num_attention_heads": 12,
|
17 |
+
"num_hidden_layers": 12,
|
18 |
+
"pad_token_id": 0,
|
19 |
+
"position_embedding_type": "absolute",
|
20 |
+
"task_type_vocab_size": 3,
|
21 |
+
"torch_dtype": "float32",
|
22 |
+
"transformers_version": "4.41.2",
|
23 |
+
"type_vocab_size": 4,
|
24 |
+
"use_cache": true,
|
25 |
+
"use_task_id": false,
|
26 |
+
"vocab_size": 30522
|
27 |
+
}
|
model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:12225c02cc4446eaa03938fab97aae95b9475d666b926d54d2185b3d9057d02e
|
3 |
+
size 437957472
|
model_script.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from torch import nn
|
3 |
+
from transformers import AutoModel
|
4 |
+
|
5 |
+
class CustomModel(torch.nn.Module):
|
6 |
+
def __init__(self, model_path, dropout=0.1, hidden_dim=768):
|
7 |
+
super().__init__()
|
8 |
+
self.metric_names = ['valence', 'arousal', 'dominance', 'aoa', 'concreteness']
|
9 |
+
self.dropout_rate = dropout
|
10 |
+
self.hidden_dim = hidden_dim
|
11 |
+
|
12 |
+
self.bert = AutoModel.from_pretrained(model_path)
|
13 |
+
|
14 |
+
for name in self.metric_names:
|
15 |
+
setattr(self, name, nn.Linear(hidden_dim, 1))
|
16 |
+
setattr(self, 'l_1_' + name, nn.Linear(hidden_dim, hidden_dim))
|
17 |
+
|
18 |
+
self.layer_norm = nn.LayerNorm(self.hidden_dim)
|
19 |
+
self.relu = nn.ReLU()
|
20 |
+
self.dropout = nn.Dropout(self.dropout_rate)
|
21 |
+
self.sigmoid = nn.Sigmoid()
|
22 |
+
|
23 |
+
def save_pretrained(self, save_directory):
|
24 |
+
self.bert.save_pretrained(save_directory)
|
25 |
+
torch.save(self.state_dict(), f'{save_directory}/pytorch_model.bin')
|
26 |
+
|
27 |
+
@classmethod
|
28 |
+
def from_pretrained(cls, model_dir, dropout=0.2, hidden_dim=768):
|
29 |
+
model = cls(model_dir, dropout, hidden_dim)
|
30 |
+
state_dict = torch.load(f'{model_dir}/pytorch_model.bin', map_location=torch.device('cpu'))
|
31 |
+
model.load_state_dict(state_dict)
|
32 |
+
return model
|
33 |
+
|
34 |
+
def forward(self, *args):
|
35 |
+
_, x = self.bert(*args, return_dict=False)
|
36 |
+
output = self.rate_embedding(x)
|
37 |
+
return output
|
38 |
+
|
39 |
+
def rate_embedding(self, x):
|
40 |
+
output_ratings = []
|
41 |
+
for name in self.metric_names:
|
42 |
+
first_layer = self.relu(self.dropout(self.layer_norm(getattr(self, 'l_1_' + name)(x) + x)))
|
43 |
+
second_layer = self.sigmoid(getattr(self, name)(first_layer))
|
44 |
+
output_ratings.append(second_layer)
|
45 |
+
|
46 |
+
return output_ratings
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:06d3539e3ba563f91124dd1736f6ce082630fd834340c4d3b7894c3077bc3e02
|
3 |
+
size 449854846
|
special_tokens_map.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cls_token": "[CLS]",
|
3 |
+
"mask_token": "[MASK]",
|
4 |
+
"pad_token": "[PAD]",
|
5 |
+
"sep_token": "[SEP]",
|
6 |
+
"unk_token": "[UNK]"
|
7 |
+
}
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"added_tokens_decoder": {
|
3 |
+
"0": {
|
4 |
+
"content": "[PAD]",
|
5 |
+
"lstrip": false,
|
6 |
+
"normalized": false,
|
7 |
+
"rstrip": false,
|
8 |
+
"single_word": false,
|
9 |
+
"special": true
|
10 |
+
},
|
11 |
+
"100": {
|
12 |
+
"content": "[UNK]",
|
13 |
+
"lstrip": false,
|
14 |
+
"normalized": false,
|
15 |
+
"rstrip": false,
|
16 |
+
"single_word": false,
|
17 |
+
"special": true
|
18 |
+
},
|
19 |
+
"101": {
|
20 |
+
"content": "[CLS]",
|
21 |
+
"lstrip": false,
|
22 |
+
"normalized": false,
|
23 |
+
"rstrip": false,
|
24 |
+
"single_word": false,
|
25 |
+
"special": true
|
26 |
+
},
|
27 |
+
"102": {
|
28 |
+
"content": "[SEP]",
|
29 |
+
"lstrip": false,
|
30 |
+
"normalized": false,
|
31 |
+
"rstrip": false,
|
32 |
+
"single_word": false,
|
33 |
+
"special": true
|
34 |
+
},
|
35 |
+
"103": {
|
36 |
+
"content": "[MASK]",
|
37 |
+
"lstrip": false,
|
38 |
+
"normalized": false,
|
39 |
+
"rstrip": false,
|
40 |
+
"single_word": false,
|
41 |
+
"special": true
|
42 |
+
}
|
43 |
+
},
|
44 |
+
"clean_up_tokenization_spaces": true,
|
45 |
+
"cls_token": "[CLS]",
|
46 |
+
"do_basic_tokenize": true,
|
47 |
+
"do_lower_case": true,
|
48 |
+
"full_tokenizer_file": null,
|
49 |
+
"mask_token": "[MASK]",
|
50 |
+
"model_max_length": 1000000000000000019884624838656,
|
51 |
+
"never_split": null,
|
52 |
+
"pad_token": "[PAD]",
|
53 |
+
"sep_token": "[SEP]",
|
54 |
+
"strip_accents": null,
|
55 |
+
"tokenize_chinese_chars": true,
|
56 |
+
"tokenizer_class": "BertTokenizer",
|
57 |
+
"unk_token": "[UNK]"
|
58 |
+
}
|
vocab.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|