Views
No views yet
True/False)emilyalsentzer/Bio ClinicalBERT1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2tokenizer = AutoTokenizer.from_pretrained("cja5553/Bio_ClinicalBERT_MIMIC_IV_death_in_30_prediction_IA3_ti")
3model = AutoModelForSequenceClassification.from_pretrained("cja5553/Bio_ClinicalBERT_MIMIC_IV_death_in_30_prediction_IA3_ti")1import torch
2
3def get_outcome(tokenizer, model, text, device="cuda:0", max_length=512):
4
5 device = torch.device(device)
6 model = model.to(device)
7 model.eval()
8
9 inputs = tokenizer(
10 text,
11 return_tensors="pt",
12 max_length=max_length,
13 truncation=True,
14 padding="max_length"
15 ).to(device)
16
17 with torch.no_grad():
18 outputs = model(**inputs)
19 probs = torch.softmax(outputs.logits, dim=-1)[0] # (2,)
20
21 probs = probs.detach().cpu().numpy()
22 result = {
23 "False": float(probs[0]),
24 "True": float(probs[1])
25 }
26
27 return result
28