Update README with proper YAML metadata
Browse files
README.md
CHANGED
@@ -1,6 +1,23 @@
|
|
1 |
---
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
---
|
5 |
|
6 |
# BioMistral-7B LoRA Fine-tuned on MedQuAD
|
@@ -74,51 +91,7 @@ pip install transformers peft torch accelerate bitsandbytes
|
|
74 |
|
75 |
## Usage
|
76 |
|
77 |
-
###
|
78 |
-
|
79 |
-
```python
|
80 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
81 |
-
import torch
|
82 |
-
|
83 |
-
# Load the fine-tuned model
|
84 |
-
model_name = "ayuwal12/biomistral-7b-finetuned"
|
85 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
86 |
-
model = AutoModelForCausalLM.from_pretrained(
|
87 |
-
model_name,
|
88 |
-
device_map="auto",
|
89 |
-
torch_dtype=torch.float16
|
90 |
-
)
|
91 |
-
|
92 |
-
def generate_medical_response(question, context="", max_length=256):
|
93 |
-
# Format the prompt for medical Q&A
|
94 |
-
if context.strip():
|
95 |
-
prompt = f"### Instruction:\\n{question}\\n\\n### Input:\\n{context}\\n\\n### Response:\\n"
|
96 |
-
else:
|
97 |
-
prompt = f"### Instruction:\\n{question}\\n\\n### Response:\\n"
|
98 |
-
|
99 |
-
# Tokenize and generate
|
100 |
-
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
101 |
-
|
102 |
-
with torch.no_grad():
|
103 |
-
outputs = model.generate(
|
104 |
-
**inputs,
|
105 |
-
max_new_tokens=max_length,
|
106 |
-
temperature=0.7,
|
107 |
-
do_sample=True,
|
108 |
-
pad_token_id=tokenizer.eos_token_id,
|
109 |
-
eos_token_id=tokenizer.eos_token_id
|
110 |
-
)
|
111 |
-
|
112 |
-
# Decode and extract response
|
113 |
-
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
114 |
-
return response.split("### Response:\\n")[-1].strip()
|
115 |
-
|
116 |
-
# Example usage
|
117 |
-
response = generate_medical_response("What is diabetes and what are its main types?")
|
118 |
-
print(response)
|
119 |
-
```
|
120 |
-
|
121 |
-
### Option 2: Using LoRA Adapters (Recommended)
|
122 |
|
123 |
```python
|
124 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
@@ -144,9 +117,9 @@ if tokenizer.pad_token is None:
|
|
144 |
|
145 |
def generate_medical_response(question, context="", max_length=256):
|
146 |
if context.strip():
|
147 |
-
prompt = f"### Instruction
|
148 |
else:
|
149 |
-
prompt = f"### Instruction
|
150 |
|
151 |
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
152 |
|
@@ -160,7 +133,7 @@ def generate_medical_response(question, context="", max_length=256):
|
|
160 |
)
|
161 |
|
162 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
163 |
-
return response.split("### Response
|
164 |
|
165 |
# Example usage
|
166 |
response = generate_medical_response("What are the symptoms of hypertension?")
|
@@ -258,7 +231,7 @@ If you use this model, please cite:
|
|
258 |
title={BioMistral-7B LoRA Fine-tuned on MedQuAD},
|
259 |
author={Ayuwal},
|
260 |
year={2024},
|
261 |
-
howpublished={https://huggingface.co/ayuwal12/biomistral-7b-
|
262 |
}
|
263 |
```
|
264 |
|
@@ -276,4 +249,4 @@ For questions or issues, please open an issue on the model repository.
|
|
276 |
|
277 |
---
|
278 |
|
279 |
-
*This model was trained on the MedQuAD dataset and is intended for educational and research purposes in the medical domain. Always consult healthcare professionals for medical advice.*
|
|
|
1 |
---
|
2 |
+
license: apache-2.0
|
3 |
+
base_model: BioMistral/BioMistral-7B
|
4 |
+
tags:
|
5 |
+
- medical
|
6 |
+
- biomedical
|
7 |
+
- healthcare
|
8 |
+
- question-answering
|
9 |
+
- lora
|
10 |
+
- peft
|
11 |
+
- medquad
|
12 |
+
- biomistral
|
13 |
+
- instruction-tuning
|
14 |
+
language:
|
15 |
+
- en
|
16 |
+
datasets:
|
17 |
+
- jpmiller/medquad
|
18 |
+
library_name: peft
|
19 |
+
pipeline_tag: text-generation
|
20 |
+
model_type: mistral
|
21 |
---
|
22 |
|
23 |
# BioMistral-7B LoRA Fine-tuned on MedQuAD
|
|
|
91 |
|
92 |
## Usage
|
93 |
|
94 |
+
### Using LoRA Adapters (Recommended)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
```python
|
97 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
117 |
|
118 |
def generate_medical_response(question, context="", max_length=256):
|
119 |
if context.strip():
|
120 |
+
prompt = f"### Instruction:\n{question}\n\n### Input:\n{context}\n\n### Response:\n"
|
121 |
else:
|
122 |
+
prompt = f"### Instruction:\n{question}\n\n### Response:\n"
|
123 |
|
124 |
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
125 |
|
|
|
133 |
)
|
134 |
|
135 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
136 |
+
return response.split("### Response:\n")[-1].strip()
|
137 |
|
138 |
# Example usage
|
139 |
response = generate_medical_response("What are the symptoms of hypertension?")
|
|
|
231 |
title={BioMistral-7B LoRA Fine-tuned on MedQuAD},
|
232 |
author={Ayuwal},
|
233 |
year={2024},
|
234 |
+
howpublished={https://huggingface.co/ayuwal12/biomistral-7b-lora-adapters},
|
235 |
}
|
236 |
```
|
237 |
|
|
|
249 |
|
250 |
---
|
251 |
|
252 |
+
*This model was trained on the MedQuAD dataset and is intended for educational and research purposes in the medical domain. Always consult healthcare professionals for medical advice.*
|