Downloads · 30 days
122
1% of all-time downloads
SeanD103/Longformer_for_financial_sentiment_analysis
Longformer_for_financial_sentiment_analysis is a text classification model from SeanD103. Use it when you need a label for a piece of text. It is set up for transformers. The card lists the license as mit.
The Longformerforfinancialsentimentanalysis model is a fine-tuned version of the Longformer by Allen AI, fine-tuned for sentiment analysis of financial text. The fine-tuning process used the Financial PhraseBank datas…
Downloads · 30 days
122
1% of all-time downloads
All-time downloads
14.3K
Public
Parameters
149M
595 MB on disk
Likes
2
Public
Click a slice to open those files.
.safetensors595 MB · 99%
From the Hugging Face model README
The Longformer_for_financial_sentiment_analysis model is a fine-tuned version of the Longformer by Allen AI, fine-tuned for sentiment analysis of financial text. The fine-tuning process used the Financial PhraseBank dataset, a collection of financial news sentences annotated with sentiment.
This model is designed to classify the sentiment of financial text, such as news articles, earnings reports, and financial statements. Using the Longformer's ability to handle long documents efficiently, this model can process extended texts up to 4096 tokens, making it suitable for longer financial texts.
The model was fine-tuned on the Financial PhraseBank dataset, which contains 4840 sentences selected from financial news and annotated with their associated sentiment.
from transformers import AutoTokenizer, AutoModelForSequenceClassification
# Load the tokenizer and model
model_path = "SeanD103/Longformer_for_financial_sentiment_analysis"
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForSequenceClassification.from_pretrained(model_path)
# Example input
example_text = "The company's quarterly earnings exceeded expectations, leading to a rise in stock prices."
# Tokenize and get predictions
inputs = tokenizer(example_text, return_tensors="pt", truncation=True, padding=True)
outputs = model(**inputs)
predictions = outputs.logits.argmax(-1)
# Map predictions to labels
sentiment_mapping = {0: "Negative", 1: "Neutral", 2: "Positive"}
sentiment = sentiment_mapping[predictions.item()]
print(f'Input text: {example_text} \nEstimated sentiment: {sentiment}')
This model is based on the Longformer architecture developed by Allen AI and has been fine-tuned using the Financial PhraseBank dataset by Malo et al.