Configuration Parsing
Warning:
In adapter_config.json: "peft.task_type" must be a string
Model Card for Model ID
- llama3.2-3B ๋ชจ๋ธ์ prompt๋ฅผ ๊ณ ์ ํ๊ณ lora ๋ฐฉ์์ผ๋ก ํ์ตํ ๋ชจ๋ธ์ ๋๋ค.
- ๊ธฐ์จ, ๋นํฉ, ๋ถ๋ ธ, ๋ถ์, ์์ฒ, ์ฌํ ์ด 6๊ฐ์ง ๊ฐ์ ์ ํ์ตํ์์ต๋๋ค.
- ๋ฐ์ดํฐ๋ AIHUB์ ๊ฐ์ฑ ๋ํ ๋ง๋ญ์น๋ฅผ ์ฌ์ฉํ์ต๋๋ค.
- ๋์ด์ ์ฑ๋ณ๋ ํ์ต์ ์ฌ์ฉํ์ต๋๋ค.
Uses
import re
import torch
from transformers import AutoTokenizer
from peft import AutoPeftModelForCausalLM
model = None
tokenizer = None
device = None
PROMPT="""<|prompt|>You are an AI assistant tasked with analyzing the emotional content of a diary entry. Your goal is to determine the most closely matching emotion from a predefined list.
Here is the diary entry you need to analyze:
<diary_entry>
age: {age} | gender: {gender} | diary: {sentence}
</diary_entry>
Please carefully read and analyze the content of this diary entry. Consider the overall tone, the events described, and the language used by the writer.
Based on your analysis, choose the emotion that best matches the overall sentiment of the diary entry from the following list:
['๋ถ๋
ธ', '๋ถ์', '์์ฒ', '์ฌํ', '๋นํฉ', '๊ธฐ์จ']
Translate these emotions to English for your understanding:
['๋ถ๋
ธ(anger)', '๋ถ์(anxiety)', '์์ฒ(hurt)', '์ฌํ(sadness)', '๋นํฉ(embarrassment)', '๊ธฐ์จ(happiness)']
After you've made your decision, respond with only the chosen emotion in Korean. Do not provide any explanation or additional text.
Your response should be formatted as follows:
<emotion>[chosen emotion in korean]</emotion>
Once you've provided the emotion, end the conversation. Do not engage in any further dialogue or provide any additional information.
<|assistant|>"""
def load_model():
global model, tokenizer, device
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
path = './llama-3.2-3B-sentiment-kr-LoRA'
tokenizer = AutoTokenizer.from_pretrained(path)
model = AutoPeftModelForCausalLM.from_pretrained(
path,
attn_implementation="flash_attention_2",
torch_dtype=torch.float16,
device_map=device,
)
model.eval()
def generate(text, age, gender):
global model, tokenizer, device
text = PROMPT.format(age=age, gender=gender, sentence=text)
inputs = tokenizer(text, return_tensors="pt").to(device)
with torch.no_grad():
outputs = model.generate(**inputs, max_new_tokens=11, pad_token_id=tokenizer.pad_token_id)
decoded_output = tokenizer.decode(outputs[0])
try:
pred = decoded_output.split("<|assistant|>")[1]
pred = re.search(r'<emotion>(.*?)</emotion>', pred).group(1)
except:
pred = 'error'
return pred
print(generate("์ค๋ ์น๊ตฌ๋ ์ธ์ ์ด.", "", ""))
Accuracy
๋ฐ์ดํฐ ํ์ต์ ์ผ๋ถ๋ฅผ ํ ์คํธ์ฉ ๋ฐ์ดํฐ๋ก ์ ํ๋ ์ธก์ ๊ฒฐ๊ณผ ์ฝ 70%๋ฅผ ๋ฌ์ฑํ์ต๋๋ค.
Framework versions
- PEFT 0.13.0
- Downloads last month
- 7
Inference API (serverless) does not yet support peft models for this pipeline type.
Model tree for ozingmw/llama-3.2-3B-sentiment-kr-LoRA
Base model
meta-llama/Llama-3.2-3B-Instruct