Model Card for Model ID

Modelin Tanıtımı

Aspect-Based Sentiment Analysis (ABSA) için ince ayar yapılmış bir GPT-2 modelidir. Model, giyim ürünlerine ait "aspectler" hakkında yapılan yorumların duygu analizini gerçekleştirmek için eğitilmiştir.

Modeli Nasıl Kullanabiliriz?

from transformers import GPT2Tokenizer, GPT2ForSequenceClassification
import torch

model_name = "ebrukilic/absa-gpt-2"
tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
tokenizer.pad_token = tokenizer.eos_token
model = GPT2ForSequenceClassification.from_pretrained(model_name)

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)

def predict_sentiment(text, aspect, model, tokenizer):
    inputs = tokenizer.encode_plus(
        text=f"{aspect} hakkında: {text}",
        add_special_tokens=True,
        max_length=128,
        padding="max_length",
        truncation=True,
        return_attention_mask=True,
        return_tensors="pt"
    )

    input_ids = inputs["input_ids"].to(device)
    attention_mask = inputs["attention_mask"].to(device)
    with torch.no_grad():
        outputs = model(input_ids, attention_mask=attention_mask)

    predicted_class = torch.argmax(outputs.logits, dim=1).item()
    return predicted_class

new_text = "Ürünün kumaşı çok güzel, bayıldım!"
aspect = "kumaş"
predicted_sentiment = predict_sentiment(new_text, aspect, model, tokenizer)

print("Yorum:", new_text)
print("Aspect:", aspect)
print("Tahmin Edilen Duygu:", predicted_sentiment)
Downloads last month
28
Safetensors
Model size
124M params
Tensor type
F32
·
Inference Providers NEW
This model is not currently available via any of the supported third-party Inference Providers, and the model is not deployed on the HF Inference API.

Model tree for ebrukilic/absa-gpt-2

Finetuned
(1383)
this model

Dataset used to train ebrukilic/absa-gpt-2