takala/financial_phrasebank
Updated • 8.75k • 257
Fine-tuned FinBERT model for financial sentiment analysis of stock-related news headlines.
This model is a fine-tuned version of ProsusAI/finbert on financial sentiment data. It classifies financial text into three categories:
| Metric | Score |
|---|---|
| Accuracy | 81.88% |
| F1 Macro | 0.8009 |
| F1 Weighted | 0.8259 |
| Class | F1 Score |
|---|---|
| Negative | 0.6719 |
| Neutral | 0.8203 |
| Positive | 0.9104 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
# Load model and tokenizer
model_name = "suha-memon/finbert-stock-sentiment"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
# Example usage
headline = "Apple announces record-breaking quarterly earnings"
inputs = tokenizer(headline, return_tensors="pt", truncation=True, max_length=128)
with torch.no_grad():
outputs = model(**inputs)
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
# Get probabilities
negative_prob = predictions[0][0].item()
neutral_prob = predictions[0][1].item()
positive_prob = predictions[0][2].item()
print(f"Negative: {negative_prob:.2%}")
print(f"Neutral: {neutral_prob:.2%}")
print(f"Positive: {positive_prob:.2%}")
This model is designed for:
The model was trained on financial sentiment data from Kaggle, consisting of:
Class distribution was imbalanced with fewer negative examples, addressed using Focal Loss.
If you use this model, please cite:
@misc{finbert-stock-sentiment,
author = {Your Name},
title = {FinBERT Stock Sentiment Analyzer},
year = {2025},
publisher = {Hugging Face},
howpublished = {\url{https://huggingface.co/suha-memon/finbert-stock-sentiment}}
}