Update app.py
Browse files
app.py
CHANGED
|
@@ -7,32 +7,34 @@ st.markdown("### Articles classificator.")
|
|
| 7 |
# st.markdown("<img width=200px src='https://rozetked.me/images/uploads/dwoilp3BVjlE.jpg'>", unsafe_allow_html=True)
|
| 8 |
|
| 9 |
@st.cache
|
| 10 |
-
def
|
| 11 |
model_name = 'bert-base-uncased'
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
)
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
| 36 |
|
| 37 |
def process(title, summary):
|
| 38 |
text = title + summary
|
|
|
|
| 7 |
# st.markdown("<img width=200px src='https://rozetked.me/images/uploads/dwoilp3BVjlE.jpg'>", unsafe_allow_html=True)
|
| 8 |
|
| 9 |
@st.cache
|
| 10 |
+
def get_bert_and_tokenizer():
|
| 11 |
model_name = 'bert-base-uncased'
|
| 12 |
+
return AutoModel.from_pretrained(model_name), AutoTokenizer.from_pretrained(model_name)
|
| 13 |
+
|
| 14 |
+
bert, tokenizer = get_bert_and_tokenizer()
|
| 15 |
+
|
| 16 |
+
class devops_model(nn.Module):
|
| 17 |
+
def __init__(self):
|
| 18 |
+
super(devops_model, self).__init__()
|
| 19 |
+
self.bert = bert
|
| 20 |
+
self.fc = nn.Sequential(
|
| 21 |
+
nn.Linear(768, 768),
|
| 22 |
+
nn.ReLU(),
|
| 23 |
+
nn.Dropout(0.3),
|
| 24 |
+
nn.BatchNorm1d(768),
|
| 25 |
+
nn.Linear(768, 5),
|
| 26 |
+
nn.LogSoftmax(dim=-1)
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
def forward(self, train_batch):
|
| 30 |
+
emb = self.bert(**train_batch)['pooler_output']
|
| 31 |
+
return self.fc(emb)
|
| 32 |
+
|
| 33 |
+
@st.cache
|
| 34 |
+
def LoadModel():
|
| 35 |
+
return torch.load('model.pt')
|
| 36 |
+
|
| 37 |
+
model = LoadModel()
|
| 38 |
|
| 39 |
def process(title, summary):
|
| 40 |
text = title + summary
|