Update README.md
Browse files
README.md
CHANGED
|
@@ -26,7 +26,33 @@ Conclusion: Personalized impressions generated by PEGASUS were clinically useful
|
|
| 26 |
## 🚀 Usage
|
| 27 |
|
| 28 |
```bash
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
```
|
| 31 |
|
| 32 |
|
|
|
|
| 26 |
## 🚀 Usage
|
| 27 |
|
| 28 |
```bash
|
| 29 |
+
finetuned_model = "xtie/BART-PET-impression"
|
| 30 |
+
tokenizer = AutoTokenizer.from_pretrained(finetuned_model)
|
| 31 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(finetuned_model, ignore_mismatched_sizes=True).eval()
|
| 32 |
+
|
| 33 |
+
findings_info =
|
| 34 |
+
"""
|
| 35 |
+
Description: PET CT WHOLE BODY
|
| 36 |
+
Radiologist: James
|
| 37 |
+
Findings: Head/Neck: xxx Chest: xxx Abdomen/Pelvis: xxx Extremities/Musculoskeletal: xxx
|
| 38 |
+
Indication: The patient is a [AGE]-year old [SEX] with a history of xxx
|
| 39 |
+
"""
|
| 40 |
+
|
| 41 |
+
inputs = tokenizer(findings_info, padding="max_length", truncation=True, max_length=1024, return_tensors="pt")
|
| 42 |
+
input_ids = inputs.input_ids.to("cuda")
|
| 43 |
+
attention_mask = inputs.attention_mask.to("cuda")
|
| 44 |
+
outputs = model.generate(input_ids, attention_mask=attention_mask, max_new_tokens=512,
|
| 45 |
+
num_beam_groups=1,
|
| 46 |
+
num_beams=4,
|
| 47 |
+
do_sample=False,
|
| 48 |
+
diversity_penalty=0.0,
|
| 49 |
+
num_return_sequences=1,
|
| 50 |
+
length_penalty=2.0,
|
| 51 |
+
no_repeat_ngram_size=3,
|
| 52 |
+
early_stopping=True)
|
| 53 |
+
|
| 54 |
+
# all special tokens including will be removed
|
| 55 |
+
output_str = tokenizer.batch_decode(outputs, skip_special_tokens=True) # get the generated impressions
|
| 56 |
```
|
| 57 |
|
| 58 |
|