|
|
|
from transformers import RobertaTokenizer, RobertaForSequenceClassification |
|
import torch |
|
import streamlit as st |
|
|
|
|
|
tokenizer = RobertaTokenizer.from_pretrained('beomi/KcBERT-v2023') |
|
model = RobertaForSequenceClassification.from_pretrained('beomi/KcBERT-v2023', num_labels=2) |
|
model.load_state_dict(torch.load("pytorchmodel_518๋ง์ธ๋ถ๋ฅ_acc8583.bin", map_location=torch.device('cpu'))) |
|
|
|
model.eval() |
|
|
|
|
|
class_labels = ["๋ฌธ์ ์์/๊ด๋ จ์์", "๋ถ์ ์ (518 ๋ง์ธ ๊ฐ๋ฅ)"] |
|
def inference(new_text): |
|
inputs = tokenizer(new_text, return_tensors="pt") |
|
|
|
with torch.no_grad(): |
|
outputs = model(**inputs) |
|
logits = outputs.logits |
|
probs = torch.nn.functional.softmax(logits, dim=-1) |
|
predicted_class = torch.argmax(probs, dim=1).item() |
|
predicted_label = class_labels[predicted_class] |
|
unpredicted_label = class_labels[1-predicted_class] |
|
probability = probs[0][predicted_class].item() |
|
return f"{predicted_label}:{probability*100:.2f}%, {unpredicted_label}:{((1-probability)*100):.2f}%" |
|
|
|
|
|
st.markdown('### 5ยท18 ๋ฏผ์ฃผํ์ด๋ ๊ด๋ จ ๋ถ์ ์ ํ ๋ฐ์ธ ํ๋จ(๋ฒ ํ๋ฒ์ )') |
|
st.markdown('<small style="color:grey;">5ยท18 ๋ฏผ์ฃผํ์ด๋๊ณผ ๊ด๋ จํด ๋ฌด์ฅ ํญ๋, ๋ถํ๊ตฐ ๊ฐ์
, ๊ฐ์ง ์ ๊ณต์ ๋ฑ ๋ถ์ ์ ํ ์ธ๊ธ๊ณผ ์ง์ญ-์ด๋
์ ๋ํ ํ์ค์ฑ ๋ฐ์ธ์ด ๋ฌธ์ ๋๊ณ ์์ต๋๋ค. ์๋์ ๋ฌธ์ฅ์ ์
๋ ฅํ๋ฉด ์ด๋ฌํ ๋ด์ฉ์ ์ค์ฌ์ผ๋ก "๋ฌธ์ ์์/๊ด๋ จ์์" ๋๋ "๋ถ์ ์ (518 ๋ง์ธ ๊ฐ๋ฅ)"๋ก ํ๋จํด ๋๋ฆฝ๋๋ค. ์์ธก ๋ชจ๋ธ์ ์ ํ๋๋ 85.83%๋ก, ์ผ๋ถ ๋ถ์ ํํ ๊ฒฐ๊ณผ๊ฐ ๋์ฌ ์ ์์ต๋๋ค </small>', unsafe_allow_html=True) |
|
user_input = st.text_area("์ด ๊ณณ์ ๋ฌธ์ฅ ์
๋ ฅ(100์ ์ดํ ๊ถ์ฅ, ๋๋ฌด ๊ธธ๋ฉด ๋ถ์ ๋ถ๊ฐ):") |
|
if st.button('์์'): |
|
result = inference(user_input) |
|
st.write(result) |