sayby commited on
Commit
13fc001
·
verified ·
1 Parent(s): b4e2acd

Upload model

Browse files
Files changed (3) hide show
  1. config.json +37 -0
  2. model.safetensors +3 -0
  3. prot_albert_model.py +38 -0
config.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "Rostlab/prot_albert",
3
+ "architectures": [
4
+ "ProtAlBertModel"
5
+ ],
6
+ "attention_probs_dropout_prob": 0,
7
+ "auto_map": {
8
+ "AutoModel": "prot_albert_model.ProtAlBertModel"
9
+ },
10
+ "bos_token_id": 2,
11
+ "classifier_dropout_prob": 0.1,
12
+ "down_scale_factor": 1,
13
+ "embedding_size": 128,
14
+ "eos_token_id": 3,
15
+ "gap_size": 0,
16
+ "hidden_act": "gelu",
17
+ "hidden_dropout_prob": 0,
18
+ "hidden_size": 4096,
19
+ "initializer_range": 0.02,
20
+ "inner_group_num": 1,
21
+ "intermediate_size": 16384,
22
+ "layer_norm_eps": 1e-12,
23
+ "layers_to_keep": [],
24
+ "max_position_embeddings": 40000,
25
+ "model_type": "albert",
26
+ "net_structure_type": 0,
27
+ "num_attention_heads": 64,
28
+ "num_hidden_groups": 1,
29
+ "num_hidden_layers": 12,
30
+ "num_memory_blocks": 0,
31
+ "pad_token_id": 0,
32
+ "position_embedding_type": "absolute",
33
+ "torch_dtype": "float32",
34
+ "transformers_version": "4.40.1",
35
+ "type_vocab_size": 2,
36
+ "vocab_size": 34
37
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c1040fb05b7462e49fb0e064e1101d16d71e8acaea7f2b36c040d1f1b4015f4b
3
+ size 895688552
prot_albert_model.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Any
2
+
3
+ import torch.nn as nn
4
+ from transformers import AlbertModel, AutoConfig
5
+ from transformers import PreTrainedModel, AutoModel, AutoConfig
6
+
7
+
8
+ class ProtAlBertModel(PreTrainedModel):
9
+ def __init__(self, config: Any, num_labels: int, hidden_size: int, model_name: str, *args, **kwargs):
10
+ """
11
+ Initialise the model.
12
+ :param: config class for the PreTrainedModel class
13
+ :param hidden_size: size of the hidden layer after the CLS token.
14
+ :param num_labels: the number of labels.
15
+ :param model_name: the name of the model.
16
+ """
17
+ super().__init__(config)
18
+ albert_config = AutoConfig.from_pretrained(model_name)
19
+ self.config = AutoConfig.from_pretrained(
20
+ model_name,
21
+ trust_remote_code=True,
22
+ )
23
+ self.protbert = AlbertModel.from_pretrained(
24
+ model_name, config=self.config, trust_remote_code=True
25
+ )
26
+ self.last_layer = nn.Sequential(
27
+ nn.Dropout(0.1),
28
+ nn.LayerNorm(self.config.hidden_size),
29
+ nn.Linear(self.config.hidden_size, hidden_size),
30
+ nn.GELU(),
31
+ nn.Linear(hidden_size, num_labels),
32
+ )
33
+
34
+ def forward(self, x):
35
+ # Take the last embedding of the [CLS] token
36
+ z = self.protbert(**x).last_hidden_state[:, 0, :]
37
+ output = self.last_layer(z)
38
+ return {"logits": output}