CoolFace
Modelpublic

AmareshHebbar/pharmacy-ner-qwen25-1b

sourceHugging Faceapache-2.0updated 3mo agoView on Hugging Face
0likes5downloads
Model Card

<div align="center">

๐Ÿ’Š Pharmacy NER โ€” Drug Entity Extraction

Qwen2.5-1.5B fine-tuned for pharmacy ner โ€” drug entity extraction

![Hugging Face](https://huggingface.co/AmareshHebbar/pharmacy-ner-qwen25-1b) ![Dataset](https://huggingface.co/datasets/AmareshHebbar/pharmacy-ner-sft) ![License](https://www.apache.org/licenses/LICENSE-2.0) ![Base Model](https://huggingface.co/unsloth/Qwen2.5-1.5B-Instruct) ![Unsloth](https://github.com/unslothai/unsloth) ![W&B](https://wandb.ai/amareshhebbar-/axiomapper/runs/5lwyt4sx)

Part of the [Medical AI Fine-tuned Model Suite](https://huggingface.co/AmareshHebbar/medical-ai-model-suite) โ€” 16 specialist models, one per task

</div>


TL;DR

Extracts structured medication entities โ€” drug name, dosage, frequency, route, indication โ€” as JSON.

INPUT:  Administer Vancomycin 1.5g IV every 12 hours for MRSA bacteraemia.
OUTPUT: {"drug": "Vancomycin", "dosage": "1.5g", "frequency": "every 12 hours", "route": "IV", "indication": "MRSA bacteraemia"}
Base modelunsloth/Qwen2.5-1.5B-Instruct
MethodQLoRA, 4-bit NF4, rank 16
Training datapharmacy-ner-sft โ€” 3,500 real-world rows
Training computeNVIDIA A40 (48GB), ~0.5h
LicenseApache 2.0

Architecture

                  +-------------------------+
  user prompt --> |  Qwen2.5-1.5B-Instruct  | --> base weights (frozen, 4-bit NF4)
                  |  + LoRA adapter (r=16)  | --> pharmacy-ner-qwen25-1b
                  +-------------------------+
                              |
                              v
                     structured output
                  (code / JSON / classification)

This repo contains only the LoRA adapter (~20MB), not the full merged weights. Load it on top of the base model as shown below โ€” this keeps the download small and lets you swap adapters on one base model in memory.


Intended use

Power medication reconciliation systems, pharmacovigilance pipelines.

Direct use

Paste a sentence mentioning a medication, get structured JSON entities back.

Downstream use

Feed extracted entities into a medication reconciliation tool or adverse-event reporting pipeline.

Out of scope

Drug interaction checking or dosage safety validation โ€” this model extracts entities, it does not assess clinical appropriateness.

This model is not a substitute for a certified medical professional's judgment. Output should be reviewed by a qualified person before being used in a clinical or billing decision.

Quickstart

Option A โ€” Transformers + PEFT

python
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
import torch

base_model = "unsloth/Qwen2.5-1.5B-Instruct"
adapter    = "AmareshHebbar/pharmacy-ner-qwen25-1b"

tokenizer = AutoTokenizer.from_pretrained(base_model)
model = AutoModelForCausalLM.from_pretrained(
    base_model,
    torch_dtype=torch.bfloat16,
    device_map="auto",
)
model = PeftModel.from_pretrained(model, adapter)

messages = [
    {"role": "system", "content": "You are a pharmacy NLP system. Extract drug name, dosage, frequency, route of administration, and indication from the text."},
    {"role": "user", "content": "Administer Vancomycin 1.5g IV every 12 hours for MRSA bacteraemia."},
]
inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True).to(model.device)
outputs = model.generate(inputs, max_new_tokens=128, temperature=0.1, do_sample=True)
print(tokenizer.decode(outputs[0][inputs.shape[1]:], skip_special_tokens=True))

Expected output:

{"drug": "Vancomycin", "dosage": "1.5g", "frequency": "every 12 hours", "route": "IV", "indication": "MRSA bacteraemia"}

Option B โ€” Unsloth (2x faster load + inference)

python
from unsloth import FastLanguageModel

model, tokenizer = FastLanguageModel.from_pretrained(
    model_name="AmareshHebbar/pharmacy-ner-qwen25-1b",
    max_seq_length=512,
    load_in_4bit=True,
)
FastLanguageModel.for_inference(model)

messages = [
    {"role": "system", "content": "You are a pharmacy NLP system. Extract drug name, dosage, frequency, route of administration, and indication from the text."},
    {"role": "user", "content": "Patient is on Warfarin 5mg orally once daily for atrial fibrillation."},
]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens=128, temperature=0.1, do_sample=True)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))

Option C โ€” vLLM (production serving, OpenAI-compatible)

bash
vllm serve unsloth/Qwen2.5-1.5B-Instruct \
    --enable-lora \
    --lora-modules pharmacy-ner-qwen25-1b=AmareshHebbar/pharmacy-ner-qwen25-1b \
    --host 0.0.0.0 --port 8000 --dtype bfloat16
python
from openai import OpenAI

client = OpenAI(base_url="http://localhost:8000/v1", api_key="not-needed")
response = client.chat.completions.create(
    model="pharmacy-ner-qwen25-1b",
    messages=[
        {"role": "system", "content": "You are a pharmacy NLP system. Extract drug name, dosage, frequency, route of administration, and indication from the text."},
        {"role": "user", "content": "Morphine sulphate 10mg SC PRN every 4 hours for severe cancer pain."},
    ],
    temperature=0.1,
)
print(response.choices[0].message.content)

Option D โ€” GGUF / llama.cpp (CPU / edge inference)

This repo ships LoRA adapter weights, not a pre-merged GGUF. To run on llama.cpp, merge first:

bash
pip install unsloth
python -c "
from unsloth import FastLanguageModel
model, tokenizer = FastLanguageModel.from_pretrained('AmareshHebbar/pharmacy-ner-qwen25-1b', load_in_4bit=False)
model.save_pretrained_gguf('pharmacy-ner-qwen25-1b-gguf', tokenizer, quantization_method='q4_k_m')
"

Training details

Data

Trained on 3,500 examples extracted from bigbio/drugprot โ€” biomedical abstracts with drug-protein interaction annotations (source). No synthetic or LLM-generated training data โ€” every example pairs real-world input with its authoritative output.

SplitRows
Train2,800
Validation350
Test350

Full extraction pipeline documented on the dataset card.

Hyperparameters

ParameterValue
LoRA rank (r)16
LoRA alpha32
LoRA dropout0
Target modulesqproj, kproj, vproj, oproj, gateproj, upproj, down_proj
Quantization4-bit NF4 (QLoRA)
Max sequence length512
Optimizerpagedadamw8bit
LR schedule2e-4, cosine
Gradient checkpointingUnsloth (smart offload)

Training compute

GPUNVIDIA A40 (48GB)
Cloud providerRunPod
Training time~0.5h (incl. eval + hub push)
TrackingW&B run
CO2 estimateself-reported, not measured with a carbon tracker โ€” treat as approximate

Fine-tuned with Unsloth for 2x faster training and reduced VRAM, using TRL's SFTTrainer. Full project: wandb.ai/amareshhebbar-/axiomapper.


Bias, risks & limitations

Data recency. Training data reflects a specific snapshot in time (CMS FY2026 / dataset publish date). Codes, rates, and rules referenced may become outdated as source authorities issue updates โ€” always cross-check against the live authoritative source before high-stakes use.

Failure mode. Like any LLM, this model can produce a plausible-sounding but incorrect output, especially on rare, ambiguous, or highly compound real-world cases that fall outside the training distribution. It does not know when it's wrong.

Language. English-language input only (Hindi-medical model excepted, where Hindi system prompts are used but underlying clinical reasoning data is largely English-sourced).

Not a regulated medical device. This model has not been validated, cleared, or approved by any regulatory body (FDA, CDSCO, or equivalent) as a medical device or clinical decision support tool. It is a research/engineering artifact.

Misapplication risk. Do not use this model as the sole basis for a clinical, billing, or compliance decision affecting a real patient or claim. Do not deploy in an emergency triage context without a human-in-the-loop and clear escalation paths.


FAQ

Q: Can I merge the adapter into the base model for faster inference? Yes โ€” use model.merge_and_unload() after loading with PEFT, or use Unsloth's save_pretrained_merged() method.

Q: Why QLoRA instead of full fine-tuning? The base model already has strong language and medical knowledge from pretraining. QLoRA adapts only ~0.5-1% of parameters, which is enough to specialize the output format and domain without the cost or overfitting risk of full fine-tuning.

Q: Can I fine-tune this further on my own data? Yes, this adapter can be used as a starting checkpoint for continued fine-tuning. Note this may require merging first depending on your training framework.

Q: Why is the output format so strict? Each task was trained on a fixed system prompt and consistent output structure. Following the documented system prompt closely (see Quickstart above) gives the most reliable results โ€” deviating from it may produce inconsistent formatting.

Q: Does this model store or transmit my input data? No. Like any open-weight model, all inference happens locally on your own infrastructure (or wherever you deploy it) โ€” nothing is sent back to the model author.


Troubleshooting

SymptomLikely causeFix
ValueError: padding_token not setBase tokenizer has no pad tokenSet tokenizer.pad_token = tokenizer.eos_token before inference
Garbled / repeated outputWrong chat template appliedMake sure you use tokenizer.apply_chat_template, not a raw string prompt
CUDA OOM on loadInsufficient VRAMUse load_in_4bit=True (already default above) or reduce max_seq_length
Adapter loads but ignores fine-tuningBase model mismatchConfirm you loaded the exact base listed above โ€” adapters are not portable across different base models or quantizations

Related models in this suite

ModelTaskSize
icd10-coder-qwen25-7bICD-10-CM medical coding7B
snomed-mapper-qwen25-7bClinical concept mapping7B
icd10-to-drg-qwen25-1bICD-10 to DRG reimbursement1.5B
pmjay-classifier-qwen25-3bIndia PM-JAY classification3B

Full suite overview: AmareshHebbar/medical-ai-model-suite


Changelog

VersionDateNotes
v1.02026Initial release โ€” QLoRA fine-tune on 3,500 real-world rows

Citation

bibtex
@misc{medicalai2026,
  author    = {Hebbar, Amaresh},
  title     = {Medical AI Fine-tuning Suite},
  year      = {2026},
  publisher = {HuggingFace},
  url       = {https://huggingface.co/AmareshHebbar}
}

Contact

![GitHub](https://github.com/amareshhebbar) ![LinkedIn](https://www.linkedin.com/in/gvamaresh) ![Hugging Face](https://huggingface.co/AmareshHebbar)