AnkitAI commited on
Commit
b3d1bee
·
verified ·
1 Parent(s): 6ae24a7

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +14 -9
README.md CHANGED
@@ -86,19 +86,24 @@ Final Evaluation Accuracy**: **96.69%**
86
  ## Usage
87
  You can load and use the model with the Hugging Face `transformers` library as follows:
88
  ```python
89
- from transformers import AutoTokenizer, AutoModelForSequenceClassification
 
 
 
90
 
91
- tokenizer = AutoTokenizer.from_pretrained('AnkitAI/distilbert-base-uncased-financial-news-sentiment-analysis')
92
- model = AutoModelForSequenceClassification.from_pretrained('AnkitAI/distilbert-base-uncased-financial-news-sentiment-analysis')
93
-
94
- text = "The company's quarterly earnings surpassed all estimates, indicating strong growth."
95
  inputs = tokenizer(text, return_tensors="pt")
 
 
 
 
 
96
 
97
- outputs = model(**inputs)
98
- predictions = outputs.logits.argmax(dim=-1)
99
 
100
- label_mapping = {0: 'Negative', 1: 'Neutral', 2: 'Positive'}
101
- print(f"Sentiment: {label_mapping[predictions.item()]}")
102
  ```
103
 
104
  ## License
 
86
  ## Usage
87
  You can load and use the model with the Hugging Face `transformers` library as follows:
88
  ```python
89
+ import torch
90
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
91
+ tokenizer = AutoTokenizer.from_pretrained("AnkitAI/distilbert-base-uncased-financial-news-sentiment-analysis")
92
+ model = AutoModelForSequenceClassification.from_pretrained("AnkitAI/distilbert-base-uncased-financial-news-sentiment-analysis")
93
 
94
+ text = "The company's revenue declined significantly due to market competition."
 
 
 
95
  inputs = tokenizer(text, return_tensors="pt")
96
+ with torch.no_grad():
97
+ outputs = model(**inputs)
98
+
99
+ logits = outputs.logits
100
+ predicted_class_id = logits.argmax().item()
101
 
102
+ label_mapping = {0: "Negative", 1: "Neutral", 2: "Positive"}
103
+ predicted_label = label_mapping[predicted_class_id]
104
 
105
+ print(f"Text: {text}")
106
+ print(f"Predicted Sentiment: {predicted_label}")
107
  ```
108
 
109
  ## License