🧾 Model Card β€” financial_sentiment_model

🧠 Model Overview

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:

  • 🟒 Positive β€” Market gains, optimism, positive growth indicators
  • βšͺ Neutral β€” Factual reports, regulatory updates, mixed signals
  • πŸ”΄ Negative β€” Market declines, losses, macroeconomic risks

It is tailored to assist quantitative trading pipelines, risk management engines, and financial analysts in extracting crisp sentiment signals from volatile financial text.

πŸ—οΈ Training Details

  • Base Model: ProsusAI/finbert
  • Framework: PyTorch & Hugging Face Transformers (Trainer)
  • Training Epochs: 3 full epochs
  • Total Optimization Steps: 1,770 steps
  • Total Training Time: ~7 minutes 26 seconds (446.2s)
  • Evaluation Throughput: ~247 samples/sec

πŸ“Š Evaluation Metrics

Performance evaluated at the end of each training epoch across the test/validation set:

Final Benchmark (Epoch 3.0)

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.

πŸ’¬ Example Usage

Using Hugging Face Pipeline (High-Level)

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))

Loading the Model Directly

from transformers import AutoTokenizer, AutoModelForSequenceClassification

tokenizer = AutoTokenizer.from_pretrained(
    "sbasu2512/financial_sentiment_model"
)
model = AutoModelForSequenceClassification.from_pretrained(
    "sbasu2512/financial_sentiment_model"
)

πŸš€ Using the ONNX Model

This repository contains an optimized ONNX Runtime version of the Financial Sentiment Analyzer for fast CPU and GPU inference.

Installation

pip install onnxruntime optimum transformers

For NVIDIA GPU inference:

pip install onnxruntime-gpu optimum transformers

Download the Model

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)

Local Usage

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)

Basic Inference

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

Confidence Scores

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

Predict Multiple Headlines

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

Output Labels

ID Sentiment
0 Negative
1 Neutral
2 Positive

Performance

The ONNX version provides significantly faster inference than the original PyTorch model while maintaining identical predictions. It is suitable for:

  • Real-time news sentiment analysis
  • Trading pipelines
  • Financial research
  • Batch inference
  • REST APIs
  • Production deployment

🧩 Intended Use

  • Real-time sentiment analysis for Indian and global stock market news.
  • Generation of features and sentiment signals for algorithmic trading models.
  • Parsing and tone classification of corporate earnings reports or press releases.

πŸ“œ Licensing & Commercial Use

This model is published under the Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0) license.

  • Personal, Academic, and Research Use: Completely free.
  • Commercial Use: If you wish to use this model, its weights, or derivatives for commercial purposes, enterprise applications, or monetary gain, you must obtain a commercial license.

πŸ“§ Contact for Commercial Licensing

[email protected]

πŸ§‘β€πŸ’» Developer Info

Downloads last month
31
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ 2 Ask for provider support

Space using sbasu2512/financial_sentiment_model 1