File size: 1,747 Bytes
eb530e9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# ์ถ”๋ก 
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๋ง์–ธ๋ถ„๋ฅ˜_acc9308.bin"))
# ๋ชจ๋ธ์„ ํ‰๊ฐ€ ๋ชจ๋“œ๋กœ ์„ค์ •
model.eval()

# ์ž…๋ ฅ ํ…์ŠคํŠธ ์˜ˆ์‹œ
class_labels = ["์ ์ ˆ(518๋ง์–ธ_NO)", "๋ถ€์ ์ ˆ(518๋ง์–ธ_YES)"]
def inference(new_text):
    inputs = tokenizer(new_text, return_tensors="pt")
    # ์ถ”๋ก  ์ˆ˜ํ–‰ (CPU ์‚ฌ์šฉ)
    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]
    probability = probs[0][predicted_class].item()
    return f"์˜ˆ์ธก: {predicted_label}, ํ™•๋ฅ : {probability:.4f}"

# Streamlit interface
st.title('5ยท18 ๋ฏผ์ฃผํ™”์šด๋™ ๊ด€๋ จ ๋ถ€์ ์ ˆํ•œ ๋ฐœ์–ธ ํƒ์ง€')
st.markdown('<small style="color:grey;">5ยท18 ๋ฏผ์ฃผํ™”์šด๋™๊ณผ ๊ด€๋ จํ•ด ๋ฌด์žฅ ํญ๋™, ๋ถํ•œ๊ตฐ ๊ฐœ์ž…, ๊ฐ€์งœ ์œ ๊ณต์ž ๋“ฑ ๋ถ€์ ์ ˆํ•œ ์–ธ๊ธ‰๊ณผ ์ง€์—ญ-์ด๋…์— ๋Œ€ํ•œ ํ˜์˜ค์„ฑ ๋ฐœ์–ธ์ด ๋ฌธ์ œ๋˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์•„๋ž˜์— ๋ฌธ์žฅ์„ ์ž…๋ ฅํ•˜๋ฉด ์ด๋Ÿฌํ•œ ๋‚ด์šฉ์„ ์ค‘์‹ฌ์œผ๋กœ ๋ฌธ์žฅ์˜ ๋ถ€์ ์ ˆ์„ฑ ์—ฌ๋ถ€๋ฅผ ํ™•๋ฅ ๊ณผ ํ•จ๊ป˜ ํŒ๋‹จํ•ด ๋“œ๋ฆฝ๋‹ˆ๋‹ค. </small>', unsafe_allow_html=True)
user_input = st.text_area("์ด ๊ณณ์— ๋ฌธ์žฅ ์ž…๋ ฅ(100์ž ์ดํ•˜ ๊ถŒ์žฅ):")
if st.button('์‹œ์ž‘'):
    result = inference(user_input)
    st.write(result)