Downloads · 30 days
14
7% of all-time downloads
Lekhansh/bioclinical-treatment-detector
bioclinical-treatment-detector is a token classification model from Lekhansh. Use it when you need labels on individual words, such as names. The card lists the license as apache-2.0.
This model is a specialized token classification system designed to detect treatment-related information in addiction medicine clinical notes. It is fine-tuned from thomas-sounack/BioClinical-ModernBERT-large to ident…
Downloads · 30 days
14
7% of all-time downloads
All-time downloads
205
Public
Parameters
396M
4.8 GB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors1.6 GB · 100%
From the Hugging Face model README
This model is a specialized token classification system designed to detect treatment-related information in addiction medicine clinical notes. It is fine-tuned from thomas-sounack/BioClinical-ModernBERT-large to identify current and future treatment plans, medication decisions, and therapeutic interventions while preserving patient privacy.
Key Purpose: Prevent information leakage about locus of care and medication decisions when training clinical decision support systems in addiction medicine. This model enables researchers to mask sensitive treatment information before using clinical data for machine learning applications.
O: Outside treatment informationB-TREATMENT: Beginning of treatment entityI-TREATMENT: Inside treatment entityThe model achieves strong performance on treatment detection:
These metrics reflect the model's ability to accurately identify treatment-related spans while minimizing false positives and negatives.
from transformers import AutoTokenizer, AutoModelForTokenClassification
import torch
# Load model and tokenizer
model_name = "Lekhansh/bioclinical-treatment-detector"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForTokenClassification.from_pretrained(model_name)
# Example clinical text
text = """
Treatment Plan:
1. Start Tablet Buprenorphine 8mg twice daily
2. Continue counseling sessions weekly
3. Follow up in outpatient clinic after 2 weeks
"""
# Tokenize and predict
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512,
return_offsets_mapping=True)
outputs = model(**{k: v for k, v in inputs.items() if k != 'offset_mapping'})
# Get predictions
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
predicted_labels = torch.argmax(predictions, dim=-1)[0]
# Map predictions to text spans
id2label = {0: "O", 1: "B-TREATMENT", 2: "I-TREATMENT"}
offset_mapping = inputs["offset_mapping"][0]
treatment_spans = []
current_span = None
for i, (label_id, (start, end)) in enumerate(zip(predicted_labels, offset_mapping)):
if start == 0 and end == 0: # Skip special tokens
continue
label = id2label[label_id.item()]
if label == "B-TREATMENT":
if current_span:
treatment_spans.append(current_span)
current_span = {"start": start.item(), "end": end.item()}
elif label == "I-TREATMENT" and current_span:
current_span["end"] = end.item()
else:
if current_span:
treatment_spans.append(current_span)
current_span = None
if current_span:
treatment_spans.append(current_span)
# Extract treatment text
for span in treatment_spans:
treatment_text = text[span["start"]:span["end"]]
print(f"Treatment detected: '{treatment_text}'")
For more sophisticated inference with confidence scores and batch processing, see the complete example:
import torch
import numpy as np
from transformers import AutoTokenizer, AutoModelForTokenClassification
class TreatmentDetector:
def __init__(self, model_name):
self.tokenizer = AutoTokenizer.from_pretrained(model_name)
self.model = AutoModelForTokenClassification.from_pretrained(model_name)
self.model.eval()
self.id2label = {0: "O", 1: "B-TREATMENT", 2: "I-TREATMENT"}
def detect_treatments(self, text, confidence_threshold=0.5):
encoding = self.tokenizer(
text, return_tensors="pt", truncation=True, max_length=8192,
return_offsets_mapping=True, padding=True
)
with torch.no_grad():
outputs = self.model(**{k: v for k, v in encoding.items() if k != 'offset_mapping'})
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
predicted_labels = torch.argmax(predictions, dim=-1)[0]
confidence_scores = torch.max(predictions, dim=-1)[0][0]
treatment_spans = []
current_span = None
for i, (label_id, confidence, (start, end)) in enumerate(
zip(predicted_labels, confidence_scores, encoding["offset_mapping"][0])
):
if start == 0 and end == 0:
continue
label = self.id2label[label_id.item()]
conf = confidence.item()
if label == "B-TREATMENT" and conf > confidence_threshold:
if current_span:
treatment_spans.append(current_span)
current_span = {
"start": start.item(), "end": end.item(),
"confidence": conf
}
elif label == "I-TREATMENT" and current_span and conf > confidence_threshold:
current_span["end"] = end.item()
current_span["confidence"] = (current_span["confidence"] + conf) / 2
else:
if current_span:
treatment_spans.append(current_span)
current_span = None
if current_span:
treatment_spans.append(current_span)
# Add text content
for span in treatment_spans:
span["text"] = text[span["start"]:span["end"]]
return treatment_spans
# Usage
detector = TreatmentDetector("Lekhansh/bioclinical-treatment-detector")
treatments = detector.detect_treatments(clinical_text)
If you use this model in your research, please cite:
@misc{bioclinical-treatment-detector,
title={Addiction Medicine Treatment Information Detector for Clinical AI},
author={[Lekhansh S, Prakrithi SN]},
year={2025},
publisher={Hugging Face},
howpublished={\url{https://huggingface.co/Lekhansh/bioclinical-treatment-detector}}
}
For questions about this model or its applications in privacy-preserving clinical AI, please contact [[email protected]].
This model is released under the Apache 2.0 License. Please ensure compliance with all applicable healthcare privacy regulations when using this model.