I am new to transformers models and trying to extract aspect and sentiment for a sentence but having issues
from transformers import AutoTokenizer, AutoModelForSequenceClassification
model_name = "yangheng/deberta-v3-base-absa-v1.1"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
text = "The food was great but the service was terrible."
inputs = tokenizer(text, return_tensors="pt")
outputs = model(**inputs)
I am able to get the tensor what I need is the output to extract the aspect and sentiment for the overall sentence
I tried this however getting error
sentiment_scores = outputs.logits.softmax(dim=1)
aspect_scores = sentiment_scores[:, 1:-1]
aspects = [tokenizer.decode([x]) for x in inputs["input_ids"].squeeze()][1:-1]
sentiments = ['Positive' if score > 0.5 else 'Negative' for score in aspect_scores.squeeze()]
for aspect, sentiment in zip(aspects, sentiments):
print(f"{aspect}: {sentiment}")
I am looking for below o/p or similar o/p
I am unable to write the logic as to how extract aspect and sentiment
text -The food was great but the service was terrible
aspect- food ,sentiment positive
aspect - service, sentiment negative
or at overall level
aspect - food, sentiment positive