Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from torch.utils.data import Dataset, DataLoader
|
3 |
+
from torch.optim import AdamW
|
4 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
5 |
+
import torch.nn.functional as F
|
6 |
+
|
7 |
+
MODEL = "AventIQ-AI/sentiment-analysis-for-user-reviews-sentiment"
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL)
|
9 |
+
model = AutoModelForSequenceClassification.from_pretrained(MODEL,num_labels=2,ignore_mismatched_sizes=True)
|
10 |
+
|
11 |
+
|
12 |
+
def predict(text):
|
13 |
+
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=128)
|
14 |
+
with torch.no_grad():
|
15 |
+
outputs = quantize_model(**inputs)
|
16 |
+
probs = F.softmax(outputs.logits, dim=1)
|
17 |
+
pred = torch.argmax(probs, dim=1).item()
|
18 |
+
label_map = {0: "Negative", 1: "Neutral", 2: "Positive"}
|
19 |
+
return f"Sentiment: {label_map[pred]} (Confidence: {probs[0][pred]:.2f})"
|
20 |
+
|
21 |
+
# Test predictions
|
22 |
+
print("\nTest Predictions:")
|
23 |
+
print(predict("the product quality is just so so"))
|