Update model use
Browse files
README.md
CHANGED
|
@@ -44,6 +44,24 @@ pipeline_tag: text-classification
|
|
| 44 |
### Direct Use
|
| 45 |
|
| 46 |
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
[More Information Needed]
|
| 49 |
|
|
|
|
| 44 |
### Direct Use
|
| 45 |
|
| 46 |
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
| 47 |
+
```
|
| 48 |
+
from transformers import AutoModelForSequenceClassification
|
| 49 |
+
from transformers import AutoTokenizer
|
| 50 |
+
|
| 51 |
+
model = AutoModelForSequenceClassification.from_pretrained("AlCyede/sarcastic-text_prediction")
|
| 52 |
+
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
|
| 53 |
+
|
| 54 |
+
def predict(text):
|
| 55 |
+
inputs = tokenizer(text, padding=True, truncation=True, return_tensors="pt")
|
| 56 |
+
outputs = model(**inputs)
|
| 57 |
+
logits = outputs.logits
|
| 58 |
+
predicted_class_id = logits.argmax().item()
|
| 59 |
+
confidence = logits.softmax(dim=1)[0][predicted_class_id].item()
|
| 60 |
+
return {
|
| 61 |
+
"prediction": model.config.id2label[predicted_class_id],
|
| 62 |
+
"confidence": f"{confidence * 100:.02f}%"
|
| 63 |
+
}
|
| 64 |
+
```
|
| 65 |
|
| 66 |
[More Information Needed]
|
| 67 |
|