File size: 1,527 Bytes
5a07e07
 
 
 
 
 
 
 
 
 
 
 
 
2257feb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
---
datasets:
- financial_phrasebank
- chiapudding/kaggle-financial-sentiment
- zeroshot/twitter-financial-news-sentiment
- FinanceInc/auditor_sentiment
language:
- en
library_name: transformers
tags:
- Sentiment Classification
- Finance
- Deberta-v2
---

# Deberta for Financial Sentiment Analysis

I use a Deberta model trained on over 1 million reviews from Amazon's multi-reviews dataset and finetune it on 4 finance datasets that are categorized with  Sentiment labels.
The datasets I use are 

1) financial_phrasebank
2) chiapudding/kaggle-financial-sentiment
3) zeroshot/twitter-financial-news-sentiment
4) FinanceInc/auditor_sentiment


## How to use the model

```python
import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer

def get_sentiment(sentence):
    bert_dict = {}
    vectors = tokenizer(sentence, return_tensors='pt').to(device)
    outputs = bert_model(**vectors).logits
    probs = torch.nn.functional.softmax(outputs, dim = 1)[0]
    bert_dict['neg'] = round(probs[0].item(), 3)
    bert_dict['neu'] = round(probs[1].item(), 3)
    bert_dict['pos'] = round(probs[2].item(), 3)
    return bert_dict

MODEL_NAME = 'RashidNLP/Finance_Multi_Sentiment'
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

bert_model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME, num_labels = 3).to(device)
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)

get_sentiment("The stock market will struggle to rally until debt ceiling is increased")

```