hplisiecki commited on
Commit
bc6f766
1 Parent(s): f8ddab4

Upload 8 files

Browse files
config.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "dbmdz/bert-base-german-uncased",
3
+ "architectures": [
4
+ "BertModel"
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-12,
14
+ "max_position_embeddings": 512,
15
+ "model_type": "bert",
16
+ "num_attention_heads": 12,
17
+ "num_hidden_layers": 12,
18
+ "pad_token_id": 0,
19
+ "position_embedding_type": "absolute",
20
+ "torch_dtype": "float32",
21
+ "transformers_version": "4.41.2",
22
+ "type_vocab_size": 2,
23
+ "use_cache": true,
24
+ "vocab_size": 31102
25
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d8ae3e6010782af7a52f6a98ec3954090c03204295722bdad2d6a54f3f8cb49e
3
+ size 439733088
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', 'imageability']
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:03b34ab92fefd070a720ae9edf8879e36f73c40e4d148c061b046430998d4170
3
+ size 446897118
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
+ "101": {
12
+ "content": "[UNK]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "102": {
20
+ "content": "[CLS]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "103": {
28
+ "content": "[SEP]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "104": {
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
+ "mask_token": "[MASK]",
49
+ "max_len": 512,
50
+ "model_max_length": 512,
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