Downloads · 30 days
3
4% of all-time downloads
Kirosama/medical-guardrail-mmbert-V4
medical-guardrail-mmbert-V4 is a text classification model from Kirosama. Use it when you need a label for a piece of text. It is set up for transformers.
This is an optimized, multi-label sequence classification model designed for medical routing and safety guardrails. It is built on top of jhu-clsp/mmBERT-base and fine-tuned for high-speed, enterprise-grade inference.
Downloads · 30 days
3
4% of all-time downloads
All-time downloads
69
Public
Parameters
308M
2.8 GB on disk
Likes
0
Public
Click a slice to open those files.
.onnx1.5 GB · 55%
From the Hugging Face model README
This is an optimized, multi-label sequence classification model designed for medical routing and safety guardrails. It is built on top of jhu-clsp/mmBERT-base and fine-tuned for high-speed, enterprise-grade inference.
This repository contains the model in three different formats to support various deployment environments:
onnx/fp32 directory.onnx/int8 directory (Recommended for CPU production).The model outputs probabilities for 6 distinct classes. In production, we route based on the following strict priority order to ensure safety:
Note on Outputs: Because this is a Multi-Label classification model, the model outputs raw logits. You must apply a Sigmoid activation function (e.g.,
torch.sigmoid()orscipy.special.expit()) to the outputs to get the final confidence probabilities. Do not use Softmax.
Because the PyTorch files are in the root directory, you can load them using standard transformers.
import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer
repo_id = "Kirosama/medical-guardrail-mmbert-V4"
# fix_mistral_regex=True silences the known upstream regex warning
tokenizer = AutoTokenizer.from_pretrained(repo_id, fix_mistral_regex=True)
model = AutoModelForSequenceClassification.from_pretrained(repo_id)
inputs = tokenizer("I have severe chest pain.", return_tensors="pt")
with torch.no_grad():
logits = model(**inputs).logits
# Apply Sigmoid to get probabilities
probabilities = torch.sigmoid(logits)[0].tolist()
To load the ONNX graph, switch from transformers to optimum and specify the subfolder.
from optimum.onnxruntime import ORTModelForSequenceClassification
from transformers import AutoTokenizer
repo_id = "Kirosama/medical-guardrail-mmbert-V4"
tokenizer = AutoTokenizer.from_pretrained(repo_id, fix_mistral_regex=True)
ort_fp32_model = ORTModelForSequenceClassification.from_pretrained(
repo_id,
subfolder="onnx/fp32"
)
This is the ultra-fast production model. You must specify both the subfolder and the custom file_name because the quantizer appends _quantized to the file.
from optimum.onnxruntime import ORTModelForSequenceClassification
from transformers import AutoTokenizer
repo_id = "Kirosama/medical-guardrail-mmbert-V4"
tokenizer = AutoTokenizer.from_pretrained(repo_id, fix_mistral_regex=True)
ort_int8_model = ORTModelForSequenceClassification.from_pretrained(
repo_id,
subfolder="onnx/int8",
file_name="model_quantized.onnx"
)