Downloads · 30 days
11
2% of all-time downloads
sbasu2512/financial_sentiment_model
financial_sentiment_model is a text classification model from sbasu2512. Use it when you need a label for a piece of text. It is set up for transformers. The card lists the license as cc-by-nc-4.0.
financialsentimentmodel is a highly optimized financial sentiment analysis model fine-tuned for financial news, market headlines, and economic reports.
Downloads · 30 days
11
2% of all-time downloads
All-time downloads
526
Public
Repo size
13.1 GB
Likes
0
Public
Click a slice to open those files.
.onnx876 MB · 66%
From the Hugging Face model README
financial_sentiment_model is a highly optimized financial sentiment analysis model fine-tuned for financial news, market headlines, and economic reports.
Built on top of the robust ProsusAI/finbert architecture, this model classifies text into three distinct sentiment categories with high precision:
It is tailored to assist quantitative trading pipelines, risk management engines, and financial analysts in extracting crisp sentiment signals from volatile financial text.
Trainer)Performance evaluated at the end of each training epoch across the test/validation set:
| Metric | Epoch 1.0 | Epoch 2.0 | Epoch 3.0 (Final) |
|---|---|---|---|
| Validation Loss | 0.3272 | 0.2531 | 0.2462 |
| Accuracy | 90.64% | 94.68% | 94.98% |
| Weighted F1-Score | 0.9065 | 0.9469 | 0.9499 |
| Macro F1-Score | 0.9037 | 0.9406 | 0.9397 |
| Macro Precision | 0.8898 | 0.9341 | 0.9308 |
| Macro Recall | 0.9229 | 0.9474 | 0.9495 |
The final model achieves an overall Accuracy of 94.98% and a Weighted F1-Score of 0.9499, demonstrating exceptional precision and recall for financial sentiment inference.
from transformers import pipeline
pipe = pipeline("text-classification", model="sbasu2512/financial_sentiment_model")
texts = [
"Sensex surges 500 points as IT and banking stocks rally.",
"Rupee falls sharply against the dollar amid global uncertainty.",
"TCS announces leadership reshuffle; markets await further clarity.",
]
for t in texts:
print(pipe(t))
from transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained(
"sbasu2512/financial_sentiment_model"
)
model = AutoModelForSequenceClassification.from_pretrained(
"sbasu2512/financial_sentiment_model"
)
This repository contains an optimized ONNX Runtime version of the Financial Sentiment Analyzer for fast CPU and GPU inference.
pip install onnxruntime optimum transformers
For NVIDIA GPU inference:
pip install onnxruntime-gpu optimum transformers
Clone the repository:
git clone https://huggingface.co/sbasu2512/financial_sentiment_model
or download the model directly from Hugging Face:
from optimum.onnxruntime import ORTModelForSequenceClassification
from transformers import AutoTokenizer
MODEL_NAME = "sbasu2512/financial_sentiment_analyzer_v2"
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
model = ORTModelForSequenceClassification.from_pretrained(MODEL_NAME)
from optimum.onnxruntime import ORTModelForSequenceClassification
from transformers import AutoTokenizer
MODEL_PATH = "./financial_sentiment_analyzer_v2"
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
model = ORTModelForSequenceClassification.from_pretrained(MODEL_PATH)
import torch
from optimum.onnxruntime import ORTModelForSequenceClassification
from transformers import AutoTokenizer
MODEL_PATH = "./financial_sentiment_analyzer_v2"
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
model = ORTModelForSequenceClassification.from_pretrained(MODEL_PATH)
text = """
Reliance Industries reported record quarterly profits,
beating analyst expectations.
"""
inputs = tokenizer(
text,
return_tensors="pt",
truncation=True,
max_length=512,
)
outputs = model(**inputs)
prediction = torch.argmax(outputs.logits, dim=1).item()
labels = {
0: "Negative",
1: "Neutral",
2: "Positive",
}
print(labels[prediction])
Example output:
Positive
import torch
probabilities = torch.softmax(outputs.logits, dim=1)[0]
labels = ["Negative", "Neutral", "Positive"]
for label, probability in zip(labels, probabilities):
print(f"{label}: {probability:.4f}")
Example output:
Negative : 0.0124
Neutral : 0.0836
Positive : 0.9040
headlines = [
"Tata Motors reports record EV sales.",
"Markets remained largely unchanged today.",
"Company files for bankruptcy protection.",
]
inputs = tokenizer(
headlines,
padding=True,
truncation=True,
max_length=512,
return_tensors="pt",
)
outputs = model(**inputs)
predictions = torch.argmax(outputs.logits, dim=1)
labels = ["Negative", "Neutral", "Positive"]
for headline, pred in zip(headlines, predictions):
print(f"{headline}\n→ {labels[pred.item()]}\n")
Example output:
Tata Motors reports record EV sales.
→ Positive
Markets remained largely unchanged today.
→ Neutral
Company files for bankruptcy protection.
→ Negative
| ID | Sentiment |
|---|---|
| 0 | Negative |
| 1 | Neutral |
| 2 | Positive |
The ONNX version provides significantly faster inference than the original PyTorch model while maintaining identical predictions. It is suitable for:
This model is published under the Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0) license.