Team Ai
Modelpublic

Sharpaxis/Finance_DistilBERT_sentiment

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
0likes68downloads
Model Card

<!-- This model card has been generated automatically according to the information the Trainer had access to. You should probably proofread and complete it, then remove this comment. -->

FinanceDistilBERTsentiment

This model is a fine-tuned version of distilbert-base-uncased on the financial_phrasebank dataset. It achieves the following results on the evaluation set:

  • —Loss: 0.2763
  • —F1: 0.9101
  • —Acc: 0.9088

Model description

More information needed

Intended uses & limitations

More information needed

Training and evaluation data

More information needed

Training procedure

Training hyperparameters

The following hyperparameters were used during training:

  • —learning_rate: 4e-06
  • —trainbatchsize: 32
  • —evalbatchsize: 32
  • —seed: 42
  • —optimizer: Use adamwtorch with betas=(0.9,0.999) and epsilon=1e-08 and optimizerargs=No additional optimizer arguments
  • —lrschedulertype: linear
  • —lrschedulerwarmup_steps: 600
  • —num_epochs: 12

Training results (Final epoch)

Training LossEpochStepValidation LossF1Acc
0.09751.0870.27630.91010.9088

Framework versions

  • —Transformers 4.46.2
  • —Pytorch 2.5.1
  • —Datasets 3.1.0
  • —Tokenizers 0.20.3
python
import matplotlib.pyplot as plt
import plotly.graph_objects as go
from IPython.display import display, HTML
import numpy as np
from transformers import pipeline
%matplotlib inline

# Pipelines
classifier = pipeline("text-classification", model="Sharpaxis/Finance_DistilBERT_sentiment", top_k=None)
pipe = pipeline("text-classification", model="Sharpaxis/News_classification_distilbert")

def finance_text_predictor(text):
    text = str(text)
    out = classifier(text)[0]
    type_news = pipe(text)[0]
    
    # Display news type and text in HTML
    if type_news['label'] == 'LABEL_1':
        display(HTML(f"""
        <div style="border: 2px solid red; padding: 10px; margin: 10px; background-color: #ffe6e6; color: black; font-weight: bold;">
            IMPORTANT TECH/FIN News<br>
            <div style="margin-top: 10px; font-weight: normal; font-size: 14px; color: darkred;">{text}</div>
        </div>
        """))
    elif type_news['label'] == 'LABEL_0':
        display(HTML(f"""
        <div style="border: 2px solid green; padding: 10px; margin: 10px; background-color: #e6ffe6; color: black; font-weight: bold;">
            NON IMPORTANT NEWS<br>
            <div style="margin-top: 10px; font-weight: normal; font-size: 14px; color: darkgreen;">{text}</div>
        </div>
        """))
    
    # Sentiment analysis scores
    scores = [sample['score'] for sample in out]
    labels = [sample['label'] for sample in out]
    label_map = {'LABEL_0': "Negative", 'LABEL_1': "Neutral", 'LABEL_2': "Positive"}
    sentiments = [label_map[label] for label in labels]
    
    print("SCORES")
    for i in range(len(scores)):
        print(f"{sentiments[i]} : {scores[i]:.4f}")
    
    print(f"Sentiment of text is {sentiments[np.argmax(scores)]}")
    
    # Bar chart for sentiment scores
    fig = go.Figure(
        data=[go.Bar(x=sentiments, y=scores, marker=dict(color=["red", "blue", "green"]), width=0.3)]
    )
    fig.update_layout(
        title="Sentiment Analysis Scores",
        xaxis_title="Sentiments",
        yaxis_title="Scores",
        template="plotly_dark"
    )
    fig.show()