Views
No views yet
1from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
2
3tokenizer = AutoTokenizer.from_pretrained("razent/SciFive-large-Pubmed_PMC-MedNLI")
4model = AutoModelForSeq2SeqLM.from_pretrained("razent/SciFive-large-Pubmed_PMC-MedNLI")
5model.cuda()
6
7sent_1 = "In the ED, initial VS revealed T 98.9, HR 73, BP 121/90, RR 15, O2 sat 98% on RA."
8sent_2 = "The patient is hemodynamically stable"
9text = f"mednli: sentence1: {sent_1} sentence2: {sent_2}"
10
11encoding = tokenizer.encode_plus(text, padding='max_length', max_length=256, return_tensors="pt")
12input_ids, attention_masks = encoding["input_ids"].to("cuda"), encoding["attention_mask"].to("cuda")
13
14outputs = model.generate(
15 input_ids=input_ids, attention_mask=attention_masks,
16 max_length=8,
17 early_stopping=True
18)
19
20for output in outputs:
21 line = tokenizer.decode(output, skip_special_tokens=True, clean_up_tokenization_spaces=True)
22 print(line)