Views
No views yet
1from transformers import BertTokenizer, BertForSequenceClassification
2import numpy as np
3
4finbert = BertForSequenceClassification.from_pretrained('yiyanghkust/finbert-tone',num_labels=3)
5tokenizer = BertTokenizer.from_pretrained('yiyanghkust/finbert-tone')
6
7sentences = ["there is a shortage of capital, and we need extra financing",
8 "growth is strong and we have plenty of liquidity",
9 "there are doubts about our finances",
10 "profits are flat"]
11
12inputs = tokenizer(sentences, return_tensors="pt", padding=True)
13outputs = finbert(**inputs)[0]
14
15labels = {0:'neutral', 1:'positive',2:'negative'}
16for idx, sent in enumerate(sentences):
17 print(sent, '----', labels[np.argmax(outputs.detach().numpy()[idx])])
18
19'''
20there is a shortage of capital, and we need extra financing ---- negative
21growth is strong and we have plenty of liquidity ---- positive
22there are doubts about our finances ---- negative
23profits are flat ---- neutral
24'''
251@misc{yang2020finbert,
2 title={FinBERT: A Pretrained Language Model for Financial Communications},
3 author={Yi Yang and Mark Christopher Siy UY and Allen Huang},
4 year={2020},
5 eprint={2006.08097},
6 archivePrefix={arXiv},
7 }
8