RayCappola commited on
Commit
e731bb3
1 Parent(s): 423ee1a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -9
app.py CHANGED
@@ -7,11 +7,13 @@ class Net(nn.Module):
7
  def __init__(self):
8
  super(Net,self).__init__()
9
  self.layer = nn.Sequential(
10
- nn.Linear(768, 768),
11
  nn.ReLU(),
12
- nn.Linear(768, 768),
13
  nn.ReLU(),
14
- nn.Linear(768, 8),
 
 
15
  )
16
 
17
  def forward(self,x):
@@ -32,18 +34,24 @@ def get_word_vector(sent, tokenizer, model):
32
 
33
  return get_hidden_states(encoded, model)
34
 
35
- model=Net()
36
- model.load_state_dict(torch.load('dummy_model.txt', map_location=torch.device('cpu')))
37
- model.eval()
38
 
39
 
40
  labels_articles = {1: 'Computer Science',2: 'Economics',3: "Electrical Engineering And Systems Science",
41
 
42
  4: "Mathematics",5: "Physics",6: "Quantitative Biology",7: "Quantitative Finance", 8: "Statistics"}
43
 
44
- tokenizer = AutoTokenizer.from_pretrained("Callidior/bert2bert-base-arxiv-titlegen")
45
-
46
- model_emb = AutoModelForSeq2SeqLM.from_pretrained("Callidior/bert2bert-base-arxiv-titlegen")
 
 
 
 
 
 
 
 
 
47
 
48
  title = st.text_area("Write title of your article")
49
  summary = st.text_area("Write summary of your article or dont write anything (but you should press Ctrl + Enter)")
 
7
  def __init__(self):
8
  super(Net,self).__init__()
9
  self.layer = nn.Sequential(
10
+ nn.Linear(768, 512),
11
  nn.ReLU(),
12
+ nn.Linear(512, 256),
13
  nn.ReLU(),
14
+ nn.Linear(256, 128),
15
+ nn.ReLU(),
16
+ nn.Linear(128, 8),
17
  )
18
 
19
  def forward(self,x):
 
34
 
35
  return get_hidden_states(encoded, model)
36
 
 
 
 
37
 
38
 
39
  labels_articles = {1: 'Computer Science',2: 'Economics',3: "Electrical Engineering And Systems Science",
40
 
41
  4: "Mathematics",5: "Physics",6: "Quantitative Biology",7: "Quantitative Finance", 8: "Statistics"}
42
 
43
+ @st.cache
44
+ def load_models():
45
+ model=Net()
46
+ model.load_state_dict(torch.load('dummy_model.txt', map_location=torch.device('cpu')))
47
+ model.eval()
48
+
49
+ tokenizer = AutoTokenizer.from_pretrained("Callidior/bert2bert-base-arxiv-titlegen")
50
+
51
+ model_emb = AutoModelForSeq2SeqLM.from_pretrained("Callidior/bert2bert-base-arxiv-titlegen")
52
+ return model, model_emb, tokenizer
53
+
54
+ model, model_emb, tokenizer = load_models()
55
 
56
  title = st.text_area("Write title of your article")
57
  summary = st.text_area("Write summary of your article or dont write anything (but you should press Ctrl + Enter)")