File size: 3,219 Bytes
992e1b1 47d9a54 992e1b1 47d9a54 992e1b1 47d9a54 992e1b1 47d9a54 992e1b1 47d9a54 992e1b1 47d9a54 992e1b1 47d9a54 992e1b1 47d9a54 992e1b1 47d9a54 992e1b1 47d9a54 992e1b1 47d9a54 992e1b1 47d9a54 992e1b1 47d9a54 992e1b1 47d9a54 992e1b1 47d9a54 992e1b1 47d9a54 4f54552 47d9a54 992e1b1 47d9a54 992e1b1 47d9a54 992e1b1 47d9a54 992e1b1 47d9a54 992e1b1 47d9a54 992e1b1 |
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
---
base_model: meta-llama/Llama-3.2-3B-Instruct
library_name: peft
language:
- ko
- en
metrics:
- accuracy
pipeline_tag: text-classification
---
# Model Card for Model ID
- llama3.2-3B ๋ชจ๋ธ์ prompt๋ฅผ ๊ณ ์ ํ๊ณ lora ๋ฐฉ์์ผ๋ก ํ์ตํ ๋ชจ๋ธ์
๋๋ค.
- ๊ธฐ์จ, ๋นํฉ, ๋ถ๋
ธ, ๋ถ์, ์์ฒ, ์ฌํ ์ด 6๊ฐ์ง ๊ฐ์ ์ ํ์ตํ์์ต๋๋ค.
- ๋ฐ์ดํฐ๋ AIHUB์ [๊ฐ์ฑ ๋ํ ๋ง๋ญ์น](https://www.aihub.or.kr/aihubdata/data/view.do?currMenu=115&topMenu=100&aihubDataSe=data&dataSetSn=86)๋ฅผ ์ฌ์ฉํ์ต๋๋ค.
- ๋์ด์ ์ฑ๋ณ๋ ํ์ต์ ์ฌ์ฉํ์ต๋๋ค.
## 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 |