Views
No views yet
1import torch
2from transformers import GPT2LMHeadModel, GPT2Tokenizer
3
4
5path = "Mohammed-Altaf/Medical-ChatBot"
6device = "cuda" if torch.cuda.is_available() else "cpu"
7tokenizer = GPT2Tokenizer.from_pretrained(path)
8model = GPT2LMHeadModel.from_pretrained(path).to(device)
9
10prompt_input = (
11 "The conversation between human and AI assistant.\n"
12 "[|Human|] {input}\n"
13 "[|AI|]"
14)
15sentence = prompt_input.format_map({'input': "what is parkinson's disease?"})
16inputs = tokenizer(sentence, return_tensors="pt").to(device)
17
18with torch.no_grad():
19 beam_output = model.generate(**inputs,
20 min_new_tokens=1,
21 max_length=512,
22 num_beams=3,
23 repetition_penalty=1.2,
24 early_stopping=True,
25 eos_token_id=198
26 )
27 print(tokenizer.decode(beam_output[0], skip_special_tokens=True))The conversation between human and AI assistant.
[|Human|] what is parkinson's disease?
[|AI|] Parkinson's disease is a neurodegenerative disorder that affects movement. It is caused by the loss of dopamine-producing cells in the brain.The conversation between human and AI assistant.
[|Human|] what type of honey is best for a bad covid cough?
[|AI|] Manuka honey has been shown to have anti-inflammatory and antibacterial properties that can help alleviate symptoms of a bad covid cough.