Rezaul Karim
commited on
Update README.md
Browse files
README.md
CHANGED
|
@@ -14,18 +14,6 @@ https://huggingface.co/rezahf2024/fine_tuned_financial_setiment_analysis_gpt2_mo
|
|
| 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.
|
|
@@ -44,6 +32,54 @@ label_mapping = {
|
|
| 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.
|
|
@@ -163,7 +199,7 @@ def compute_metrics(eval_pred):
|
|
| 163 |
|
| 164 |
## Citation [optional]
|
| 165 |
|
| 166 |
-
<!-- If
|
| 167 |
|
| 168 |
**BibTeX:**
|
| 169 |
|
|
|
|
| 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 |
- **Developed by:** Rezaul Karim, Ph.D.
|
| 18 |
- **Funded by [optional]:** Self
|
| 19 |
- **Shared by [optional]:** Rezaul Karim, Ph.D.
|
|
|
|
| 32 |
|
| 33 |
The model is already fine-tuned for downstream financial sentiment analysis tasks.
|
| 34 |
|
| 35 |
+
```
|
| 36 |
+
import torch
|
| 37 |
+
|
| 38 |
+
# Load your fine-tuned model and tokenizer
|
| 39 |
+
model = AutoModelForSequenceClassification.from_pretrained("fine_tuned_finsetiment_model")
|
| 40 |
+
tokenizer = AutoTokenizer.from_pretrained("fine_tuned_finsetiment_model")
|
| 41 |
+
|
| 42 |
+
# Define the label mapping as provided
|
| 43 |
+
label_mapping_reverse = {
|
| 44 |
+
'LABEL_0': 'mildly positive',
|
| 45 |
+
'LABEL_1': 'mildly negative',
|
| 46 |
+
'LABEL_2': 'moderately negative',
|
| 47 |
+
'LABEL_3': 'moderately positive',
|
| 48 |
+
'LABEL_4': 'positive',
|
| 49 |
+
'LABEL_5': 'negative',
|
| 50 |
+
'LABEL_6': 'neutral',
|
| 51 |
+
'LABEL_7': 'strong negative',
|
| 52 |
+
'LABEL_8': 'strong positive'
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
def model_predict(text):
|
| 56 |
+
# Tokenize the input text
|
| 57 |
+
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
|
| 58 |
+
|
| 59 |
+
# Get predictions from the model
|
| 60 |
+
with torch.no_grad():
|
| 61 |
+
logits = model(**inputs).logits
|
| 62 |
+
|
| 63 |
+
# Convert to probabilities
|
| 64 |
+
probabilities = torch.nn.functional.softmax(logits, dim=-1)
|
| 65 |
+
|
| 66 |
+
# Create a list of tuples with label and probability
|
| 67 |
+
label_prob_pairs = [(label_mapping_reverse[label_idx], prob.item())
|
| 68 |
+
for label_idx, prob in enumerate(probabilities.squeeze())]
|
| 69 |
+
|
| 70 |
+
# Sort the list by probability in descending order
|
| 71 |
+
sorted_label_prob_pairs = sorted(label_prob_pairs, key=lambda pair: pair[1], reverse=True)
|
| 72 |
+
|
| 73 |
+
# Return the sorted list of label-probability pairs
|
| 74 |
+
return sorted_label_prob_pairs
|
| 75 |
+
|
| 76 |
+
# Example usage
|
| 77 |
+
text = "Intel Corporation (NASDAQ: INTC) has unveiled a remote verification platform called Project Amber"
|
| 78 |
+
predictions = model_predict(text)
|
| 79 |
+
for label, prob in predictions:
|
| 80 |
+
print(f"{label}: {prob:.3f}")
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
## How to Get Started with the Model
|
| 84 |
|
| 85 |
Use the code below to get started with the model.
|
|
|
|
| 199 |
|
| 200 |
## Citation [optional]
|
| 201 |
|
| 202 |
+
<!-- If a paper or blog post is introducing the model, the APA and Bibtex information for that should go in this section. -->
|
| 203 |
|
| 204 |
**BibTeX:**
|
| 205 |
|