Views
No views yet
| Property | Value |
|---|---|
| Base Model | unsloth/mistral-7b-v0.3-bnb-4bit |
| Fine-tuning Method | QLoRA (4-bit quantization + LoRA adapters) |
| Training Framework | Unsloth + TRL |
| Trainable Parameters | ~42M (LoRA adapters) |
| Context Length | 2048 tokens |
| License | Apache 2.0 |
1from unsloth import FastLanguageModel
2
3model, tokenizer = FastLanguageModel.from_pretrained(
4 model_name="sri2000us/swasthai-medical-7b",
5 max_seq_length=2048,
6 load_in_4bit=True,
7)
8FastLanguageModel.for_inference(model)
9
10def ask_swasthai(question):
11 prompt = f"""### Instruction:
12You are SwasthAI, an expert Indian healthcare assistant. Answer the medical question accurately.
13
14### Input:
15{question}
16
17### Response:
18"""
19 inputs = tokenizer([prompt], return_tensors="pt").to("cuda")
20 outputs = model.generate(**inputs, max_new_tokens=256, use_cache=True)
21 response = tokenizer.batch_decode(outputs)[0]
22 return response.split("### Response:")[-1].strip()
23
24# Example
25print(ask_swasthai("What are the symptoms of diabetes?"))1from transformers import AutoModelForCausalLM, AutoTokenizer
2from peft import PeftModel
3
4# Load base model
5base_model = AutoModelForCausalLM.from_pretrained(
6 "mistralai/Mistral-7B-v0.3",
7 load_in_4bit=True,
8 device_map="auto",
9)
10tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-v0.3")
11
12# Load LoRA adapters
13model = PeftModel.from_pretrained(base_model, "sri2000us/swasthai-medical-7b")### Instruction:
You are SwasthAI, an expert Indian healthcare assistant. Answer the medical question accurately.
### Input:
{user_question}
### Response:
{model_response}Common symptoms include increased thirst and frequent urination, unexplained weight loss, fatigue, blurred vision, slow-healing wounds, and numbness in extremities. If you experience these, consult a doctor for HbA1c and fasting blood sugar tests.
Reduce sodium intake, follow DASH diet, exercise 30 minutes daily, maintain healthy weight, limit alcohol, practice yoga/meditation, and include potassium-rich foods. Always continue prescribed medications.
1# LoRA Configuration
2r = 16
3lora_alpha = 16
4lora_dropout = 0
5target_modules = ["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"]
6
7# Training Arguments
8learning_rate = 2e-4
9batch_size = 2
10gradient_accumulation_steps = 4
11num_epochs = 1
12optimizer = "adamw_8bit"1@misc{swasthai-medical-7b,
2 author = {SwasthAI Team},
3 title = {SwasthAI Medical 7B: Fine-tuned Mistral for Indian Healthcare},
4 year = {2025},
5 publisher = {HuggingFace},
6 url = {https://huggingface.co/sri2000us/swasthai-medical-7b}
7}