О модели

Модель TinyLlama/TinyLlama-1.1B-Chat-v1.0, дообученная с помощью библиотеки PEFT адаптером QLoRA, предназначена для оценки тональности сообщений пользователей. Дообучена на датасете "cardiffnlp/tweet_eval", определяя тональность твитов.

Результат после дообучения

Результат после дообучения: macro F1: 0.53

Как использовать

Хоть модель и обучалась определять тональность твитов, она вполне способна и определять тональность обычных сообщений/текстов

if torch.cuda.is_available():
    DEVICE = "cuda"
elif torch.backends.mps.is_available():
    DEVICE = "mps"
else:
    DEVICE = "cpu"
model = AutoModelForCausalLM.from_pretrained(f"{REPO_NAME}-tinyllama-qlora", device_map="cuda")
tokenizer = AutoTokenizer.from_pretrained(f"{REPO_NAME}-tinyllama-qlora")
tokenizer.pad_token = tokenizer.eos_token
tokenizer.padding_side = "left"

IDX2NAME = {0: "negative", 1: "neutral", 2: "positive"}
def postprocess_sentiment(output_text: str) -> str:
    """
    Фильтрует вывод модели и возвращает только метку класса, к которому относится сообщение ('positive', 'negative', 'neutral').
    Parameters:
        output_text (str): Текст, сгенерированный моделью.

    Returns:
        str: тональность текста или пустая строка
    """

    parts = output_text.split("assistant", 1)
    text_to_process = parts[1] if len(parts) > 1 else output_text

    match = re.search(rf"\b({'|'.join(IDX2NAME.values())})\b", text_to_process, re.IGNORECASE)
    return match.group(1).lower() if match else ""
SYSTEM_PROMPT = "Your task is to look through the provided text and classify the sentiment of it. Possible classes are: positive, negative, neutral. Respond only one word from the possible classes that best describes the sentiment of provided text."
text = 'I hate playing Minecraft' #здесь может быть ваш текст
chat = [
    {'role': 'system', 'content' : SYSTEM_PROMPT},
    {'role': 'user', 'content' : f"Text to classify: {text}"}
    ]
ch_temp = tokenizer.apply_chat_template(chat, tokenize = False)
input_ids = tokenizer(ch_temp, return_tensors = 'pt').to(model.device)
output_ids = model.generate(input_ids['input_ids'], max_new_tokens=16)
generated_text = tokenizer.decode(output_ids[0][len(input_ids[0]) :], skip_special_tokens=True)
print(generated_text)

Примеры использования

Промт: "I hate morning"

Ответ модели: negative

Промт: "I love playing videogames"

Ответ модели: positive

Промт: "It is raining today"

Ответ модели: neutral

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for georgebu/peft_tinyllama_qlora

Finetuned
(332)
this model

Dataset used to train georgebu/peft_tinyllama_qlora

Collection including georgebu/peft_tinyllama_qlora