Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -86,6 +86,7 @@ st.markdown("### Hello, world!")
|
|
| 86 |
|
| 87 |
title = st.text_area("Title HERE")
|
| 88 |
abstract = st.text_area("Abstract HERE")
|
|
|
|
| 89 |
|
| 90 |
|
| 91 |
if st.button('Предположить'):
|
|
@@ -108,6 +109,35 @@ if st.button('Предположить'):
|
|
| 108 |
idx = torch.nn.functional.softmax(ans[0], dim=0).argmax().item()
|
| 109 |
st.markdown(f'{idx_to_tag[idx]}')
|
| 110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
|
| 113 |
|
|
|
|
| 86 |
|
| 87 |
title = st.text_area("Title HERE")
|
| 88 |
abstract = st.text_area("Abstract HERE")
|
| 89 |
+
ans = None
|
| 90 |
|
| 91 |
|
| 92 |
if st.button('Предположить'):
|
|
|
|
| 109 |
idx = torch.nn.functional.softmax(ans[0], dim=0).argmax().item()
|
| 110 |
st.markdown(f'{idx_to_tag[idx]}')
|
| 111 |
|
| 112 |
+
if st.button("Посмотреть топ"):
|
| 113 |
+
if not ans:
|
| 114 |
+
text = title + " : " + abstract
|
| 115 |
+
inputs = tokenizer.encode_plus(
|
| 116 |
+
text,
|
| 117 |
+
None,
|
| 118 |
+
add_special_tokens=True,
|
| 119 |
+
max_length=256,
|
| 120 |
+
pad_to_max_length=True,
|
| 121 |
+
return_token_type_ids=True
|
| 122 |
+
)
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
ids = torch.Tensor(inputs['input_ids']).long()
|
| 126 |
+
mask = torch.Tensor(inputs['attention_mask']).long()
|
| 127 |
+
token_type_ids = torch.Tensor(inputs['token_type_ids']).long()
|
| 128 |
+
|
| 129 |
+
ans = model(ids.unsqueeze(0), mask.unsqueeze(0), token_type_ids.unsqueeze(0))
|
| 130 |
+
elems = [el.item() for el in ans[0].argsort(descending=True)[:10]]
|
| 131 |
+
probs = ans[0].softmax(dim=0)
|
| 132 |
+
str = ''
|
| 133 |
+
for el in elems:
|
| 134 |
+
str += el + " : " + probs[el] + "\n"
|
| 135 |
+
|
| 136 |
+
st.markdown(str)
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
|
| 141 |
|
| 142 |
|
| 143 |
|