Downloads · 30 days
5
10% of all-time downloads
fabriceyhc/Llama-DrugDetector-8B-MFI-v2
Llama-DrugDetector-8B-MFI-v2 is a text generation model from fabriceyhc. Use it when you need the model to write or continue text. It is set up for peft. The card lists the license as llama3.1.
Llama-DrugDetector-8B-MFI-v2 is a LoRA fine-tuned model for detecting illicit drug use in clinical notes. It is based on fabriceyhc/Llama-DrugDetector-8B (8B parameters).
Downloads · 30 days
5
10% of all-time downloads
All-time downloads
51
Public
Repo size
509 MB
Likes
0
Public
Click a slice to open those files.
.pt328 MB · 53%
From the Hugging Face model README
Llama-DrugDetector-8B-MFI-v2 is a LoRA fine-tuned model for detecting illicit drug use in clinical notes. It is based on fabriceyhc/Llama-DrugDetector-8B (8B parameters).
The model performs multi-task classification, predicting:
Ranked 2nd out of 3 models in our evaluation (Macro F1: 0.876)
| Drug | F1 | Precision | Recall |
|---|---|---|---|
| Methamphetamine | 0.835 | 0.796 | 0.878 |
| Fentanyl | 0.909 | 0.909 | 0.909 |
| Injection Drug Use | 0.885 | 0.964 | 0.818 |
| Macro Average | 0.876 |
| Drug | Accuracy |
|---|---|
| Methamphetamine | 0.553 |
| Fentanyl | 0.581 |
| Injection Drug Use | 0.464 |
| Average | 0.533 |
| Model | Size | Macro F1 | Temporal Acc |
|---|---|---|---|
| Ministral-DrugDetector-14B-MFI | 14B | 0.940 | 0.704 |
| Llama-DrugDetector-8B-MFI-v2 | 8B | 0.876 | 0.533 |
| MediPhi-DrugDetector-MFI | 3.8B | 0.863 | 0.502 |
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
import torch
# Load base model
base_model = "fabriceyhc/Llama-DrugDetector-8B"
model = AutoModelForCausalLM.from_pretrained(
base_model,
torch_dtype=torch.bfloat16,
device_map="auto",
trust_remote_code=True
)
# Load LoRA adapter
model = PeftModel.from_pretrained(model, "fabriceyhc/Llama-DrugDetector-8B-MFI-v2")
# Load tokenizer
tokenizer = AutoTokenizer.from_pretrained("fabriceyhc/Llama-DrugDetector-8B-MFI-v2")
# Task instruction
task_instruction = """### Task Description:
Please carefully review the following medical note and identify illicit drug use.
**CRITICAL RULES:**
1. **Positive drug test -> ALWAYS ILLICIT** (unless in medication list)
2. **PMH/History of use -> ILLICIT** (even if historical)
3. **Substance use disorder -> ILLICIT**
4. **Patient self-reports (endorses, reports, admits) -> ILLICIT**
5. **Prescribed/medical use -> NOT ILLICIT**
**Drugs to identify:**
- **Methamphetamine**: Illicit amphetamine use (not prescribed Adderall)
- **Fentanyl**: Illicit fentanyl use (not prescribed patches/procedural)
- **Injection Drug Use**: IV drug use (IVDU, IVDA)
**Temporal Classification:**
- **Current**: Present tense, recent use, positive test
- **Historical**: Past tense, "history of", "former user"
- **Unknown**: Timeframe unclear
### Desired Format:
Methamphetamine Illicit Use: <True/False/Unknown>
Fentanyl Illicit Use: <True/False/Unknown>
Injection Drug Use: <True/False/Unknown>
Methamphetamine Temporal Status: <Current/Historical/Unknown/N/A>
Fentanyl Temporal Status: <Current/Historical/Unknown/N/A>
Injection Drug Use Temporal Status: <Current/Historical/Unknown/N/A>"""
# Example note
note_text = "Patient reports using meth daily for the past 2 weeks. Denies IV drug use."
# Format prompt
prompt = f"""{task_instruction}
### The medical note to evaluate:
{note_text}
### Answer:
"""
# Generate
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(
**inputs,
max_new_tokens=200,
do_sample=False,
pad_token_id=tokenizer.eos_token_id
)
# Decode
result = tokenizer.decode(outputs[0][inputs['input_ids'].shape[1]:], skip_special_tokens=True)
print(result)
Methamphetamine Illicit Use: True
Fentanyl Illicit Use: False
Injection Drug Use: False
Methamphetamine Temporal Status: Current
Fentanyl Temporal Status: N/A
Injection Drug Use Temporal Status: N/A
Recommended:
Not Recommended:
@misc{llama-drugdetector-8b-mfi-v2-2025,
author = {Hanna-Chang, Fabrice},
title = {Llama-DrugDetector-8B-MFI-v2},
year = {2025},
publisher = {HuggingFace},
url = {https://huggingface.co/fabriceyhc/Llama-DrugDetector-8B-MFI-v2}
}
LLAMA3.1