Spaces:
No application file
No application file
Create customer sentiment
Browse files- customer sentiment +22 -0
customer sentiment
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
|
| 3 |
+
# Initialize the Hugging Face zero-shot classification pipeline
|
| 4 |
+
classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
|
| 5 |
+
|
| 6 |
+
# Review text to analyze
|
| 7 |
+
review_text = "The product's quality was poor, and customer service was useless. I was quite unsatisfied with my experience."
|
| 8 |
+
|
| 9 |
+
# Define the labels for sentiment classification
|
| 10 |
+
labels = ["POSITIVE", "NEUTRAL", "NEGATIVE"]
|
| 11 |
+
|
| 12 |
+
# Perform zero-shot classification
|
| 13 |
+
result = classifier(review_text, labels)
|
| 14 |
+
|
| 15 |
+
# Print the results
|
| 16 |
+
print("Review Analysis:")
|
| 17 |
+
for i, label in enumerate(result['labels']):
|
| 18 |
+
print(f"{label}: {result['scores'][i]:.4f}")
|
| 19 |
+
|
| 20 |
+
# Output the label with the highest score as the predicted sentiment
|
| 21 |
+
predicted_sentiment = result['labels'][0] # The label with the highest score is at index 0
|
| 22 |
+
print(f"\nPredicted Sentiment: {predicted_sentiment}")
|