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