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