Views
No views yet
microsoft/deberta-v3-base0: Negative1: Neutral2: Positive1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4model_name = "iSathyam03/McD_Reviews_Sentiment_Analysis"
5tokenizer = AutoTokenizer.from_pretrained(model_name)
6model = AutoModelForSequenceClassification.from_pretrained(model_name)
7
8def predict_sentiment(text):
9 inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
10 with torch.no_grad():
11 outputs = model(**inputs)
12 logits = outputs.logits
13 prediction = torch.argmax(logits, dim=1).item()
14 sentiment_labels = {0: "Negative", 1: "Neutral", 2: "Positive"}
15 return sentiment_labels[prediction]
16
17# Example
18text = "The fries were amazing but the burger was stale."
19print(predict_sentiment(text))@article{he2020deberta,
title={DeBERTa: Decoding-enhanced BERT with Disentangled Attention},
author={He, Pengcheng and Liu, Xiaodong and Gao, Jianfeng and Chen, Weizhu},
journal={arXiv preprint arXiv:2006.03654},
year={2020}
}