Update README.md
Browse files
README.md
CHANGED
|
@@ -84,29 +84,58 @@ The following hyperparameters were used during training:
|
|
| 84 |
|
| 85 |
|
| 86 |
```python
|
|
|
|
| 87 |
import plotly.graph_objects as go
|
| 88 |
-
|
|
|
|
| 89 |
from transformers import pipeline
|
|
|
|
| 90 |
|
| 91 |
-
#
|
| 92 |
-
classifier = pipeline("text-classification", model="Sharpaxis/
|
|
|
|
| 93 |
|
| 94 |
-
def
|
| 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
|
|
|
|
|
|
|
| 101 |
for i in range(len(scores)):
|
| 102 |
-
print(f"{sentiments[i]} : {scores[i]}")
|
|
|
|
| 103 |
print(f"Sentiment of text is {sentiments[np.argmax(scores)]}")
|
|
|
|
|
|
|
| 104 |
fig = go.Figure(
|
| 105 |
-
data=[go.Bar(x=sentiments,y=scores,marker=dict(color=["red", "blue", "green"]),width=0.3)]
|
|
|
|
| 106 |
fig.update_layout(
|
| 107 |
title="Sentiment Analysis Scores",
|
| 108 |
xaxis_title="Sentiments",
|
| 109 |
yaxis_title="Scores",
|
| 110 |
template="plotly_dark"
|
| 111 |
)
|
| 112 |
-
fig.show()
|
|
|
|
| 84 |
|
| 85 |
|
| 86 |
```python
|
| 87 |
+
import matplotlib.pyplot as plt
|
| 88 |
import plotly.graph_objects as go
|
| 89 |
+
from IPython.display import display, HTML
|
| 90 |
+
import numpy as np
|
| 91 |
from transformers import pipeline
|
| 92 |
+
%matplotlib inline
|
| 93 |
|
| 94 |
+
# Pipelines
|
| 95 |
+
classifier = pipeline("text-classification", model="Sharpaxis/Finance_DistilBERT_sentiment", top_k=None)
|
| 96 |
+
pipe = pipeline("text-classification", model="Sharpaxis/News_classification_distilbert")
|
| 97 |
|
| 98 |
+
def finance_text_predictor(text):
|
| 99 |
text = str(text)
|
| 100 |
out = classifier(text)[0]
|
| 101 |
+
type_news = pipe(text)[0]
|
| 102 |
+
|
| 103 |
+
# Display news type and text in HTML
|
| 104 |
+
if type_news['label'] == 'LABEL_1':
|
| 105 |
+
display(HTML(f"""
|
| 106 |
+
<div style="border: 2px solid red; padding: 10px; margin: 10px; background-color: #ffe6e6; color: black; font-weight: bold;">
|
| 107 |
+
IMPORTANT TECH/FIN News<br>
|
| 108 |
+
<div style="margin-top: 10px; font-weight: normal; font-size: 14px; color: darkred;">{text}</div>
|
| 109 |
+
</div>
|
| 110 |
+
"""))
|
| 111 |
+
elif type_news['label'] == 'LABEL_0':
|
| 112 |
+
display(HTML(f"""
|
| 113 |
+
<div style="border: 2px solid green; padding: 10px; margin: 10px; background-color: #e6ffe6; color: black; font-weight: bold;">
|
| 114 |
+
NON IMPORTANT NEWS<br>
|
| 115 |
+
<div style="margin-top: 10px; font-weight: normal; font-size: 14px; color: darkgreen;">{text}</div>
|
| 116 |
+
</div>
|
| 117 |
+
"""))
|
| 118 |
+
|
| 119 |
+
# Sentiment analysis scores
|
| 120 |
scores = [sample['score'] for sample in out]
|
| 121 |
+
labels = [sample['label'] for sample in out]
|
| 122 |
+
label_map = {'LABEL_0': "Negative", 'LABEL_1': "Neutral", 'LABEL_2': "Positive"}
|
| 123 |
+
sentiments = [label_map[label] for label in labels]
|
| 124 |
+
|
| 125 |
+
print("SCORES")
|
| 126 |
for i in range(len(scores)):
|
| 127 |
+
print(f"{sentiments[i]} : {scores[i]:.4f}")
|
| 128 |
+
|
| 129 |
print(f"Sentiment of text is {sentiments[np.argmax(scores)]}")
|
| 130 |
+
|
| 131 |
+
# Bar chart for sentiment scores
|
| 132 |
fig = go.Figure(
|
| 133 |
+
data=[go.Bar(x=sentiments, y=scores, marker=dict(color=["red", "blue", "green"]), width=0.3)]
|
| 134 |
+
)
|
| 135 |
fig.update_layout(
|
| 136 |
title="Sentiment Analysis Scores",
|
| 137 |
xaxis_title="Sentiments",
|
| 138 |
yaxis_title="Scores",
|
| 139 |
template="plotly_dark"
|
| 140 |
)
|
| 141 |
+
fig.show()
|