Spaces:
No application file
No application file
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}") | |