Add comprehensive model card
Browse files
README.md
ADDED
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language: en
|
3 |
+
license: apache-2.0
|
4 |
+
base_model: google/gemma-7b
|
5 |
+
tags:
|
6 |
+
- financial-sentiment-analysis
|
7 |
+
- fine-tuned
|
8 |
+
- peft
|
9 |
+
- lora
|
10 |
+
- financial-phrasebank
|
11 |
+
- gemma
|
12 |
+
datasets:
|
13 |
+
- financial_phrasebank
|
14 |
+
metrics:
|
15 |
+
- accuracy
|
16 |
+
- f1
|
17 |
+
- precision
|
18 |
+
- recall
|
19 |
+
model-index:
|
20 |
+
- name: trained-gemma-sentences_allagree
|
21 |
+
results:
|
22 |
+
- task:
|
23 |
+
type: text-classification
|
24 |
+
name: Financial Sentiment Analysis
|
25 |
+
dataset:
|
26 |
+
type: financial_phrasebank
|
27 |
+
name: Financial PhraseBank
|
28 |
+
config: sentences_allagree
|
29 |
+
metrics:
|
30 |
+
- type: accuracy
|
31 |
+
value: 0.876
|
32 |
+
name: Accuracy
|
33 |
+
- type: f1
|
34 |
+
value: 0.870
|
35 |
+
name: F1 Score
|
36 |
+
- type: precision
|
37 |
+
value: 0.875
|
38 |
+
name: Precision
|
39 |
+
- type: recall
|
40 |
+
value: 0.865
|
41 |
+
name: Recall
|
42 |
+
---
|
43 |
+
|
44 |
+
# Trained Gemma Sentences_Allagree
|
45 |
+
|
46 |
+
## Model Description
|
47 |
+
|
48 |
+
Gemma-7B fine-tuned on financial sentiment (100% agreement threshold). This model was fine-tuned using LoRA (Low-Rank Adaptation) on the Financial PhraseBank dataset with 100% annotator agreement threshold.
|
49 |
+
|
50 |
+
## Model Details
|
51 |
+
|
52 |
+
- **Base Model**: google/gemma-7b
|
53 |
+
- **Fine-tuning Method**: LoRA (Low-Rank Adaptation)
|
54 |
+
- **Dataset**: Financial PhraseBank (sentences with 100% annotator agreement)
|
55 |
+
- **Task**: Financial Sentiment Analysis (3-class: positive, negative, neutral)
|
56 |
+
- **Language**: English
|
57 |
+
|
58 |
+
## Performance
|
59 |
+
|
60 |
+
| Metric | Value |
|
61 |
+
|--------|-------|
|
62 |
+
| Accuracy | 87.6% |
|
63 |
+
| F1 Score | 87.0% |
|
64 |
+
| Precision | 87.5% |
|
65 |
+
| Recall | 86.5% |
|
66 |
+
|
67 |
+
## Training Details
|
68 |
+
|
69 |
+
This model was fine-tuned as part of a Final Year Project on Financial Sentiment Analysis and Stock Prediction. The training used:
|
70 |
+
|
71 |
+
- **Training Framework**: Transformers + PEFT
|
72 |
+
- **Quantization**: 4-bit quantization using BitsAndBytes
|
73 |
+
- **Hardware**: CUDA-enabled GPU
|
74 |
+
- **Hyperparameter Optimization**: Extensive Optuna-based tuning
|
75 |
+
|
76 |
+
## Usage
|
77 |
+
|
78 |
+
```python
|
79 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
80 |
+
from peft import PeftModel
|
81 |
+
import torch
|
82 |
+
|
83 |
+
# Load base model and tokenizer
|
84 |
+
base_model = AutoModelForCausalLM.from_pretrained(
|
85 |
+
"google/gemma-7b",
|
86 |
+
torch_dtype=torch.float16,
|
87 |
+
device_map="auto"
|
88 |
+
)
|
89 |
+
tokenizer = AutoTokenizer.from_pretrained("google/gemma-7b")
|
90 |
+
|
91 |
+
# Load fine-tuned model
|
92 |
+
model = PeftModel.from_pretrained(base_model, "jengyang/trained-gemma-sentences_allagree-financial-sentiment")
|
93 |
+
|
94 |
+
# Prepare input
|
95 |
+
text = "The company reported strong quarterly earnings, exceeding analyst expectations."
|
96 |
+
prompt = f"Classify the sentiment of this financial text as positive, negative, or neutral: {text}\n\nSentiment:"
|
97 |
+
|
98 |
+
# Tokenize and generate
|
99 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
100 |
+
with torch.no_grad():
|
101 |
+
outputs = model.generate(
|
102 |
+
**inputs,
|
103 |
+
max_new_tokens=10,
|
104 |
+
do_sample=False,
|
105 |
+
pad_token_id=tokenizer.eos_token_id
|
106 |
+
)
|
107 |
+
|
108 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
109 |
+
print(response)
|
110 |
+
```
|
111 |
+
|
112 |
+
## Training Data
|
113 |
+
|
114 |
+
The model was trained on the Financial PhraseBank dataset, specifically using sentences where 100% of annotators agreed on the sentiment label. This ensures higher quality and consistency in the training data.
|
115 |
+
|
116 |
+
The Financial PhraseBank contains financial news headlines categorized into:
|
117 |
+
- **Positive**: Favorable financial news
|
118 |
+
- **Negative**: Unfavorable financial news
|
119 |
+
- **Neutral**: Factual financial information without clear sentiment
|
120 |
+
|
121 |
+
## Evaluation
|
122 |
+
|
123 |
+
The model was evaluated on a held-out test set from the Financial PhraseBank dataset. The evaluation metrics reflect performance on financial sentiment classification with the 100% agreement threshold.
|
124 |
+
|
125 |
+
**Note**: Gemma models in this series achieved up to 87.6% accuracy, representing state-of-the-art performance on financial sentiment analysis tasks.
|
126 |
+
|
127 |
+
## Limitations and Bias
|
128 |
+
|
129 |
+
- The model is specifically designed for financial text sentiment analysis
|
130 |
+
- Performance may vary on non-financial text or different domains
|
131 |
+
- The model reflects the biases present in the Financial PhraseBank dataset
|
132 |
+
- Results should be interpreted within the context of financial sentiment analysis
|
133 |
+
- The model may not capture nuanced sentiment in complex financial scenarios
|
134 |
+
|
135 |
+
## Intended Use
|
136 |
+
|
137 |
+
**Intended Use Cases:**
|
138 |
+
- Financial news sentiment analysis
|
139 |
+
- Investment research and analysis
|
140 |
+
- Automated financial content classification
|
141 |
+
- Academic research in financial NLP
|
142 |
+
|
143 |
+
**Out-of-Scope Use Cases:**
|
144 |
+
- General-purpose sentiment analysis
|
145 |
+
- Medical or legal text analysis
|
146 |
+
- Real-time trading decisions without human oversight
|
147 |
+
|
148 |
+
## Citation
|
149 |
+
|
150 |
+
If you use this model, please cite:
|
151 |
+
|
152 |
+
```bibtex
|
153 |
+
@misc{trained_gemma_sentences_allagree,
|
154 |
+
title={Trained Gemma Sentences_Allagree: Fine-tuned gemma-7b for Financial Sentiment Analysis},
|
155 |
+
author={Final Year Project},
|
156 |
+
year={2024},
|
157 |
+
howpublished={\url{https://huggingface.co/jengyang/trained-gemma-sentences_allagree-financial-sentiment}}
|
158 |
+
}
|
159 |
+
```
|
160 |
+
|
161 |
+
## Model Card Authors
|
162 |
+
|
163 |
+
This model card was generated as part of a Final Year Project on Financial Sentiment Analysis and Stock Prediction.
|