Update README.md
Browse files
README.md
CHANGED
|
@@ -80,25 +80,41 @@ The following hyperparameters were used during training:
|
|
| 80 |
- Datasets 3.1.0
|
| 81 |
- Tokenizers 0.20.3
|
| 82 |
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
|
|
|
| 86 |
import plotly.graph_objects as go
|
| 87 |
%matplotlib inline
|
| 88 |
from transformers import pipeline
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
| 90 |
def finance_sentiment_predictor(text):
|
| 91 |
text = str(text)
|
| 92 |
out = classifier(text)[0]
|
| 93 |
scores = [sample['score'] for sample in out]
|
| 94 |
-
labels = [sample['label'] for sample in out
|
| 95 |
-
label_map = {'LABEL_0':"Negative",'LABEL_1':"Neutral",'LABEL_2':"Positive"}
|
| 96 |
-
sentiments = [label_map[label] for label
|
|
|
|
| 97 |
for i in range(len(scores)):
|
| 98 |
print(f"{sentiments[i]} : {scores[i]}")
|
|
|
|
| 99 |
print(f"Sentiment of text is {sentiments[np.argmax(scores)]}")
|
|
|
|
|
|
|
| 100 |
fig = go.Figure(
|
| 101 |
-
data=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
fig.update_layout(
|
| 103 |
title="Sentiment Analysis Scores",
|
| 104 |
xaxis_title="Sentiments",
|
|
|
|
| 80 |
- Datasets 3.1.0
|
| 81 |
- Tokenizers 0.20.3
|
| 82 |
|
| 83 |
+
## Finance Sentiment Predictor
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
```python
|
| 87 |
import plotly.graph_objects as go
|
| 88 |
%matplotlib inline
|
| 89 |
from transformers import pipeline
|
| 90 |
+
|
| 91 |
+
# Load the sentiment analysis pipeline
|
| 92 |
+
classifier = pipeline("text-classification", model="Sharpaxis/FIN_BERT_sentiment", top_k=None)
|
| 93 |
+
|
| 94 |
def finance_sentiment_predictor(text):
|
| 95 |
text = str(text)
|
| 96 |
out = classifier(text)[0]
|
| 97 |
scores = [sample['score'] for sample in out]
|
| 98 |
+
labels = [sample['label'] for sample in out]
|
| 99 |
+
label_map = {'LABEL_0': "Negative", 'LABEL_1': "Neutral", 'LABEL_2': "Positive"}
|
| 100 |
+
sentiments = [label_map[label] for label in labels]
|
| 101 |
+
|
| 102 |
for i in range(len(scores)):
|
| 103 |
print(f"{sentiments[i]} : {scores[i]}")
|
| 104 |
+
|
| 105 |
print(f"Sentiment of text is {sentiments[np.argmax(scores)]}")
|
| 106 |
+
|
| 107 |
+
# Create the bar chart
|
| 108 |
fig = go.Figure(
|
| 109 |
+
data=[
|
| 110 |
+
go.Bar(
|
| 111 |
+
x=sentiments,
|
| 112 |
+
y=scores,
|
| 113 |
+
marker=dict(color=["red", "blue", "green"]),
|
| 114 |
+
width=0.3 # Adjust bar width
|
| 115 |
+
)
|
| 116 |
+
]
|
| 117 |
+
)
|
| 118 |
fig.update_layout(
|
| 119 |
title="Sentiment Analysis Scores",
|
| 120 |
xaxis_title="Sentiments",
|