Text Classification
Transformers
PyTorch
Safetensors
English
deberta-v2
Sentiment Classification
Finance
Deberta-v2
Inference Endpoints
RashidNLP commited on
Commit
718cca4
1 Parent(s): 2257feb

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +9 -8
README.md CHANGED
@@ -30,15 +30,16 @@ The datasets I use are
30
  import torch
31
  from transformers import AutoModelForSequenceClassification, AutoTokenizer
32
 
33
- def get_sentiment(sentence):
34
  bert_dict = {}
35
- vectors = tokenizer(sentence, return_tensors='pt').to(device)
36
  outputs = bert_model(**vectors).logits
37
- probs = torch.nn.functional.softmax(outputs, dim = 1)[0]
38
- bert_dict['neg'] = round(probs[0].item(), 3)
39
- bert_dict['neu'] = round(probs[1].item(), 3)
40
- bert_dict['pos'] = round(probs[2].item(), 3)
41
- return bert_dict
 
42
 
43
  MODEL_NAME = 'RashidNLP/Finance_Multi_Sentiment'
44
  device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
@@ -46,6 +47,6 @@ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
46
  bert_model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME, num_labels = 3).to(device)
47
  tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
48
 
49
- get_sentiment("The stock market will struggle to rally until debt ceiling is increased")
50
 
51
  ```
 
30
  import torch
31
  from transformers import AutoModelForSequenceClassification, AutoTokenizer
32
 
33
+ def get_sentiment(sentences):
34
  bert_dict = {}
35
+ vectors = tokenizer(sentences, padding = True, max_length = 65, return_tensors='pt').to(device)
36
  outputs = bert_model(**vectors).logits
37
+ probs = torch.nn.functional.softmax(outputs, dim = 1)
38
+ for prob in probs:
39
+ bert_dict['neg'] = round(prob[0].item(), 3)
40
+ bert_dict['neu'] = round(prob[1].item(), 3)
41
+ bert_dict['pos'] = round(prob[2].item(), 3)
42
+ print (bert_dict)
43
 
44
  MODEL_NAME = 'RashidNLP/Finance_Multi_Sentiment'
45
  device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
 
47
  bert_model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME, num_labels = 3).to(device)
48
  tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
49
 
50
+ get_sentiment(["The stock market will struggle until debt ceiling is increased", "ChatGPT is boosting Microsoft's search engine market share"])
51
 
52
  ```