Views
No views yet
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4model_name = "your_username/FinancialNewsSentimentAnalyzer" # Replace with actual hub path
5tokenizer = AutoTokenizer.from_pretrained(model_name)
6model = AutoModelForSequenceClassification.from_pretrained(model_name)
7
8headline = "Tesla Stock Surges 8% Following Unexpectedly Strong Q3 Delivery Numbers"
9inputs = tokenizer(headline, return_tensors="pt")
10
11with torch.no_grad():
12 logits = model(**inputs).logits
13
14predicted_class_id = logits.argmax().item()
15predicted_label = model.config.id2label[predicted_class_id]
16
17print(f"Headline: {headline}")
18print(f"Predicted Sentiment: {predicted_label}")