Rezaul Karim
commited on
Commit
•
2ec2d86
1
Parent(s):
1b7c35e
Update README.md
Browse files
README.md
CHANGED
@@ -1,94 +1,131 @@
|
|
1 |
---
|
2 |
library_name: transformers
|
3 |
-
|
|
|
|
|
4 |
---
|
5 |
|
6 |
# Model Card for Model ID
|
7 |
-
|
8 |
-
<!-- Provide a quick summary of what the model is/does. -->
|
9 |
-
|
10 |
-
|
11 |
|
12 |
## Model Details
|
13 |
|
14 |
### Model Description
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
### Model Sources [optional]
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
- **
|
33 |
-
- **Paper [optional]:** [More Information Needed]
|
34 |
-
- **Demo [optional]:** [More Information Needed]
|
35 |
|
36 |
## Uses
|
37 |
|
38 |
-
|
39 |
|
40 |
-
|
41 |
|
42 |
-
|
43 |
|
44 |
[More Information Needed]
|
45 |
|
46 |
-
|
47 |
|
48 |
-
|
49 |
|
50 |
-
|
51 |
|
52 |
-
|
53 |
|
54 |
-
|
|
|
55 |
|
56 |
-
|
|
|
57 |
|
58 |
-
|
59 |
|
60 |
-
|
|
|
|
|
61 |
|
62 |
-
|
|
|
63 |
|
64 |
-
|
65 |
|
66 |
-
|
|
|
67 |
|
68 |
-
|
|
|
|
|
69 |
|
70 |
-
|
71 |
|
72 |
-
|
|
|
73 |
|
74 |
-
|
75 |
|
76 |
-
|
|
|
77 |
|
78 |
-
|
79 |
|
80 |
-
|
|
|
81 |
|
82 |
-
|
|
|
83 |
|
84 |
-
###
|
85 |
|
86 |
-
|
|
|
87 |
|
88 |
-
|
89 |
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
|
|
|
|
|
|
|
92 |
|
93 |
#### Training Hyperparameters
|
94 |
|
@@ -102,27 +139,15 @@ Use the code below to get started with the model.
|
|
102 |
|
103 |
## Evaluation
|
104 |
|
105 |
-
|
106 |
|
107 |
-
|
108 |
|
109 |
-
|
|
|
|
|
110 |
|
111 |
-
|
112 |
-
|
113 |
-
[More Information Needed]
|
114 |
-
|
115 |
-
#### Factors
|
116 |
-
|
117 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
118 |
-
|
119 |
-
[More Information Needed]
|
120 |
-
|
121 |
-
#### Metrics
|
122 |
-
|
123 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
124 |
-
|
125 |
-
[More Information Needed]
|
126 |
|
127 |
### Results
|
128 |
|
@@ -130,44 +155,6 @@ Use the code below to get started with the model.
|
|
130 |
|
131 |
#### Summary
|
132 |
|
133 |
-
|
134 |
-
|
135 |
-
## Model Examination [optional]
|
136 |
-
|
137 |
-
<!-- Relevant interpretability work for the model goes here -->
|
138 |
-
|
139 |
-
[More Information Needed]
|
140 |
-
|
141 |
-
## Environmental Impact
|
142 |
-
|
143 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
144 |
-
|
145 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
146 |
-
|
147 |
-
- **Hardware Type:** [More Information Needed]
|
148 |
-
- **Hours used:** [More Information Needed]
|
149 |
-
- **Cloud Provider:** [More Information Needed]
|
150 |
-
- **Compute Region:** [More Information Needed]
|
151 |
-
- **Carbon Emitted:** [More Information Needed]
|
152 |
-
|
153 |
-
## Technical Specifications [optional]
|
154 |
-
|
155 |
-
### Model Architecture and Objective
|
156 |
-
|
157 |
-
[More Information Needed]
|
158 |
-
|
159 |
-
### Compute Infrastructure
|
160 |
-
|
161 |
-
[More Information Needed]
|
162 |
-
|
163 |
-
#### Hardware
|
164 |
-
|
165 |
-
[More Information Needed]
|
166 |
-
|
167 |
-
#### Software
|
168 |
-
|
169 |
-
[More Information Needed]
|
170 |
-
|
171 |
## Citation [optional]
|
172 |
|
173 |
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
@@ -176,26 +163,7 @@ Carbon emissions can be estimated using the [Machine Learning Impact calculator]
|
|
176 |
|
177 |
[More Information Needed]
|
178 |
|
179 |
-
**APA:**
|
180 |
-
|
181 |
-
[More Information Needed]
|
182 |
-
|
183 |
-
## Glossary [optional]
|
184 |
-
|
185 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
186 |
-
|
187 |
-
[More Information Needed]
|
188 |
-
|
189 |
-
## More Information [optional]
|
190 |
-
|
191 |
-
[More Information Needed]
|
192 |
-
|
193 |
-
## Model Card Authors [optional]
|
194 |
-
|
195 |
-
[More Information Needed]
|
196 |
|
197 |
## Model Card Contact
|
198 |
|
199 |
-
|
200 |
-
|
201 |
-
|
|
|
1 |
---
|
2 |
library_name: transformers
|
3 |
+
license: mit
|
4 |
+
language:
|
5 |
+
- en
|
6 |
---
|
7 |
|
8 |
# Model Card for Model ID
|
9 |
+
https://huggingface.co/rezahf2024/fine_tuned_financial_setiment_analysis_gpt2_model
|
|
|
|
|
|
|
10 |
|
11 |
## Model Details
|
12 |
|
13 |
### Model Description
|
14 |
|
15 |
+
This a fine-tuned GPT2 model on the https://huggingface.co/datasets/FinGPT/fingpt-sentiment-train dataset for the down-stream financial sentiment analysis.
|
16 |
+
|
17 |
+
label_mapping = {
|
18 |
+
'LABEL_0': 'mildly positive',
|
19 |
+
'LABEL_1': 'mildly negative',
|
20 |
+
'LABEL_2': 'moderately negative',
|
21 |
+
'LABEL_3': 'moderately positive',
|
22 |
+
'LABEL_4': 'positive',
|
23 |
+
'LABEL_5': 'negative',
|
24 |
+
'LABEL_6': 'neutral',
|
25 |
+
'LABEL_7': 'strong negative',
|
26 |
+
'LABEL_8': 'strong positive'
|
27 |
+
}
|
28 |
+
|
29 |
+
- **Developed by:** Rezaul Karim, Ph.D.
|
30 |
+
- **Funded by [optional]:** Self
|
31 |
+
- **Shared by [optional]:** Rezaul Karim, Ph.D.
|
32 |
+
- **Model type:** Fine-tuned GPT2
|
33 |
+
- **Language(s) (NLP):** financial sentiment analysis
|
34 |
+
- **License:** MIT
|
35 |
+
- **Finetuned from model [optional]:** https://huggingface.co/datasets/mteb/tweet_sentiment_extraction
|
36 |
|
37 |
### Model Sources [optional]
|
38 |
|
39 |
+
- **Repository:** https://github.com/rezacsedu/financial_sentiment_analysis_LLM
|
40 |
+
- **Paper [optional]:** on the way
|
41 |
+
- **Demo [optional]:** on the way
|
|
|
|
|
42 |
|
43 |
## Uses
|
44 |
|
45 |
+
The model is already fine-tuned for downstream financial sentiment analysis tasks.
|
46 |
|
47 |
+
## How to Get Started with the Model
|
48 |
|
49 |
+
Use the code below to get started with the model.
|
50 |
|
51 |
[More Information Needed]
|
52 |
|
53 |
+
## Training Details
|
54 |
|
55 |
+
### Training Data
|
56 |
|
57 |
+
from transformers import GPT2Tokenizer
|
58 |
|
59 |
+
dataset = load_dataset("FinGPT/fingpt-sentiment-train")
|
60 |
|
61 |
+
tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
|
62 |
+
tokenizer.pad_token = tokenizer.eos_token
|
63 |
|
64 |
+
def tokenize_function(examples):
|
65 |
+
return tokenizer(examples["input"], padding="max_length", truncation=True)
|
66 |
|
67 |
+
tokenized_datasets = dataset.map(tokenize_function, batched=True)
|
68 |
|
69 |
+
from datasets import DatasetDict
|
70 |
+
import random
|
71 |
+
import string
|
72 |
|
73 |
+
def generate_random_id():
|
74 |
+
return ''.join(random.choices(string.ascii_lowercase + string.digits, k=10))
|
75 |
|
76 |
+
unique_outputs = set(dataset['train']['output'])
|
77 |
|
78 |
+
#label_mapping = {'mildly positive': 0, 'positive': 1, 'strong positive':2, 'moderately positive': 3, 'negative': 4, 'neutral': 5} # Add more mappings as needed
|
79 |
+
label_mapping = {label: index for index, label in enumerate(unique_outputs)}
|
80 |
|
81 |
+
def transform_dataset(dataset):
|
82 |
+
dataset = dataset.rename_column('input', 'text')
|
83 |
+
dataset = dataset.rename_column('output', 'label_text')
|
84 |
|
85 |
+
dataset = dataset.remove_columns(['instruction'])
|
86 |
|
87 |
+
dataset = dataset.add_column('id', [generate_random_id() for _ in range(dataset.num_rows)])
|
88 |
+
dataset = dataset.add_column('label', [label_mapping[label_text] for label_text in dataset['label_text']])
|
89 |
|
90 |
+
return dataset
|
91 |
|
92 |
+
transformed_dataset = DatasetDict({'train': transform_dataset(tokenized_datasets['train'])})
|
93 |
+
transformed_dataset['train'].set_format(type=None, columns=['id', 'text', 'label', 'label_text', 'input_ids', 'attention_mask'])
|
94 |
|
95 |
+
train_test_split = transformed_dataset['train'].train_test_split(test_size=0.3, seed=42)
|
96 |
|
97 |
+
tokenized_datasets['test'] = train_test_split['test']
|
98 |
+
tokenized_datasets['train'] = train_test_split['train']
|
99 |
|
100 |
+
small_train_dataset = tokenized_datasets["train"].shuffle(seed=42).select(range(100))
|
101 |
+
small_eval_dataset = tokenized_datasets["test"].shuffle(seed=42).select(range(100))
|
102 |
|
103 |
+
### Fine-tune Procedure
|
104 |
|
105 |
+
from transformers import GPT2ForSequenceClassification
|
106 |
+
from transformers import TrainingArguments, Trainer
|
107 |
|
108 |
+
model = GPT2ForSequenceClassification.from_pretrained("gpt2", num_labels=9)
|
109 |
|
110 |
+
training_args = TrainingArguments(
|
111 |
+
output_dir="test_trainer",
|
112 |
+
#evaluation_strategy="epoch",
|
113 |
+
per_device_train_batch_size=1, # Reduce batch size here
|
114 |
+
per_device_eval_batch_size=1, # Optionally, reduce for evaluation as well
|
115 |
+
gradient_accumulation_steps=4
|
116 |
+
)
|
117 |
+
|
118 |
+
trainer = Trainer(
|
119 |
+
model=model,
|
120 |
+
args=training_args,
|
121 |
+
train_dataset=small_train_dataset,
|
122 |
+
eval_dataset=small_eval_dataset,
|
123 |
+
compute_metrics=compute_metrics,
|
124 |
+
)
|
125 |
|
126 |
+
trainer.train()
|
127 |
+
trainer.evaluate()
|
128 |
+
trainer.save_model("fine_tuned_finsetiment_model")
|
129 |
|
130 |
#### Training Hyperparameters
|
131 |
|
|
|
139 |
|
140 |
## Evaluation
|
141 |
|
142 |
+
import evaluate
|
143 |
|
144 |
+
metric = evaluate.load("accuracy")
|
145 |
|
146 |
+
def compute_metrics(eval_pred):
|
147 |
+
logits, labels = eval_pred
|
148 |
+
predictions = np.argmax(logits, axis=-1)
|
149 |
|
150 |
+
return metric.compute(predictions=predictions, references=labels)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
|
152 |
### Results
|
153 |
|
|
|
155 |
|
156 |
#### Summary
|
157 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
## Citation [optional]
|
159 |
|
160 |
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
|
|
163 |
|
164 |
[More Information Needed]
|
165 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
|
167 |
## Model Card Contact
|
168 |
|
169 | |
|
|
|