A newer version of the Gradio SDK is available:
6.1.0
title: Financial Sentiment Analysis Ensemble
emoji: π
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: 4.44.0
app_file: app.py
pinned: false
license: apache-2.0
tags:
- financial-sentiment
- sentiment-analysis
- finance
- nlp
- ensemble
- transformers
- gradio
π Financial Sentiment Analysis Ensemble
An advanced AI-powered sentiment analysis system specifically designed for financial texts. This application uses an ensemble of three fine-tuned transformer models to provide highly accurate sentiment predictions for financial news, social media posts, and market commentary.
π― Features
- Ensemble Prediction: Combines predictions from 3 specialized models for higher accuracy
- Real-time Analysis: Instant sentiment analysis with confidence scores
- Interactive Interface: User-friendly Gradio interface with examples
- Detailed Results: Individual model predictions and probability distributions
- Financial Focus: Specifically trained on financial datasets
π§ Model Architecture
The ensemble consists of three fine-tuned models:
DistilBERT Model (
codealchemist01/financial-sentiment-distilbert)- Fast and efficient for real-time analysis
- Based on DistilBERT-base-uncased
- Optimized for speed without sacrificing accuracy
BERT-Large Model (
codealchemist01/financial-sentiment-bert-large)- High accuracy with deep contextual understanding
- Based on BERT-Large-uncased
- Superior performance on complex financial texts
Improved Model (
codealchemist01/financial-sentiment-improved)- Enhanced with advanced training techniques
- Balanced dataset training
- Custom loss functions and optimization
π Performance
- Ensemble Accuracy: 79.7%
- Individual Model Accuracies: 79.7% (DistilBERT), 84.3% (BERT-Large), 82.1% (Improved)
- Dataset: Twitter Financial News Sentiment
- Categories: Bearish π, Neutral β‘οΈ, Bullish π
π Usage
Web Interface
Simply enter your financial text in the input box and click "Analyze Sentiment" to get:
- Ensemble prediction with confidence score
- Probability distribution across all sentiment categories
- Individual predictions from each model
- Visual probability chart
API Usage
You can also use the individual models directly:
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
# Load any of the models
model_name = "codealchemist01/financial-sentiment-distilbert"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
def predict_sentiment(text):
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512)
with torch.no_grad():
outputs = model(**inputs)
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
labels = ["Bearish", "Neutral", "Bullish"]
predicted_class = torch.argmax(predictions, dim=-1).item()
confidence = predictions[0][predicted_class].item()
return {
"label": labels[predicted_class],
"confidence": confidence
}
# Example
result = predict_sentiment("The stock market is showing strong growth today")
print(result)
π Example Predictions
"Tesla's innovative battery technology could revolutionize the automotive industry."
- Prediction: Bullish π (85.2% confidence)
"Company earnings fell short of expectations, leading to a significant drop in share price."
- Prediction: Bearish π (91.7% confidence)
"The Federal Reserve maintained interest rates, keeping market conditions stable."
- Prediction: Neutral β‘οΈ (78.3% confidence)
π οΈ Technical Details
- Framework: Transformers, PyTorch
- Interface: Gradio 4.0+
- Training: Fine-tuned on financial datasets with advanced techniques
- Ensemble Method: Average probability aggregation
- Preprocessing: Text normalization and tokenization
π License
This project is licensed under the Apache 2.0 License.
π€ Contributing
Contributions are welcome! Please feel free to submit issues or pull requests.
π§ Contact
For questions or collaborations, please reach out through the Hugging Face community.
Built with β€οΈ for the financial AI community