from transformers import AutoTokenizer, AutoModelForSequenceClassification # Load pre-trained model and tokenizer #model_name = "ProsusAI/finbert" #model_name = "ahmedrachid/FinancialBERT-Sentiment-Analysis" model_name="mrm8488/distilroberta-finetuned-financial-news-sentiment-analysis" tokenizer = AutoTokenizer.from_pretrained(model_name) model = AutoModelForSequenceClassification.from_pretrained(model_name) # Example: Classify a financial text text = "With the launch of Apple Silicon, Apple shares have increased" inputs = tokenizer(text, return_tensors="pt") outputs = model(**inputs) predictions = outputs.logits.argmax(dim=1).item() # 'predictions' will contain the sentiment class (e.g., 0 for negative, 1 for neutral, 2 for positive) print("Predicted sentiment class:", predictions)