A fine-tuned medical Named Entity Recognition (NER) model based on Llama-3.2-3B-Instruct using LoRA (Low-Rank Adaptation) for efficient parameter tuning. This model is specialized for extracting medical entities and relationships from biomedical texts.
Model Details
Model Description
This model fine-tunes Llama-3.2-3B-Instruct for medical Named Entity Recognition across three specialized tasks:
Chemical Extraction: Identifies drug and chemical compound names
Disease Extraction: Identifies disease and medical condition names
Relationship Extraction: Identifies chemical-disease interactions (which chemicals influence which diseases)
The model was trained on a curated dataset derived from the ChemProt corpus with 2,994 high-quality medical text samples, achieving balanced performance across all three tasks.
Developed by: Alberto Clemente (@albyos)
Model type: Causal Language Model with LoRA adapters
Language(s): English (medical/biomedical domain)
License: Llama 3.2 Community License
Finetuned from model: meta-llama/Llama-3.2-3B-Instruct
This model is designed for extracting structured medical information from unstructured biomedical texts, including:
Research papers and clinical studies
Medical literature reviews
Drug interaction documentation
Disease characterization documents
Input format:
The following article contains technical terms including diseases, drugs and chemicals.
Create a list only of the [chemicals/diseases/influences] mentioned.
[MEDICAL TEXT]
List of extracted [chemicals/diseases/influences]:
Output format:
For chemicals/diseases: Bullet list of entities
For relationships: Pipe-separated pairs (chemical | disease)
Downstream Use
This model can be integrated into:
Medical literature mining pipelines
Drug discovery workflows
Clinical decision support systems
Pharmacovigilance systems
Biomedical knowledge graph construction
Out-of-Scope Use
This model is NOT suitable for:
Clinical diagnosis or treatment recommendations
Patient-facing medical advice
Real-time critical healthcare decisions
Languages other than English
Non-medical domain NER tasks
Important: This model is for research and information extraction purposes only. It should not be used as a substitute for professional medical judgment.
Bias, Risks, and Limitations
Known Limitations
Domain Specificity: Trained on scientific/biomedical literature; may not perform well on clinical notes or patient-facing text
Entity Coverage: Limited to chemicals, diseases, and their relationships; doesn't extract other medical entities (procedures, anatomy, etc.)
Training Data Bias: Reflects patterns in ChemProt corpus; may not generalize to all medical subdomains
Hallucination Risk: As with all LLMs, may occasionally generate plausible but incorrect entities
Format Sensitivity: Performance depends on using the exact prompt format from training
Recommendations
Always validate extracted entities against authoritative medical databases (ChEBI, MeSH, UMLS)
Use in conjunction with human expert review for high-stakes applications
Monitor for false positives (hallucinated entities) and false negatives (missed entities)
Implement confidence thresholding based on your use case requirements
Consider ensemble methods with other biomedical NER tools (e.g., BioMistral, PubMedBERT)
How to Get Started with the Model
python
1from transformers import AutoTokenizer, AutoModelForCausalLM
2from peft import PeftModel
3import torch
45# Load base model and tokenizer6base_model_id ="meta-llama/Llama-3.2-3B-Instruct"7model = AutoModelForCausalLM.from_pretrained(8 base_model_id,9 torch_dtype=torch.float16,10 device_map="auto"11)12tokenizer = AutoTokenizer.from_pretrained(base_model_id)1314# Load LoRA adapter15adapter_model_id ="albyos/llama3-medical-ner-lora-{timestamp}"# Replace with actual model ID16model = PeftModel.from_pretrained(model, adapter_model_id)1718# Format prompt (example for chemical extraction)19prompt ="""<|begin_of_text|><|start_header_id|>system<|end_header_id|>
2021You are a medical NER expert specialized in extracting entities from biomedical texts.
22Extract entities EXACTLY as they appear in the text.
2324CRITICAL RULES:
251. Return ONLY entities found verbatim in the article
262. Preserve exact formatting: hyphens, capitalization, special characters
273. Extract complete multi-word terms
284. For relationships: use format 'chemical NAME | disease NAME'
2930OUTPUT FORMAT:
31- One entity per line with leading dash
32- No explanations or additional text<|eot_id|><|start_header_id|>user<|end_header_id|>
3334The following article contains technical terms including diseases, drugs and chemicals.
35Create a list only of the chemicals mentioned.
3637Aspirin and ibuprofen are commonly used to treat inflammation. Recent studies show
38that metformin may reduce the risk of type-2 diabetes complications.
3940List of extracted chemicals:
41<|eot_id|><|start_header_id|>assistant<|end_header_id|>
4243"""4445# Generate46inputs = tokenizer(prompt, return_tensors="pt").to(model.device)47outputs = model.generate(48**inputs,49 max_new_tokens=128,50 do_sample=False,51 temperature=1.0,52 repetition_penalty=1.15,53)54response = tokenizer.decode(outputs[0], skip_special_tokens=True)5556# Extract assistant response57if"<|start_header_id|>assistant<|end_header_id|>"in response:58 result = response.split("<|start_header_id|>assistant<|end_header_id|>")[-1].strip()59print(result)
Training Details
Training Data
Dataset: Custom medical NER dataset derived from ChemProt corpus
Total samples: 2,994 (after cleaning and deduplication)
Source: Biomedical literature abstracts
Tasks: Chemical extraction, disease extraction, relationship extraction
Split: 80% train (2,397), 10% validation (298), 10% test (299)
Quality: 99.8% retention rate, 0 empty completions, stratified by task
Data Characteristics (from exploration analysis):
Unique chemicals: 1,578 entities
Unique diseases: 2,199 entities
Vocabulary size: 13,710 unique words
Prompt length: Median 1,357 characters (195 words), range 345-4,018 chars
Note: LoRA fine-tuning is significantly more efficient than full model training, using only ~1.5% of trainable parameters and ~3 hours of compute time vs. days/weeks for full training.
Technical Specifications
Model Architecture and Objective
Base Architecture: Llama-3.2-3B-Instruct (Meta AI)
Parameters: 3 billion (base model)
Architecture: Transformer decoder with grouped-query attention
Context length: 8,192 tokens
Vocabulary: 128,000 tokens (SentencePiece)
LoRA Adaptation:
Trainable parameters: ~47 million (~1.5% of total)
LoRA rank: 16 (low-rank decomposition dimension)
Adapter placement: All attention and MLP projection layers
Training objective: Next-token prediction (causal language modeling)
Compute Infrastructure
Hardware
Training: NVIDIA A100 80GB GPU
Memory: 80GB VRAM (4-bit quantization reduces to ~7GB usage)
CPU: High-memory instance (for data preprocessing)
Software
Framework: Hugging Face Transformers 4.x
Training: Hugging Face Trainer with PEFT (Parameter-Efficient Fine-Tuning)
If you use this model in your research, please cite:
BibTeX:
bibtex
1@misc{clemente2025medical-ner-lora,
2 author = {Clemente, Alberto},
3 title = {Llama-3.2-3B Medical NER with LoRA},
4 year = {2025},
5 publisher = {Hugging Face},
6 journal = {Hugging Face Model Hub},
7 howpublished = {\url{https://huggingface.co/albyos/llama3-medical-ner-lora}},
8}