Views
No views yet
| Subject | Model Accuracy (%) |
|---|---|
| Clinical Knowledge | 71.70 |
| Medical Genetics | 78.00 |
| Human Aging | 70.40 |
| Human Sexuality | 73.28 |
| College Medicine | 62.43 |
| Anatomy | 64.44 |
| College Biology | 72.22 |
| High School Biology | 77.10 |
| Professional Medicine | 63.97 |
| Nutrition | 73.86 |
| Professional Psychology | 68.95 |
| Virology | 54.22 |
| High School Psychology | 83.67 |
| Average | 70.33 |
1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3
4class MedicalAssistant:
5 def __init__(self, model_name="SpectreLynx/Ryeta-0", device="cuda"):
6 self.device = device
7 self.tokenizer = AutoTokenizer.from_pretrained(model_name)
8 self.model = AutoModelForCausalLM.from_pretrained(model_name).to(self.device)
9 self.sys_message = '''
10 You are an AI Medical Assistant trained on a vast dataset of health information. Please be thorough and
11 provide an informative answer. If you don't know the answer to a specific medical inquiry, advise seeking professional help.
12 '''
13
14 def format_prompt(self, question):
15 messages = [
16 {"role": "system", "content": self.sys_message},
17 {"role": "user", "content": question}
18 ]
19 prompt = self.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
20 return prompt
21
22 def generate_response(self, question, max_new_tokens=512):
23 prompt = self.format_prompt(question)
24 inputs = self.tokenizer(prompt, return_tensors="pt").to(self.device)
25 with torch.no_grad():
26 outputs = self.model.generate(**inputs, max_new_tokens=max_new_tokens, use_cache=True)
27 answer = self.tokenizer.batch_decode(outputs, skip_special_tokens=True)[0].strip()
28 return answer
29
30if __name__ == "__main__":
31 assistant = MedicalAssistant()
32 question = '''
33 Symptoms:
34 Dizziness, headache, and nausea.
35
36 What is the differential diagnosis?
37 '''
38 response = assistant.generate_response(question)
39 print(response)
40