hplisiecki commited on
Commit
39bf9bb
1 Parent(s): d9e4f9e

Upload 8 files

Browse files
config.json ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "D:/PycharmProjects/roberta/roberta_base_transformers/",
3
+ "architectures": [
4
+ "RobertaModel"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "bos_token_id": 0,
8
+ "classifier_dropout": null,
9
+ "eos_token_id": 2,
10
+ "gradient_checkpointing": false,
11
+ "hidden_act": "gelu",
12
+ "hidden_dropout_prob": 0.1,
13
+ "hidden_size": 768,
14
+ "initializer_range": 0.02,
15
+ "intermediate_size": 3072,
16
+ "layer_norm_eps": 1e-05,
17
+ "max_position_embeddings": 514,
18
+ "model_type": "roberta",
19
+ "num_attention_heads": 12,
20
+ "num_hidden_layers": 12,
21
+ "pad_token_id": 1,
22
+ "position_embedding_type": "absolute",
23
+ "torch_dtype": "float32",
24
+ "transformers_version": "4.41.2",
25
+ "type_vocab_size": 1,
26
+ "use_cache": true,
27
+ "vocab_size": 50001
28
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:358c63bfab956620f7fb8704d76f72cc87d09ba278d15ef41aa3094fd54d1da4
3
+ size 497793896
model_script.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from torch import nn
3
+ from transformers import RobertaModel
4
+
5
+ class CustomModel(torch.nn.Module):
6
+ def __init__(self, model_path, dropout=0.2, hidden_dim=768):
7
+ super().__init__()
8
+ self.metric_names = ['affect', 'arousal', 'dominance', 'origin', 'significance', 'concreteness', 'imageability', 'aqcuisition']
9
+ self.dropout_rate = dropout
10
+ self.hidden_dim = hidden_dim
11
+
12
+ self.bert = RobertaModel.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:4e0c41d7390dfc0f4b0f142d2261260d5cd0c3b501b639dba124268815cfef95
3
+ size 516791470
special_tokens_map.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {}
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "<s>",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "1": {
12
+ "content": "<pad>",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "2": {
20
+ "content": "</s>",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "3": {
28
+ "content": "<unk>",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "50000": {
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
+ "model_max_length": 1000000000000000019884624838656,
46
+ "tokenizer_class": "PreTrainedTokenizerFast"
47
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff