e9t/nsmc
Updated β’ 567 β’ 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