AdityaAI9 commited on
Commit
054c79a
·
verified ·
1 Parent(s): c5e6fd0

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +182 -3
README.md CHANGED
@@ -1,3 +1,182 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Financial Sentiment Classifier 📈
2
+
3
+ A fine-tuned DistilBERT model for financial text sentiment analysis, capable of classifying financial news and statements into three categories: **positive**, **negative**, and **neutral**.
4
+
5
+ ## Model Description
6
+
7
+ This model is a fine-tuned version of [distilbert-base-uncased](https://huggingface.co/distilbert-base-uncased) specifically trained on financial text data for sentiment classification. It achieves **97.5% accuracy** on the validation set and is optimized for analyzing financial news, earnings reports, market commentary, and other finance-related text.
8
+
9
+ ### Key Features
10
+ - **High Performance**: 97.5% accuracy on financial sentiment classification
11
+ - **Fast Inference**: Built on DistilBERT for efficient processing
12
+ - **Domain-Specific**: Trained specifically on financial text data
13
+ - **Balanced Classes**: Handles positive, negative, and neutral sentiments effectively
14
+
15
+ ## Model Details
16
+
17
+ - **Base Model**: distilbert-base-uncased
18
+ - **Task**: Text Classification (Sentiment Analysis)
19
+ - **Language**: English
20
+ - **Domain**: Financial Text
21
+ - **Classes**: 3 (positive, negative, neutral)
22
+ - **Training Data**: ~36K financial text samples (original + synthetic data)
23
+
24
+ ### Performance Metrics
25
+
26
+ | Metric | Score |
27
+ |--------|-------|
28
+ | Accuracy | 97.52% |
29
+ | F1-Score | 97.51% |
30
+ | Precision | 97.52% |
31
+ | Recall | 97.52% |
32
+
33
+ ## Quick Start
34
+
35
+ ### Installation
36
+
37
+ ```bash
38
+ pip install transformers torch
39
+ ```
40
+
41
+ ### Usage
42
+
43
+ ```python
44
+ from transformers import pipeline
45
+
46
+ # Load the classifier
47
+ classifier = pipeline(
48
+ "text-classification",
49
+ model="AdityaAI9/distilbert_finance_sentiment_analysis"
50
+ )
51
+
52
+ # Analyze financial text
53
+ result = classifier("The company reported strong quarterly earnings with 15% revenue growth.")
54
+ print(result)
55
+ # Output: [{'label': 'positive', 'score': 0.9845}]
56
+
57
+ # Multiple examples
58
+ texts = [
59
+ "Stock prices fell sharply due to disappointing earnings.",
60
+ "The company maintained steady performance this quarter.",
61
+ "Revenue exceeded expectations with record-breaking profits."
62
+ ]
63
+
64
+ results = classifier(texts)
65
+ for text, result in zip(texts, results):
66
+ print(f"Text: {text}")
67
+ print(f"Sentiment: {result['label']} (confidence: {result['score']:.3f})")
68
+ print("-" * 50)
69
+ ```
70
+
71
+ ### Advanced Usage
72
+
73
+ ```python
74
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
75
+ import torch
76
+
77
+ # Load model and tokenizer
78
+ tokenizer = AutoTokenizer.from_pretrained("AdityaAI9/distilbert_finance_sentiment_analysis")
79
+ model = AutoModelForSequenceClassification.from_pretrained("AdityaAI9/distilbert_finance_sentiment_analysis")
80
+
81
+ # Manual prediction
82
+ text = "The merger is expected to create significant shareholder value."
83
+ inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=256)
84
+
85
+ with torch.no_grad():
86
+ outputs = model(**inputs)
87
+ predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
88
+ predicted_class = torch.argmax(predictions, dim=-1)
89
+
90
+ # Map to labels
91
+ label_mapping = {0: "negative", 1: "neutral", 2: "positive"}
92
+ sentiment = label_mapping[predicted_class.item()]
93
+ confidence = predictions.max().item()
94
+
95
+ print(f"Sentiment: {sentiment} (confidence: {confidence:.3f})")
96
+ ```
97
+
98
+ ## Training Data
99
+
100
+ The model was trained on a combination of:
101
+
102
+ 1. **Original Financial News Dataset**: ~5K labeled financial news sentences
103
+ 2. **Synthetic Financial Data**: ~31K synthetic financial statements generated using state-of-the-art language models
104
+
105
+ The synthetic data generation approach helps address class imbalance and provides diverse financial vocabulary coverage. You can find the synthetic data generation code [here](https://github.com/aditya699/Common-Challenges-in-LLMS-/blob/main/synthetic_data_generator/syndata.py).
106
+
107
+ ### Data Distribution
108
+ - **Neutral**: 14,638 samples (40.2%)
109
+ - **Negative**: 11,272 samples (31.0%)
110
+ - **Positive**: 10,539 samples (28.8%)
111
+
112
+ ## Training Details
113
+
114
+ ### Training Hyperparameters
115
+ - **Epochs**: 5
116
+ - **Batch Size**: 16 (training), 32 (validation)
117
+ - **Learning Rate**: Default AdamW
118
+ - **Max Sequence Length**: 256 tokens
119
+ - **Optimizer**: AdamW
120
+ - **Warmup**: Linear warmup
121
+
122
+ ### Training Infrastructure
123
+ - **GPU**: CUDA-enabled training
124
+ - **Framework**: Hugging Face Transformers
125
+ - **Evaluation Strategy**: Every 500 steps
126
+
127
+ ## Use Cases
128
+
129
+ This model is particularly useful for:
130
+
131
+ - **Financial News Analysis**: Classify sentiment of news articles affecting stock prices
132
+ - **Earnings Report Processing**: Analyze quarterly and annual reports
133
+ - **Market Research**: Sentiment analysis of financial commentary and analyst reports
134
+ - **Trading Signals**: Generate sentiment-based trading indicators
135
+ - **Risk Assessment**: Evaluate sentiment trends for investment decisions
136
+ - **Social Media Monitoring**: Analyze financial discussions on social platforms
137
+
138
+ ## Limitations and Considerations
139
+
140
+ - **Domain Specificity**: Optimized for financial text; may not perform well on general sentiment tasks
141
+ - **Language**: Currently supports English only
142
+ - **Context Window**: Limited to 256 tokens; longer texts will be truncated
143
+ - **Temporal Bias**: Trained on contemporary financial language; may need updates for evolving terminology
144
+ - **Market Context**: Does not consider broader market conditions or temporal context
145
+
146
+ ## Ethical Considerations
147
+
148
+ - This model should not be the sole basis for financial decisions
149
+ - Always combine with fundamental analysis and professional financial advice
150
+ - Be aware of potential biases in training data
151
+ - Consider market volatility and external factors not captured in text
152
+
153
+ ## Citation
154
+
155
+ If you use this model in your research or applications, please cite:
156
+
157
+ ```bibtex
158
+ @misc{distilbert-finance-sentiment-analysis,
159
+ title={Financial Sentiment Classifier: A Fine-tuned DistilBERT Model},
160
+ author={AdityaAI9},
161
+ year={2024},
162
+ howpublished={\url{https://huggingface.co/AdityaAI9/distilbert_finance_sentiment_analysis}},
163
+ }
164
+ ```
165
+
166
+ ## License
167
+
168
+ This model is released under the MIT License. See LICENSE for more details.
169
+
170
+ ## Acknowledgments
171
+
172
+ - Built using [Hugging Face Transformers](https://huggingface.co/transformers/)
173
+ - Base model: [DistilBERT](https://huggingface.co/distilbert-base-uncased)
174
+ - Synthetic data generation techniques for improved model performance
175
+
176
+ ## Contact
177
+
178
+ For questions, suggestions, or collaboration opportunities, please open an issue in the [GitHub repository](https://github.com/aditya699/Common-Challenges-in-LLMS-) or reach out through Hugging Face.
179
+
180
+ ---
181
+
182
+ **Note**: This model is for research and educational purposes. Always consult with financial professionals before making investment decisions.