Update README.md
Browse files
README.md
CHANGED
@@ -8,9 +8,8 @@ tags:
|
|
8 |
- BERT
|
9 |
|
10 |
widget:
|
11 |
-
- text: "7 yo canine with history of vomiting intermittently
|
12 |
-
|
13 |
-
example_title: "Pancreatic Disorder"
|
14 |
---
|
15 |
|
16 |
|
@@ -38,9 +37,34 @@ VetBERT was further finetuned on a set of 5002 annotated clinical notes to class
|
|
38 |
Load the model via the transformers library:
|
39 |
|
40 |
```
|
41 |
-
from transformers import AutoTokenizer,
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
```
|
45 |
|
46 |
## Citation
|
|
|
8 |
- BERT
|
9 |
|
10 |
widget:
|
11 |
+
- text: "Hx: 7 yo canine with history of vomiting intermittently since yesterday. No other concerns. Still eating and drinking normally. cPL negative."
|
12 |
+
example_title: "Enteropathy"
|
|
|
13 |
---
|
14 |
|
15 |
|
|
|
37 |
Load the model via the transformers library:
|
38 |
|
39 |
```
|
40 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
41 |
+
import torch
|
42 |
+
|
43 |
+
# Load the tokenizer and model from the Hugging Face Hub
|
44 |
+
model_name = 'havocy28/VetBERTDx'
|
45 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
46 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
47 |
+
|
48 |
+
# Example text to classify
|
49 |
+
text = "Hx: 7 yo canine with history of vomiting intermittently since yesterday. No other concerns. Still eating and drinking normally. cPL negative."
|
50 |
+
|
51 |
+
# Encode the text and prepare inputs for the model
|
52 |
+
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=512)
|
53 |
+
|
54 |
+
# Predict and compute softmax to get probabilities
|
55 |
+
with torch.no_grad():
|
56 |
+
logits = model(**inputs).logits
|
57 |
+
probabilities = torch.softmax(logits, dim=-1)
|
58 |
+
|
59 |
+
# Retrieve label mapping from model's configuration
|
60 |
+
label_map = model.config.id2label
|
61 |
+
|
62 |
+
# Combine labels and probabilities, and sort by probability in descending order
|
63 |
+
sorted_probs = sorted(((prob.item(), label_map[idx]) for idx, prob in enumerate(probabilities[0])), reverse=True, key=lambda x: x[0])
|
64 |
+
|
65 |
+
# Display sorted probabilities and labels
|
66 |
+
for prob, label in sorted_probs:
|
67 |
+
print(f"{label}: {prob:.4f}")
|
68 |
```
|
69 |
|
70 |
## Citation
|