Views
No views yet
mistralai/Mistral-7B-Instruct-v0.2] for medical question answering, fine-tuned using QLoRA (4-bit) and PEFT on a custom medical Q&A dataset.mistralai/Mistral-7B-Instruct-v0.2adapter_model.safetensors)⚠️ Not for real-world clinical use. This model is for research/educational purposes only.
| Metric | Before LoRA | After LoRA |
|---|---|---|
| BLEU | 0.0145 | 0.0721 |
| F1 | 0.2457 | 0.3901 |
1from transformers import AutoModelForCausalLM, AutoTokenizer
2from peft import PeftModel
3import torch
4
5tokenizer = AutoTokenizer.from_pretrained("your-username/mistral-7b-medical-qa-lora")
6base_model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-Instruct-v0.2", torch_dtype=torch.float16, device_map="auto")
7model = PeftModel.from_pretrained(base_model, "your-username/mistral-7b-medical-qa-lora")
8
9def ask_medical_question(question):
10 prompt = f"<s>[INST] {question} [/INST]"
11 inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
12 with torch.no_grad():
13 output = model.generate(**inputs, max_new_tokens=150, temperature=0.7)
14 return tokenizer.decode(output[0], skip_special_tokens=True).split("[/INST]")[-1].strip()
15
16print(ask_medical_question("What is diabetes?"))