codealchemist01's picture
Upload README.md with huggingface_hub
f35ea6d verified

A newer version of the Gradio SDK is available: 6.1.0

Upgrade
metadata
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:

  1. DistilBERT Model (codealchemist01/financial-sentiment-distilbert)

    • Fast and efficient for real-time analysis
    • Based on DistilBERT-base-uncased
    • Optimized for speed without sacrificing accuracy
  2. 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
  3. 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