Views
No views yet
1
2models:
3 - model: Undi95/Llama-3-Unholy-8B
4 parameters:
5 weight: [0.25, 0.35, 0.45, 0.35, 0.25]
6 density: [0.1, 0.25, 0.5, 0.25, 0.1]
7 - model: Locutusque/llama-3-neural-chat-v1-8b
8 - model: ruslanmv/Medical-Llama3-8B-16bit
9 parameters:
10 weight: [0.55, 0.45, 0.35, 0.45, 0.55]
11 density: [0.1, 0.25, 0.5, 0.25, 0.1]
12merge_method: dare_ties
13base_model: Locutusque/llama-3-neural-chat-v1-8b
14parameters:
15 int8_mask: true
16dtype: bfloat16
17| Subject | Medichat-Llama3-8B Accuracy (%) | Dr. Samantha Accuracy (%) |
|---|---|---|
| Clinical Knowledge | 71.70 | 52.83 |
| Medical Genetics | 78.00 | 49.00 |
| Human Aging | 70.40 | 58.29 |
| Human Sexuality | 73.28 | 55.73 |
| College Medicine | 62.43 | 38.73 |
| Anatomy | 64.44 | 41.48 |
| College Biology | 72.22 | 52.08 |
| High School Biology | 77.10 | 53.23 |
| Professional Medicine | 63.97 | 38.73 |
| Nutrition | 73.86 | 50.33 |
| Professional Psychology | 68.95 | 46.57 |
| Virology | 54.22 | 41.57 |
| High School Psychology | 83.67 | 66.60 |
| Average | 70.33 | 48.85 |
1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3
4class MedicalAssistant:
5 def __init__(self, model_name="sethuiyer/Medichat-Llama3-8B", 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)
40ollama run monotykamary/medichat-llama3 in your
terminal. If you have limited computing resources, check out this video to learn how to run it on
a Google Colab backend.