Views
No views yet
This model is for educational and informational purposes only.
It is not a substitute for professional medical advice, diagnosis, or treatment.
Always consult a qualified healthcare provider for medical concerns.
1from transformers import AutoTokenizer, AutoModelForCausalLM
2
3model_id = "nabilfaieaz/tinyllama-med-full"
4
5# Load tokenizer and model
6tokenizer = AutoTokenizer.from_pretrained(model_id)
7if tokenizer.pad_token is None:
8 tokenizer.pad_token = tokenizer.eos_token
9
10model = AutoModelForCausalLM.from_pretrained(
11 model_id,
12 torch_dtype="auto",
13 device_map="auto"
14)
15
16# Example prompt
17system_prompt = (
18 "You are a helpful, concise medical assistant. Provide general information only, "
19 "not a diagnosis. If urgent or personal issues are mentioned, advise seeing a clinician."
20)
21
22question = "What is hypertension?"
23prompt = f"{system_prompt}\n\nQuestion: {question}\nAnswer:"
24
25inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
26outputs = model.generate(
27 **inputs,
28 max_new_tokens=128,
29 do_sample=False,
30 temperature=0.0,
31 top_p=1.0,
32 eos_token_id=tokenizer.eos_token_id,
33 pad_token_id=tokenizer.pad_token_id
34)
35
36print(tokenizer.decode(outputs[0], skip_special_tokens=True))
37
38🧠 Training Details
39Base model: TinyLlama/TinyLlama-1.1B-Chat-v1.0
40Fine-tuning method: LoRA (via peft)
41Target modules: q_proj, k_proj, v_proj, o_proj
42LoRA config:
43 * r = 16
44 * alpha = 16
45 * dropout = 0.0
46Max sequence length: 512 tokens
47Batch size: 2 per device (gradient accumulation for effective batch)
48Learning rate: 2e-4
49Precision: fp16
50Evaluation: periodic eval every 200 steps
51Checkpoints: saved every 500 steps, final merge from checkpoint-17000
52
53📊 Intended Use
54Intended:
55 * Educational explanations of medical terms and concepts
56 * Study aid for medical students and healthcare professionals
57 * Healthcare-related chatbot demos
58
59Not intended:
60 * Real-time clinical decision making
61 * Emergency medical guidance
62 * Handling sensitive personal medical data (PHI)
63⚙️ Technical Notes
64 * The model is merged — you don’t need to separately load LoRA adapters.
65 * Works with Hugging Face transformers ≥ 4.38.
66 * Can be quantized to 4-bit (e.g., QLoRA) for local inference.
67