Views
No views yet
1# Sample text to predict
2text = "I love this movie, it was fantastic!"
3
4# Tokenize the input text
5inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
6
7# Get model predictions
8with torch.no_grad():
9 outputs = model(**inputs)
10
11# Get the logits (model's raw output)
12logits = outputs.logits
13
14# Convert logits to probabilities (if needed) and get the predicted class (0 or 1)
15predictions = torch.argmax(logits, dim=-1).item()
16
17# Map the prediction to sentiment labels
18labels = {0: "NEGATIVE", 1: "POSITIVE"} # Assuming binary classification
19predicted_label = labels[predictions]
20
21print(f"Predicted Sentiment: {predicted_label}")