Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
base_model: Qwen/Qwen2.5-7B-Instruct
|
| 4 |
+
pipeline_tag: text-generation
|
| 5 |
+
library_name: peft
|
| 6 |
+
language:
|
| 7 |
+
- en
|
| 8 |
+
tags:
|
| 9 |
+
- qwen
|
| 10 |
+
- 7b
|
| 11 |
+
- peft
|
| 12 |
+
- lora
|
| 13 |
+
- qlora
|
| 14 |
+
- 4-bit
|
| 15 |
+
- healthcare
|
| 16 |
+
- triage
|
| 17 |
+
- nhs
|
| 18 |
+
- uk
|
| 19 |
+
- safety
|
| 20 |
+
metrics:
|
| 21 |
+
- perplexity
|
| 22 |
+
---
|
| 23 |
+
|
| 24 |
+
# DocMap UK Triage (Qwen2.5-7B-Instruct, QLoRA)
|
| 25 |
+
|
| 26 |
+
LoRA adapters (and merged model variant) for a UK NHS-style healthcare triage/navigation assistant. The model provides safe routing (999/111/GP/UTC/Pharmacy), concise guidance, citations (when provided), and a brief non‑diagnostic disclaimer.
|
| 27 |
+
|
| 28 |
+
## Intended use
|
| 29 |
+
- Preliminary UK triage guidance and healthcare navigation.
|
| 30 |
+
- Not a diagnostic tool. Not a medical device. Use under human oversight.
|
| 31 |
+
|
| 32 |
+
## Quick start (adapters)
|
| 33 |
+
```python
|
| 34 |
+
import torch
|
| 35 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 36 |
+
from peft import PeftModel
|
| 37 |
+
|
| 38 |
+
BASE = "Qwen/Qwen2.5-7B-Instruct"
|
| 39 |
+
ADAPTER = "<your-username>/docmap-uk-triage-lorav1-qwen7b"
|
| 40 |
+
|
| 41 |
+
tok = AutoTokenizer.from_pretrained(BASE, use_fast=True)
|
| 42 |
+
if tok.pad_token is None: tok.pad_token = tok.eos_token
|
| 43 |
+
|
| 44 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 45 |
+
BASE, device_map="auto", load_in_4bit=True, trust_remote_code=True
|
| 46 |
+
)
|
| 47 |
+
model = PeftModel.from_pretrained(model, ADAPTER)
|
| 48 |
+
|
| 49 |
+
SYSTEM = "You are DocMap's UK NHS triage assistant. Provide safe routing and a brief non‑diagnostic disclaimer."
|
| 50 |
+
msgs = [{"role":"system","content":SYSTEM},{"role":"user","content":"Headache 2 days, no vomiting."}]
|
| 51 |
+
prompt = tok.apply_chat_template(msgs, tokenize=False, add_generation_prompt=True)
|
| 52 |
+
inputs = tok(prompt, return_tensors="pt").to(model.device)
|
| 53 |
+
with torch.inference_mode():
|
| 54 |
+
out = model.generate(**inputs, max_new_tokens=320, temperature=0.2, top_p=0.9, repetition_penalty=1.03)
|
| 55 |
+
print(tok.decode(out[0], skip_special_tokens=True))
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
## Quick start (merged model)
|
| 59 |
+
```python
|
| 60 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 61 |
+
import torch
|
| 62 |
+
|
| 63 |
+
MODEL_ID = "<your-username>/docmap-uk-triage-merged-qwen2.5-7b"
|
| 64 |
+
tok = AutoTokenizer.from_pretrained(MODEL_ID, use_fast=True)
|
| 65 |
+
m = AutoModelForCausalLM.from_pretrained(MODEL_ID, device_map="auto", torch_dtype=torch.bfloat16)
|
| 66 |
+
|
| 67 |
+
msgs = [{"role":"system","content":"You are DocMap's UK NHS triage assistant."},
|
| 68 |
+
{"role":"user","content":"Chest discomfort on exertion, no sweating, no breathlessness."}]
|
| 69 |
+
prompt = tok.apply_chat_template(msgs, tokenize=False, add_generation_prompt=True)
|
| 70 |
+
ids = tok(prompt, return_tensors="pt").to(m.device)
|
| 71 |
+
with torch.inference_mode():
|
| 72 |
+
out = m.generate(**ids, max_new_tokens=320, temperature=0.2, top_p=0.9)
|
| 73 |
+
print(tok.decode(out[0], skip_special_tokens=True))
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
## Training summary
|
| 77 |
+
- Method: QLoRA (bitsandbytes 4‑bit nf4, double-quant, bfloat16 compute)
|
| 78 |
+
- LoRA: r=32, alpha=32, dropout=0.05; targets: q_proj,k_proj,v_proj,o_proj,gate_proj,up_proj,down_proj
|
| 79 |
+
- Seq len: 4096; batch: 1; grad_accum: 16; epochs: 3; lr: 2e‑4; gradient checkpointing
|
| 80 |
+
- Data: Supabase train bucket (`lorav1/**` JSONL: instruction, input?, output, citations)
|
| 81 |
+
|
| 82 |
+
## Evaluation (hold‑out 10%)
|
| 83 |
+
- Eval loss ≈ 0.243 → perplexity ≈ 1.27 (in‑distribution)
|
| 84 |
+
|
| 85 |
+
## Safety
|
| 86 |
+
- This is general information, not a medical diagnosis.
|
| 87 |
+
- Emergencies: call 999. Urgent concerns: contact NHS 111.
|
| 88 |
+
- Verify outputs clinically; model may miss edge cases.
|
| 89 |
+
|
| 90 |
+
## Files
|
| 91 |
+
- Adapters: `adapter_model.safetensors`, `adapter_config.json`
|
| 92 |
+
- Merged: `model.safetensors` (shards), `config.json`, tokenizer files, `chat_template.jinja` (default DocMap system)
|
| 93 |
+
|
| 94 |
+
## License
|
| 95 |
+
- Adapters and merged distribution: Apache‑2.0.
|
| 96 |
+
- Base model and any third‑party content follow their respective licenses.
|
| 97 |
+
|
| 98 |
+
## Acknowledgements
|
| 99 |
+
- Base: Qwen/Qwen2.5‑7B‑Instruct
|
| 100 |
+
- Tooling: PEFT, Transformers, TRL, bitsandbytes
|
| 101 |
+
- UK healthcare sources (NHS and reputable UK providers)
|