Update README.md
Browse files
    	
        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( 
     | 
| 34 | 
         
             
                bert_dict = {}
         
     | 
| 35 | 
         
            -
                vectors = tokenizer( 
     | 
| 36 | 
         
             
                outputs = bert_model(**vectors).logits
         
     | 
| 37 | 
         
            -
                probs = torch.nn.functional.softmax(outputs, dim = 1) 
     | 
| 38 | 
         
            -
                 
     | 
| 39 | 
         
            -
             
     | 
| 40 | 
         
            -
             
     | 
| 41 | 
         
            -
             
     | 
| 
         | 
|
| 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  
     | 
| 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 | 
         
             
            ```
         
     |