Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,12 +1,136 @@
|
|
| 1 |
---
|
| 2 |
-
title: Financial Sentiment Ensemble
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
-
app_file:
|
| 9 |
pinned: false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Financial Sentiment Analysis Ensemble
|
| 3 |
+
emoji: π
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.44.0
|
| 8 |
+
app_file: space_app.py
|
| 9 |
pinned: false
|
| 10 |
+
license: apache-2.0
|
| 11 |
+
tags:
|
| 12 |
+
- financial-sentiment
|
| 13 |
+
- sentiment-analysis
|
| 14 |
+
- finance
|
| 15 |
+
- nlp
|
| 16 |
+
- ensemble
|
| 17 |
+
- transformers
|
| 18 |
+
- gradio
|
| 19 |
---
|
| 20 |
|
| 21 |
+
# π Financial Sentiment Analysis Ensemble
|
| 22 |
+
|
| 23 |
+
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.
|
| 24 |
+
|
| 25 |
+
## π― Features
|
| 26 |
+
|
| 27 |
+
- **Ensemble Prediction**: Combines predictions from 3 specialized models for higher accuracy
|
| 28 |
+
- **Real-time Analysis**: Instant sentiment analysis with confidence scores
|
| 29 |
+
- **Interactive Interface**: User-friendly Gradio interface with examples
|
| 30 |
+
- **Detailed Results**: Individual model predictions and probability distributions
|
| 31 |
+
- **Financial Focus**: Specifically trained on financial datasets
|
| 32 |
+
|
| 33 |
+
## π§ Model Architecture
|
| 34 |
+
|
| 35 |
+
The ensemble consists of three fine-tuned models:
|
| 36 |
+
|
| 37 |
+
1. **DistilBERT Model** (`codealchemist01/financial-sentiment-distilbert`)
|
| 38 |
+
- Fast and efficient for real-time analysis
|
| 39 |
+
- Based on DistilBERT-base-uncased
|
| 40 |
+
- Optimized for speed without sacrificing accuracy
|
| 41 |
+
|
| 42 |
+
2. **BERT-Large Model** (`codealchemist01/financial-sentiment-bert-large`)
|
| 43 |
+
- High accuracy with deep contextual understanding
|
| 44 |
+
- Based on BERT-Large-uncased
|
| 45 |
+
- Superior performance on complex financial texts
|
| 46 |
+
|
| 47 |
+
3. **Improved Model** (`codealchemist01/financial-sentiment-improved`)
|
| 48 |
+
- Enhanced with advanced training techniques
|
| 49 |
+
- Balanced dataset training
|
| 50 |
+
- Custom loss functions and optimization
|
| 51 |
+
|
| 52 |
+
## π Performance
|
| 53 |
+
|
| 54 |
+
- **Ensemble Accuracy**: 79.7%
|
| 55 |
+
- **Individual Model Accuracies**: 79.7% (DistilBERT), 84.3% (BERT-Large), 82.1% (Improved)
|
| 56 |
+
- **Dataset**: Twitter Financial News Sentiment
|
| 57 |
+
- **Categories**: Bearish π, Neutral β‘οΈ, Bullish π
|
| 58 |
+
|
| 59 |
+
## π Usage
|
| 60 |
+
|
| 61 |
+
### Web Interface
|
| 62 |
+
|
| 63 |
+
Simply enter your financial text in the input box and click "Analyze Sentiment" to get:
|
| 64 |
+
- Ensemble prediction with confidence score
|
| 65 |
+
- Probability distribution across all sentiment categories
|
| 66 |
+
- Individual predictions from each model
|
| 67 |
+
- Visual probability chart
|
| 68 |
+
|
| 69 |
+
### API Usage
|
| 70 |
+
|
| 71 |
+
You can also use the individual models directly:
|
| 72 |
+
|
| 73 |
+
```python
|
| 74 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 75 |
+
import torch
|
| 76 |
+
|
| 77 |
+
# Load any of the models
|
| 78 |
+
model_name = "codealchemist01/financial-sentiment-distilbert"
|
| 79 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 80 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 81 |
+
|
| 82 |
+
def predict_sentiment(text):
|
| 83 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512)
|
| 84 |
+
|
| 85 |
+
with torch.no_grad():
|
| 86 |
+
outputs = model(**inputs)
|
| 87 |
+
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
| 88 |
+
|
| 89 |
+
labels = ["Bearish", "Neutral", "Bullish"]
|
| 90 |
+
predicted_class = torch.argmax(predictions, dim=-1).item()
|
| 91 |
+
confidence = predictions[0][predicted_class].item()
|
| 92 |
+
|
| 93 |
+
return {
|
| 94 |
+
"label": labels[predicted_class],
|
| 95 |
+
"confidence": confidence
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
# Example
|
| 99 |
+
result = predict_sentiment("The stock market is showing strong growth today")
|
| 100 |
+
print(result)
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
## π Example Predictions
|
| 104 |
+
|
| 105 |
+
- **"Tesla's innovative battery technology could revolutionize the automotive industry."**
|
| 106 |
+
- Prediction: Bullish π (85.2% confidence)
|
| 107 |
+
|
| 108 |
+
- **"Company earnings fell short of expectations, leading to a significant drop in share price."**
|
| 109 |
+
- Prediction: Bearish π (91.7% confidence)
|
| 110 |
+
|
| 111 |
+
- **"The Federal Reserve maintained interest rates, keeping market conditions stable."**
|
| 112 |
+
- Prediction: Neutral β‘οΈ (78.3% confidence)
|
| 113 |
+
|
| 114 |
+
## π οΈ Technical Details
|
| 115 |
+
|
| 116 |
+
- **Framework**: Transformers, PyTorch
|
| 117 |
+
- **Interface**: Gradio 4.0+
|
| 118 |
+
- **Training**: Fine-tuned on financial datasets with advanced techniques
|
| 119 |
+
- **Ensemble Method**: Average probability aggregation
|
| 120 |
+
- **Preprocessing**: Text normalization and tokenization
|
| 121 |
+
|
| 122 |
+
## π License
|
| 123 |
+
|
| 124 |
+
This project is licensed under the Apache 2.0 License.
|
| 125 |
+
|
| 126 |
+
## π€ Contributing
|
| 127 |
+
|
| 128 |
+
Contributions are welcome! Please feel free to submit issues or pull requests.
|
| 129 |
+
|
| 130 |
+
## π§ Contact
|
| 131 |
+
|
| 132 |
+
For questions or collaborations, please reach out through the Hugging Face community.
|
| 133 |
+
|
| 134 |
+
---
|
| 135 |
+
|
| 136 |
+
*Built with β€οΈ for the financial AI community*
|