Update README.md
Browse files
README.md
CHANGED
@@ -8,4 +8,30 @@ base_model:
|
|
8 |
- distilbert/distilbert-base-uncased
|
9 |
pipeline_tag: zero-shot-classification
|
10 |
library_name: transformers
|
11 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
- distilbert/distilbert-base-uncased
|
9 |
pipeline_tag: zero-shot-classification
|
10 |
library_name: transformers
|
11 |
+
---
|
12 |
+
|
13 |
+
Example code:
|
14 |
+
```python3
|
15 |
+
# Sample text to predict
|
16 |
+
text = "I love this movie, it was fantastic!"
|
17 |
+
|
18 |
+
# Tokenize the input text
|
19 |
+
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
|
20 |
+
|
21 |
+
# Get model predictions
|
22 |
+
with torch.no_grad():
|
23 |
+
outputs = model(**inputs)
|
24 |
+
|
25 |
+
# Get the logits (model's raw output)
|
26 |
+
logits = outputs.logits
|
27 |
+
|
28 |
+
# Convert logits to probabilities (if needed) and get the predicted class (0 or 1)
|
29 |
+
predictions = torch.argmax(logits, dim=-1).item()
|
30 |
+
|
31 |
+
# Map the prediction to sentiment labels
|
32 |
+
labels = {0: "NEGATIVE", 1: "POSITIVE"} # Assuming binary classification
|
33 |
+
predicted_label = labels[predictions]
|
34 |
+
|
35 |
+
print(f"Predicted Sentiment: {predicted_label}")
|
36 |
+
```
|
37 |
+
---
|