Add usage example
Browse files
README.md
CHANGED
|
@@ -39,6 +39,38 @@ It achieves the following results on the evaluation set:
|
|
| 39 |
|
| 40 |
More information needed
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
## Intended uses & limitations
|
| 43 |
|
| 44 |
More information needed
|
|
|
|
| 39 |
|
| 40 |
More information needed
|
| 41 |
|
| 42 |
+
## Example
|
| 43 |
+
|
| 44 |
+
```
|
| 45 |
+
import torch
|
| 46 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
| 47 |
+
|
| 48 |
+
model = AutoModelForSequenceClassification.from_pretrained("nfliu/deberta-v3-large_boolq")
|
| 49 |
+
tokenizer = AutoTokenizer.from_pretrained("nfliu/deberta-v3-large_boolq")
|
| 50 |
+
|
| 51 |
+
# Each example is a (question, context) pair.
|
| 52 |
+
examples = [
|
| 53 |
+
("Lake Tahoe is in California", "Lake Tahoe is a popular tourist spot in California."),
|
| 54 |
+
("Water is wet", "Contrary to popular belief, water is not wet.")
|
| 55 |
+
]
|
| 56 |
+
|
| 57 |
+
encoded_input = tokenizer(examples, padding=True, truncation=True, return_tensors="pt")
|
| 58 |
+
|
| 59 |
+
with torch.no_grad():
|
| 60 |
+
model_output = model(**encoded_input)
|
| 61 |
+
probabilities = torch.softmax(model_output.logits, dim=-1).cpu().tolist()
|
| 62 |
+
|
| 63 |
+
probability_no = [round(prob[0], 2) for prob in probabilities]
|
| 64 |
+
probability_yes = [round(prob[1], 2) for prob in probabilities]
|
| 65 |
+
|
| 66 |
+
for example, p_no, p_yes in zip(examples, probability_no, probability_yes):
|
| 67 |
+
print(f"Question: {example[0]}")
|
| 68 |
+
print(f"Context: {example[1]}")
|
| 69 |
+
print(f"p(No | question, context): {p_no}")
|
| 70 |
+
print(f"p(Yes | question, context): {p_yes}")
|
| 71 |
+
print()
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
## Intended uses & limitations
|
| 75 |
|
| 76 |
More information needed
|