File size: 1,434 Bytes
c5da81d
d98e05f
5bf9261
 
c5da81d
d98e05f
 
c5da81d
4829d4c
d98e05f
5bf9261
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c5da81d
d98e05f
c5da81d
d98e05f
 
 
 
 
 
 
 
 
 
c5da81d
d98e05f
 
 
1
2
3
4
5
6
7
8
9
10
11
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
38
39
40
41
42
43
44
45
46
47
48
49
50
import streamlit as st
import torch
from transformers import AutoTokenizer, AutoModel, pipeline
from torch import nn

st.markdown("### Articles classificator.")
# st.markdown("<img width=200px src='https://rozetked.me/images/uploads/dwoilp3BVjlE.jpg'>", unsafe_allow_html=True)

@st.cache
def LoadModel():
    model_name = 'bert-base-uncased'
    tokenizer = AutoTokenizer.from_pretrained(model_name)
    bert = AutoModel.from_pretrained(model_name)

    class devops_model(nn.Module):
        def __init__(self):
            super(devops_model, self).__init__()
            self.bert = bert
            self.fc = nn.Sequential(
                nn.Linear(768, 768),
                nn.ReLU(),
                nn.Dropout(0.3),
                nn.BatchNorm1d(768),            
                nn.Linear(768, 5),
                nn.LogSoftmax(dim=-1)
            )
            
        def forward(self, train_batch):
            emb = self.bert(**train_batch)['pooler_output']
            return self.fc(emb)

    return torch.load('model.pt'), tokenizer


model, tokenizer = LoadModel()

def process(title, summary):
    text = title + summary
    model.eval()
    lines = [text]
    X = tokenizer(lines, padding=True, truncation=True, return_tensors="pt")
    out = model(X)
    probs = torch.exp(out[0])
    return probs
    
title = st.text_area("Title")

summary = st.text_area("Summary")

st.markdown(f"{process(title, summary)}")