e9t/nsmc
Updated โข 958 โข 17
์ด ๋ชจ๋ธ์ LoRA๋ฅผ ์ฌ์ฉํ์ฌ NSMC(Naver Sentiment Movie Corpus) ๋ฐ์ดํฐ์ ์ผ๋ก ํ์ธํ๋๋ ๊ฐ์ ๋ถ์ ๋ชจ๋ธ์ ๋๋ค.
from transformers import AutoModelForSequenceClassification, AutoTokenizer
from peft import PeftModel
import torch
# ๋ฒ ์ด์ค ๋ชจ๋ธ ๋ก๋
base_model = AutoModelForSequenceClassification.from_pretrained(
"klue/bert-base",
num_labels=2
)
# LoRA ์ด๋ํฐ ๋ก๋
model = PeftModel.from_pretrained(base_model, "JINIIII/nsmc-sentiment-lora")
tokenizer = AutoTokenizer.from_pretrained("JINIIII/nsmc-sentiment-lora")
# ์ถ๋ก
text = "์ด ์ํ ์ ๋ง ์ฌ๋ฏธ์์ด์!"
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=128)
outputs = model(**inputs)
probs = torch.softmax(outputs.logits, dim=-1)
pred = torch.argmax(probs, dim=-1).item()
label = "๊ธ์ " if pred == 1 else "๋ถ์ "
confidence = probs[0][pred].item()
print(f"๊ฒฐ๊ณผ: {label} (ํ์ ๋: {confidence:.2%})")
MIT License
JINIIII
@misc{nsmc-sentiment-lora,
author = {JINIIII},
title = {NSMC Sentiment Analysis with LoRA},
year = {2024},
publisher = {Hugging Face},
url = {https://huggingface.co/JINIIII/nsmc-sentiment-lora}
}
Note: ์ด ๋ชจ๋ธ์ ๊ต์ก ๋ชฉ์ ์ผ๋ก ๋ง๋ค์ด์ก์ต๋๋ค.
Base model
klue/bert-base