absa-gpt-2 / README.md
ebrukilic's picture
Update README.md
5d5c5d6 verified
---
library_name: transformers
tags:
- gpt2
- absa
- nlp
- turkish
license: mit
datasets:
- ebrukilic/ytu-araproje-absa-7400
language:
- tr
metrics:
- f1
- accuracy
- precision
- recall
base_model:
- openai-community/gpt2
pipeline_tag: text-classification
---
# Model Card for Model ID
<!-- Provide a quick summary of what the model is/does. -->
## 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.
- **Temel Alınan Model:** [[openai-community/gpt2](https://huggingface.co/openai-community/gpt2)]
- **Eğitildiği Veri Kümesi:** [[ebrukilic/ytu-araproje-absa-7400](ebrukilic/ytu-araproje-absa-7400)]
- **Duygu Sınıfları:** negatif: 0, nötr: 1, pozitif: 2
- **Dil:** Türkçe
- **Developed by:** [[ebru kılıç](https://huggingface.co/ebrukilic)]
- **Language(s) (NLP):** Turkish
- **Sentiment Classes:** negative: 0, neutral: 1, positive: 2
- **Finetuned from model [optional]:** [[openai-community/gpt2](https://huggingface.co/openai-community/gpt2)]
## 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)
```