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