Views
No views yet
distilbert-base-uncased for sentiment analysis on customer support tickets, capable of classifying text into five sentiment categories.1from transformers import pipeline
2
3# Load the sentiment analysis pipeline
4classifier = pipeline("text-classification", model="andyfe/siena-sentiment")
5
6# Example text
7text = """I am extremely disappointed with the customer service I received today. I've been waiting for a response for over a week, and when I finally got one, it didn't address my issue at all. This is unacceptable."""
8
9# Get prediction
10result = classifier(text)
11print(result)1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4# Load model and tokenizer
5tokenizer = AutoTokenizer.from_pretrained("andyfe/siena-sentiment")
6model = AutoModelForSequenceClassification.from_pretrained("andyfe/siena-sentiment")
7
8# Prepare input text
9text = "Your customer service team was incredibly helpful and resolved my issue quickly!"
10inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=128)
11
12# Get prediction
13outputs = model(**inputs)
14predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
15predicted_label = torch.argmax(predictions).item()
16
17# Map prediction to sentiment label
18id2label = {
19 0: "Strong Negative",
20 1: "Mild Negative",
21 2: "Neutral",
22 3: "Mild Positive",
23 4: "Strong Positive"
24}
25
26print(f"Predicted sentiment: {id2label[predicted_label]}")