ruslanmv commited on
Commit
4480304
1 Parent(s): 0d2449b

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +42 -22
README.md CHANGED
@@ -79,36 +79,52 @@ pip install transformers bitsandbytes accelerate
79
  Here's a Python code snippet demonstrating how to interact with the `Medical-Llama3-8B-16bit` model and generate answers to your medical questions:
80
 
81
  ```python
 
82
  from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
83
  import torch
 
 
 
 
 
 
 
84
  model_name = "ruslanmv/Medical-Llama3-v2"
85
- device_map = 'auto'
86
- bnb_config = BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_quant_type="nf4",bnb_4bit_compute_dtype=torch.float16,)
87
- model = AutoModelForCausalLM.from_pretrained( model_name,quantization_config=bnb_config, trust_remote_code=True,use_cache=False,device_map=device_map)
88
- tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
89
- tokenizer.pad_token = tokenizer.eos_token
90
 
 
 
 
 
 
 
 
 
 
 
91
  def askme(question):
92
  sys_message = '''
93
- You are an AI Medical Assistant trained on a vast dataset of health information. Please be thorough and
94
- provide an informative answer. If you don't know the answer to a specific medical inquiry, advise seeking professional help.
95
  '''
96
  # Create messages structured for the chat template
97
  messages = [{"role": "system", "content": sys_message}, {"role": "user", "content": question}]
98
-
99
  # Applying chat template
100
  prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
101
- inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
102
- outputs = model.generate(**inputs, max_new_tokens=100, use_cache=True)
103
-
 
 
 
 
104
  # Extract and return the generated text, removing the prompt
105
- response_text = tokenizer.batch_decode(outputs)[0].strip()
106
- answer = response_text.split('<|im_start|>assistant')[-1].strip()
107
- return answer
108
- # Example usage
109
- # - Context: First describe your problem.
110
- # - Question: Then make the question.
111
 
 
 
112
  question = '''I'm a 35-year-old male and for the past few months, I've been experiencing fatigue,
113
  increased sensitivity to cold, and dry, itchy skin.
114
  Could these symptoms be related to hypothyroidism?
@@ -119,11 +135,15 @@ print(askme(question))
119
  ```
120
  the type of answer is :
121
  ```
122
- Based on your description, it sounds like you may be experiencing symptoms of hypothyroidism.
123
- Hypothyroidism is a condition where the thyroid gland doesn't produce enough hormones, leading to a variety of symptoms.
124
- Some common symptoms include fatigue, weight gain, constipation, and dry skin.
125
- If you're experiencing any of these symptoms, it's important to see a doctor for a proper diagnosis and treatment plan.
126
- Your doctor may order blood tests to check your thyroid hormone levels
 
 
 
 
127
  ```
128
  **Important Note**
129
 
 
79
  Here's a Python code snippet demonstrating how to interact with the `Medical-Llama3-8B-16bit` model and generate answers to your medical questions:
80
 
81
  ```python
82
+
83
  from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
84
  import torch
85
+
86
+ # Define BitsAndBytesConfig
87
+ bnb_config = BitsAndBytesConfig(load_in_4bit=True,
88
+ bnb_4bit_quant_type="nf4",
89
+ bnb_4bit_compute_dtype=torch.float16)
90
+
91
+ # Model name
92
  model_name = "ruslanmv/Medical-Llama3-v2"
 
 
 
 
 
93
 
94
+ # Load tokenizer and model with BitsAndBytesConfig
95
+ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True, bnb_config=bnb_config)
96
+ model = AutoModelForCausalLM.from_pretrained(model_name, config=bnb_config)
97
+
98
+ # Ensure model is on the correct device
99
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
100
+ model.to(device)
101
+
102
+
103
+ # Define askme function
104
  def askme(question):
105
  sys_message = '''
106
+ You are Medical AI Assistant. Please be thorough and provide an informative answer.
107
+ If you don't know the answer to a specific medical inquiry, advise seeking professional help.
108
  '''
109
  # Create messages structured for the chat template
110
  messages = [{"role": "system", "content": sys_message}, {"role": "user", "content": question}]
111
+
112
  # Applying chat template
113
  prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
114
+ inputs = tokenizer(prompt, return_tensors="pt", truncation=True, padding=True, max_length=1000)
115
+ # Move inputs to device
116
+ input_ids = inputs['input_ids'].to(device)
117
+ attention_mask = inputs['attention_mask'].to(device)
118
+ # Generate outputs
119
+ with torch.no_grad():
120
+ outputs = model.generate(input_ids=input_ids, attention_mask=attention_mask, max_length=1000, use_cache=True)
121
  # Extract and return the generated text, removing the prompt
122
+ response_text = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
123
+ return response_text
124
+
 
 
 
125
 
126
+
127
+ # Example usage
128
  question = '''I'm a 35-year-old male and for the past few months, I've been experiencing fatigue,
129
  increased sensitivity to cold, and dry, itchy skin.
130
  Could these symptoms be related to hypothyroidism?
 
135
  ```
136
  the type of answer is :
137
  ```
138
+ Assistant: You should consult a physician for a proper diagnosis and discussion of treatment options. As a medical AI assistant, I do not have access to your medical history, nor can I physically examine you, so I can only provide an answer based on the information you provide. It is always best to seek the advice of a medical professional for an accurate diagnosis and treatment plan.
139
+ That being said, the symptoms you have described could be related to hypothyroidism, which is a condition in which the thyroid gland does not produce sufficient hormone. Hypothyroidism can have a number of causes, including a deficiency of iodine, a tumor of the pituitary gland that reduces thyroxine (T4) production, or autoimmune disease that damages the thyroid gland. In addition to the symptoms you have described, other possible signs of hypothyroidism include weight gain, cold intolerance, fatigue, dry skin, joint pain, memory loss, depression, and loss of sexual desire.
140
+ To determine whether your symptoms are related to hypothyroidism, your physician will start by taking a history and performing a physical examination. He or she will also order several laboratory tests, including:
141
+ 1. TSH test: This test measures the level of TSH (thyroid-stimulating hormone) in your blood. TSH stimulates the thyroid gland to produce T4. If your TSH level is elevated, it can indicate that your thyroid gland is not producing enough T4.
142
+ 2. T4 test: This test measures the level of T4 in your blood. T4 is the main hormone produced by the thyroid gland. If your T4 level is low, it can indicate that your thyroid gland is not functioning properly.
143
+ 3. T3 test: This test measures the level of T3 in your blood. T3 is another hormone produced by the thyroid gland. T3 is more active than T4 and has a number of important functions in the body, including regulating metabolism.
144
+ 4. thyroid-stimulating immunoglobulin (TSI) test: This test looks for an antibody called TSI in your blood. TSI stimulates the thyroid gland to produce more T4 and T3, even when the pituitary gland is not stimulating the thyroid gland to produce these hormones. The presence of TSI can indicate autoimmune thyroiditis.
145
+ 5. thyroid peroxidase antibody test: This test looks for an antibody called thyroid peroxidase in your blood. This antibody attacks the thyroid gland and can cause the gland to become damaged. The presence of this antibody can indicate autoimmune thyroiditis.
146
+ If any of these tests suggest that you have hypothyroidism, your physician may want to order additional tests to confirm the diagnosis. If you are found to have hypothyroidism, treatment will consist of daily medication to replace the missing hormone. With proper treatment, the symptoms of hypothyroidism usually improve within two months.
147
  ```
148
  **Important Note**
149