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 Examples
Inference API (serverless) does not yet support peft models for this pipeline type.

Model tree for ozingmw/llama-3.2-3B-sentiment-kr-LoRA

Adapter
(118)
this model