KeXing commited on
Commit
7fdc7b5
1 Parent(s): 3d2a912

Upload 6 files

Browse files
__pycache__/downstream_model.cpython-310.pyc ADDED
Binary file (2.18 kB). View file
 
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from tape import ProteinBertModel, ProteinBertConfig, TAPETokenizer # type: ignore
3
+ from tape.models import modeling_bert
4
+ import numpy as np
5
+ import torch
6
+
7
+ tokenizer = TAPETokenizer(vocab='iupac')
8
+ config=modeling_bert.ProteinBertConfig(num_hidden_layers=5,num_attention_heads=8,hidden_size=400)
9
+
10
+ bert_model = torch.load('models/bert.pt')
11
+ class_model=torch.load('models/class.pt')
12
+
13
+
14
+
15
+ def greet(name):
16
+ token_ids = torch.tensor([tokenizer.encode(name)])
17
+ token_ids = token_ids
18
+ bert_output = bert_model(token_ids)
19
+ class_output=class_model(bert_output[1])
20
+ cluster = torch.argmax(class_output, dim=1) + 1
21
+ cluster=cluster.item()
22
+
23
+ return "cluster "+str(cluster)
24
+ demo = gr.Interface(
25
+ fn=greet,
26
+ # 自定义输入框
27
+ # 具体设置方法查看官方文档
28
+ inputs=gr.Textbox(lines=3, placeholder="Name Here...",label="my input"),
29
+ outputs="text",
30
+ )
31
+ demo.launch(share=True)
downstream_model.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torch.nn as nn
3
+ from tape.models import modeling_bert
4
+
5
+
6
+ config=modeling_bert.ProteinBertConfig(hidden_size=400)
7
+ class ClassificationModel1(torch.nn.Module):
8
+ def __init__(self):
9
+ super(ClassificationModel1, self).__init__()
10
+ self.dense_layer1 = nn.Linear(1024, 2048)
11
+ self.dense_layer2 = nn.Linear(2048, 512)
12
+ self.output_layer = nn.Linear(512, 45)
13
+ self.dropout1 = nn.Dropout(0.2)
14
+ self.dropout2 = nn.Dropout(0.3)
15
+
16
+ def forward(self, protein_sequence):
17
+ hidden_layer_output1 = torch.relu(self.dense_layer1(protein_sequence))
18
+ #hidden_layer_output1 = self.dropout1(hidden_layer_output1)
19
+
20
+ hidden_layer_output2 = torch.relu(self.dense_layer2(hidden_layer_output1))
21
+ #hidden_layer_output2 = self.dropout2(hidden_layer_output2)
22
+
23
+ output = self.output_layer(hidden_layer_output2)
24
+
25
+ return output
26
+
27
+
28
+
29
+
30
+ class ClassificationModel2(nn.Module):
31
+ def __init__(self):
32
+ super(ClassificationModel2,self).__init__()
33
+ self.attention_layer=nn.Linear(400,1)
34
+ self.hidden_layer=nn.Linear(400,1024)
35
+ self.output_layer=nn.Linear(1024,45)
36
+ self.relu=nn.ReLU()
37
+ self.dropout=nn.Dropout(0.1)
38
+ self.layernorm1=nn.LayerNorm(400)
39
+ self.layernorm2=nn.LayerNorm(1024)
40
+ self.attention_selfoutput= modeling_bert.ProteinBertSelfOutput(config)
41
+
42
+ def forward(self,sequence):
43
+ sequence=self.layernorm1(sequence)
44
+ attention_values=self.attention_layer(sequence)
45
+ attention_values=self.dropout(attention_values)
46
+ attention_weights=torch.softmax(attention_values,dim=1)
47
+
48
+
49
+
50
+ weighted_embeddings=sequence*attention_weights
51
+ attention_embeddings=torch.sum(weighted_embeddings,dim=1)
52
+
53
+ attention_embeddings=self.attention_selfoutput(attention_embeddings,attention_embeddings)
54
+ attention_embeddings=self.dropout(attention_embeddings)
55
+ attention_embeddings = self.attention_selfoutput(attention_embeddings, attention_embeddings)
56
+
57
+ hidden_output=self.dropout(self.relu(self.hidden_layer(attention_embeddings)))
58
+ hidden_output=self.layernorm2(hidden_output)
59
+ output=self.output_layer(hidden_output)
60
+
61
+ return output
flagged/log.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ my input,output,flag,username,timestamp
2
+ ,,,,2023-12-18 20:31:08.484538
models/bert.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d8202c06d805df2ca08b9a460e71cb651eb7deb594f37c13c15e685d77e02b5d
3
+ size 80272735
models/class.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:54ffee6f21ff8d0c743fbf8cad638ed609030e79a6359ec115005c98f0cef9c7
3
+ size 2491739