FinBERT Financial Sentiment Classification
Model Description
Purpose: This model is a fine-tuned version of BERT, adapted for financial sentiment classification. It is specifically designed to classify financial text into categories like positive, negative, and neutral.
Architecture: Based on the BERT architecture, this model has been fine-tuned on financial texts, optimizing it for use in sentiment analysis within the finance sector.
Training Data: The model was trained on a financial dataset containing news headlines, analyst reports, and other finance-related text sources, labeled for sentiment.
Intended Use Cases: Ideal for applications in finance, such as analyzing news articles, earnings reports, and social media for sentiment to aid in investment analysis, trading decisions, or financial forecasting.
Framework: PyTorch with Hugging Face Transformers
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4# Load the tokenizer and model
5tokenizer = AutoTokenizer.from_pretrained("heroiclunatic/finbert-finance-classification")
6model = AutoModelForSequenceClassification.from_pretrained("heroiclunatic/finbert-finance-classification")
7
8# Sample text
9text = "Elon musk reports that all the board of directors of tesla resign"
10
11# Preprocess text
12inputs = tokenizer(text, return_tensors="pt")
13outputs = model(**inputs)
14
15# Get sentiment scores
16logits = outputs.logits
17predicted_class = torch.argmax(logits, dim=1).item()
18labels = ["Negative", "Neutral", "Positive"]
19print(f"Sentiment: {labels[predicted_class]}")