Delete SentimentAndIntentionAnalysis.py
Browse files
SentimentAndIntentionAnalysis.py
DELETED
|
@@ -1,26 +0,0 @@
|
|
| 1 |
-
from transformers import pipeline, BartTokenizer, BartForSequenceClassification
|
| 2 |
-
class ZeroShotClassifier:
|
| 3 |
-
|
| 4 |
-
def __init__(self, model_name, sentiment_labels, intention_labels):
|
| 5 |
-
self.model = self.create_model(model_name)
|
| 6 |
-
self.model_name = model_name
|
| 7 |
-
self.sentiment_labels = ["Positive", "Negative", "Neutral"]
|
| 8 |
-
self.intention_labels = ["Inquire", "Inform", "Payment", "Price", "Trade In", "Discount", "Complaint", "Approve", "Selling", "Confusion", "Change Package", "Upgrade", "Purchase", "Help"]
|
| 9 |
-
|
| 10 |
-
def create_model(self, model_name):
|
| 11 |
-
# Create Model
|
| 12 |
-
tokenizer = BartTokenizer.from_pretrained(model_name)
|
| 13 |
-
model = BartForSequenceClassification.from_pretrained(model_name)
|
| 14 |
-
classifier = pipeline("zero-shot-classification", model=model, tokenizer=tokenizer)
|
| 15 |
-
return classifier
|
| 16 |
-
|
| 17 |
-
def analyze_text(self, text):
|
| 18 |
-
# Sentiment analysis
|
| 19 |
-
sentiment_result = self.model(text, self.sentiment_labels)
|
| 20 |
-
sentiment = sentiment_result["labels"][0]
|
| 21 |
-
|
| 22 |
-
# Intention analysis
|
| 23 |
-
intention_result = self.model(text, self.intention_labels)
|
| 24 |
-
intention = intention_result["labels"][0]
|
| 25 |
-
|
| 26 |
-
return {"sentiment": sentiment, "intention": intention}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|