--- title: Financial Sentiment Analysis Ensemble emoji: 📈 colorFrom: blue colorTo: purple sdk: gradio sdk_version: 4.44.0 app_file: space_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: ```python 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*