Update README.md
Browse files
README.md
CHANGED
@@ -46,32 +46,41 @@ from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
46 |
# Load tokenizer and model
|
47 |
tokenizer = AutoTokenizer.from_pretrained("ruslanmv/Medical-Llama3-8B")
|
48 |
model = AutoModelForCausalLM.from_pretrained("ruslanmv/Medical-Llama3-8B").to("cuda") # If using GPU
|
49 |
-
|
50 |
-
# Function to format and generate response with prompt engineering
|
51 |
def askme(question):
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
outputs = model.generate(**inputs, max_new_tokens=64, use_cache=True) # Adjust max_new_tokens for longer responses
|
67 |
answer = tokenizer.batch_decode(outputs)[0].strip()
|
68 |
return answer
|
69 |
|
70 |
# Example usage
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
print(askme(question))
|
73 |
```
|
|
|
|
|
|
|
74 |
|
|
|
75 |
**Important Note**
|
76 |
|
77 |
This model is intended for informational purposes only and should not be used as a substitute for professional medical advice. Always consult with a qualified healthcare provider for any medical concerns.
|
|
|
46 |
# Load tokenizer and model
|
47 |
tokenizer = AutoTokenizer.from_pretrained("ruslanmv/Medical-Llama3-8B")
|
48 |
model = AutoModelForCausalLM.from_pretrained("ruslanmv/Medical-Llama3-8B").to("cuda") # If using GPU
|
49 |
+
# Function to format and generate response with prompt engineering using a chat template
|
|
|
50 |
def askme(question):
|
51 |
+
sys_message = '''
|
52 |
+
You are an AI Medical Assistant trained on a vast dataset of health information. Please be thorough and
|
53 |
+
provide an informative answer. If you don't know the answer to a specific medical inquiry, advise seeking professional help.
|
54 |
+
'''
|
55 |
+
|
56 |
+
# Create messages structured for the chat template
|
57 |
+
messages = [{"role": "system", "content": sys_message}, {"role": "user", "content": question}]
|
58 |
+
|
59 |
+
# Applying chat template
|
60 |
+
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
61 |
+
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
|
62 |
+
outputs = model.generate(**inputs, max_new_tokens=100, use_cache=True) # Adjust max_new_tokens for longer responses
|
63 |
+
|
64 |
+
# Extract and return the generated text
|
|
|
65 |
answer = tokenizer.batch_decode(outputs)[0].strip()
|
66 |
return answer
|
67 |
|
68 |
# Example usage
|
69 |
+
# - Context: First describe your problem.
|
70 |
+
# - Question: Then make the question.
|
71 |
+
question = '''
|
72 |
+
I'm a 35-year-old male and for the past few months, I've been experiencing fatigue, increased sensitivity to cold, and dry, itchy skin.
|
73 |
+
|
74 |
+
Could these symptoms be related to hypothyroidism?
|
75 |
+
If so, what steps should I take to get a proper diagnosis and discuss treatment options?
|
76 |
+
'''
|
77 |
print(askme(question))
|
78 |
```
|
79 |
+
the type of answer is :
|
80 |
+
```
|
81 |
+
Hello, I can understand your concern. I would suggest you to get a blood test done for TSH, T3, T4, and TPO antibodies. If the TSH is high, then you can be diagnosed with hypothyroidism. If the TSH is normal, then you can be diagnosed with Hashimoto's thyroiditis. In both cases, you will need to take levothyroxine. Hope I have answered your query. Let me know if I can assist you
|
82 |
|
83 |
+
```
|
84 |
**Important Note**
|
85 |
|
86 |
This model is intended for informational purposes only and should not be used as a substitute for professional medical advice. Always consult with a qualified healthcare provider for any medical concerns.
|