Views
No views yet
1from transformers import AutoModelForSequenceClassification, AutoTokenizer
2import torch
3
4# Load model and tokenizer
5model_name = "MIMEDIS/stance-model"
6model = AutoModelForSequenceClassification.from_pretrained(model_name)
7tokenizer = AutoTokenizer.from_pretrained(model_name)
8
9# Prepare input
10text = "Migrácia obohacuje našu spoločnosť o nové perspektívy a kultúry."
11inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=512)
12
13# Get predictions
14with torch.no_grad():
15 outputs = model(**inputs)
16 predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
17 predicted_class = torch.argmax(predictions, dim=-1).item()
18
19# Map class to label
20labels = {0: "NEGATIVE", 1: "NEUTRAL", 2: "POSITIVE"}
21
22print(f"Text: {text}")
23print(f"Predicted stance: {labels[predicted_class]}")
24print(f"Confidence: {predictions[0][predicted_class]:.4f}")
25print(f"All probabilities: NEGATIVE={predictions[0][0]:.4f}, NEUTRAL={predictions[0][1]:.4f}, POSITIVE={predictions[0][2]:.4f}")