Update README.md
Browse files
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 |
-
|
|
|
|
|
|
|
90 |
|
91 |
-
|
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 |
-
|
98 |
-
|
99 |
|
100 |
-
|
101 |
-
print(f"Sentiment: {
|
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
|