Git Product home page Git Product logo

finbert's Introduction

FinBERT

***** June 2, 2022: More fine-tuned FinBERT models available*****

Visit FinBERT.AI for more details on the recent development of FinBERT.

We have fine-tuned FinBERT pretrained model on several financial NLP tasks, all outperforming traditional machine learning models, deep learning models, and fine-tuned BERT models. All the fine-tuned FinBERT models are publicly hosted at Huggingface πŸ€—. Specifically, we have the following:

  • FinBERT-Pretrained: The pretrained FinBERT model on large-scale financial text. link
  • FinBERT-Sentiment: for sentiment classification task. link
  • FinBERT-ESG: for ESG classification task. link
  • FinBERT-FLS: for forward-looking statement (FLS) classification task. link

In this Github repo,

Background:

FinBERT is a BERT model pre-trained on financial communication text. The purpose is to enhance finaincal NLP research and practice. It is trained on the following three finanical communication corpus. The total corpora size is 4.9B tokens.

  • Corporate Reports 10-K & 10-Q: 2.5B tokens
  • Earnings Call Transcripts: 1.3B tokens
  • Analyst Reports: 1.1B tokens

FinBERT results in state-of-the-art performance on various financial NLP task, including sentiment analysis, ESG classification, forward-looking statement (FLS) classification. With the release of FinBERT, we hope practitioners and researchers can utilize FinBERT for a wider range of applications where the prediction target goes beyond sentiment, such as financial-related outcomes including stock returns, stock volatilities, corporate fraud, etc.


***** July 30, 2021: migrated to Huggingface πŸ€—*****

The fine-tuned FinBERT model for financial sentiment classification has been uploaded and integrated with Huggingface's transformers library. This model is fine-tuned on 10,000 manually annotated (positive, negative, neutral) sentences from analyst reports. This model achieves superior performance on financial tone anlaysis task. If you are simply interested in using FinBERT for financial tone analysis, give it a try.

from transformers import BertTokenizer, BertForSequenceClassification
import numpy as np

finbert = BertForSequenceClassification.from_pretrained('yiyanghkust/finbert-tone',num_labels=3)
tokenizer = BertTokenizer.from_pretrained('yiyanghkust/finbert-tone')

sentences = ["there is a shortage of capital, and we need extra financing", 
             "growth is strong and we have plenty of liquidity", 
             "there are doubts about our finances", 
             "profits are flat"]

inputs = tokenizer(sentences, return_tensors="pt", padding=True)
outputs = finbert(**inputs)[0]

labels = {0:'neutral', 1:'positive',2:'negative'}
for idx, sent in enumerate(sentences):
    print(sent, '----', labels[np.argmax(outputs.detach().numpy()[idx])])
    
'''
there is a shortage of capital, and we need extra financing ---- negative
growth is strong and we have plenty of liquidity ---- positive
there are doubts about our finances ---- negative
profits are flat ---- neutral
'''
    

***** Jun 16, 2020: Pretrained FinBERT Model Released*****

We provide four versions of pre-trained FinBERT weights.

FinVocab is a new WordPiece vocabulary on our finanical corpora using the SentencePiece library. We produce both cased and uncased versions of FinVocab, with sizes of 28,573 and 30,873 tokens respectively. This is very similar to the 28,996 and 30,522 token sizes of the original BERT cased and uncased BaseVocab.

Citation

@misc{yang2020finbert,
    title={FinBERT: A Pretrained Language Model for Financial Communications},
    author={Yi Yang and Mark Christopher Siy UY and Allen Huang},
    year={2020},
    eprint={2006.08097},
    archivePrefix={arXiv},
    }

Contact

Please post a Github issue or contact [email protected] if you have any questions.

finbert's People

Contributors

mcsuy avatar mcsuy1998 avatar mikaeldusenne avatar yya518 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

finbert's Issues

Data is missing to run finetune Notebook

This is a really interesting project.
Can you please provide a version of the analysttone.csv file? The NB will not run without it.

At a minimum provide a specification and a few hundred examples.

Thank you.

Richard

FinBERT pretrained model in ONNX format

Do you have a ONNX format available? My environment is ML.Net and DON’T want to go through the full conversion process and setting up the environment..

The sentiments are varying every time when i run it for the same sentence.

I have created my own sentence "there is a abundance of capital because of good profits" to test the sentiment prediction for the fine-tuned model using the notebook given: "FinBert Model Example.ipynb".

When I ran for the first time I got the result as 'positive': https://prnt.sc/vf3fnb
When I ran for the second time I got the result as 'neutral': https://prnt.sc/vf3fcr

Why is this variation happening? How can we trust the results from this model if it is not stable?

using CPU error

first, I really appreciate this model.

In my environment CUDA is available, but if i run the model, the process will die since using only CPU.
Is there a separate setting method for using CUDA?

Thank you again for this model.

For those of us without a CUDA compatible device: Note to use 'cpu' rather than 'cuda:1' as device.

Thank you for providing us with your trained model! I finally have the fine-tuned model working on my machine. But after struggling for a long time, here are some notes that may help future users who like me have little experience with these types of models.

In working through your example for using the fine-tuned FinBERT, I had issues installing torch==1.2.0 until I first ran pip install pytorch-pretrained-bert, which did the installation of torch for me and eliminated that issue.

I do not have a CUDA compatible GPU and so had to change device='cuda:1' to device='cpu'. I then needed to add map_location=device or map_location='cpu' when running model.load_state_dict(torch.load(fine_tuned_weight_path,map_location=device)).

These are rather simple changes, but they held me up for some time.

error when running FinBert Model Example.ipynb

when running model.load_state_dict(torch.load(fine_tuned_weight_path, map_location=device)) from FinBert Model Example.ipynb from my local machine, I ran into this error:

RuntimeError: Error(s) in loading state_dict for BertClassification:
	Missing key(s) in state_dict: "bert.embeddings.position_ids".

Is there sentiment score or probability of positive/neutral/negative?

Thank you for the great library.

I went through example and there are only labels, i.e. positive, neutral and negative for the text's sentiment. I'm wondering if there's any score or probability deciding what text is positive, neutral or negative?

I was looking in attributes, i.e. dir(outputs) or dir(tourch) but did not find any such value, which would be indeed useful to know.

sentiment predictions are not consistent

I am using your sentiment model to predict sentences from calls. There are two sentences:

  • The probability of neutral is .99 for the sentence 'Thanks, Martin.'
  • The probability of positive is .94 for the sentence 'Thank you.'

I am trying to understand why it gives quite different labels. Initially I thought it was the label confusion, but you have answered the question in Issue #17.
Could you explain more about how you fine-tuning the model for analyst tones and what date you use for the classification model? Thank you!

RuntimeError: The size of tensor a (538) must match the size of tensor b (512) at non-singleton dimension 1

I'm parsing conference calls and run into this error a couple of times. I used NLTK to parse the text components into sentences and then pass those sentences into the classifier following your example. It largely works, but I ran into this issue. From what I read, it arises because there are too many tokens (words) in the sentence. I manually inspect where I think the issue is occurring to identify a piece that is extra long. It occurs when there is a lot of semi-colons. So I could break up sentences with semi-colons, but that doesn't seem quite right. Using word_tokenize from nltk, there are only 488 tokens. How do you tokenize the words? I'm thinking I will truncate the sentence before passing to the model, but to do so accurately, I need to know how many tokens are created by the model.

Is my assessment of why this is happening correct and do you have a better solution than truncating? Thanks.

FinBERT pipeline vs Finbert Model Example code result difference

My collaborators and I were experimenting with FinBERT by comparing the results of your code from the Finbert Model Example notebook to the results of using the transformer code in a HuggingFace pipeline. of the 7 we tested it on, all came out with different scores, but 3 came out with different labels altogether. We were wondering if you knew what the reason for that might be? I can upload the code that we used if that would be helpful.

Is there a prediction script available?

HI,

Congrats for the wonderful work.

I would much appreciate if you would construct a prediction script which could work like this:

python bert_prediction.py --input "Sentence for classification" -- weights (path to weights)

Migration to transformers

Are there any plans on migrating the current model to the newer transformers library by hugging face? I want to use it with the sentence-transformer library but it seems like it can only run with the newer transformer model.

MisMatch between labels during dataPrep v.s. during inference

I might be missing something, but it seems there is a mis-match between the label ordering when preparing the training data v.s. when doing the inference in the provided jupyter notebook.

In the 'datasets.py' file, in the 'transform_labels' method, the order is: "dict_labels = {'positive': 0, 'neutral':1, 'negative':2}"
But in the notebook: "labels = {0:'neutral', 1:'positive', 2:'negative'}"

In both cases, 'negative'=2, but 'positive' and 'neutral' are switched.
Is there a reason I am missing?
Thank you!

Analyst Tone

Hi!
Thank you for this repository.
Do you know where I can find the Analyst Tone dataset that you mention in the paper?
Thank you,
Maxime.

TF Model

Hello,

Will you be generating a TF version of this model? I will need it to import on SparkNLP.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.