Update README.md
Browse files
README.md
CHANGED
|
@@ -79,3 +79,29 @@ The following hyperparameters were used during training:
|
|
| 79 |
- Pytorch 2.5.1
|
| 80 |
- Datasets 3.1.0
|
| 81 |
- Tokenizers 0.20.3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
- Pytorch 2.5.1
|
| 80 |
- Datasets 3.1.0
|
| 81 |
- Tokenizers 0.20.3
|
| 82 |
+
|
| 83 |
+
### code to use in pipeline
|
| 84 |
+
import matplotlib.pyplot as plt
|
| 85 |
+
import plotly.graph_objects as go
|
| 86 |
+
%matplotlib inline
|
| 87 |
+
from transformers import pipeline
|
| 88 |
+
classifier = pipeline("text-classification", model="Sharpaxis/FIN_BERT_sentiment",top_k=None)
|
| 89 |
+
def finance_sentiment_predictor(text):
|
| 90 |
+
text = str(text)
|
| 91 |
+
out = classifier(text)[0]
|
| 92 |
+
scores = [sample['score'] for sample in out]
|
| 93 |
+
labels = [sample['label'] for sample in out ]
|
| 94 |
+
label_map = {'LABEL_0':"Negative",'LABEL_1':"Neutral",'LABEL_2':"Positive"}
|
| 95 |
+
sentiments = [label_map[label] for label in labels]
|
| 96 |
+
for i in range(len(scores)):
|
| 97 |
+
print(f"{sentiments[i]} : {scores[i]}")
|
| 98 |
+
print(f"Sentiment of text is {sentiments[np.argmax(scores)]}")
|
| 99 |
+
fig = go.Figure(
|
| 100 |
+
data=[go.Bar(x=sentiments,y=scores,marker=dict(color=["red", "blue", "green"]),width=0.3)])
|
| 101 |
+
fig.update_layout(
|
| 102 |
+
title="Sentiment Analysis Scores",
|
| 103 |
+
xaxis_title="Sentiments",
|
| 104 |
+
yaxis_title="Scores",
|
| 105 |
+
template="plotly_dark"
|
| 106 |
+
)
|
| 107 |
+
fig.show()
|