Downloads · 30 days
8
13% of all-time downloads
karanchugh/bdc-domain-guardrail-modernbert
bdc-domain-guardrail-modernbert is a text classification model from karanchugh. Use it when you need a label for a piece of text. The card lists the license as apache-2.0.
Binary classifier for automotive service domain relevance. Determines if user messages are relevant to BDC (Business Development Center) conversations.
Downloads · 30 days
8
13% of all-time downloads
All-time downloads
62
Public
Parameters
150M
898 MB on disk
Likes
0
Public
Click a slice to open those files.
.onnx599 MB · 66%
From the Hugging Face model README
Binary classifier for automotive service domain relevance. Determines if user messages are relevant to BDC (Business Development Center) conversations.
| Metric | Value |
|---|---|
| Accuracy | 91.9% |
| Macro F1 | 0.907 |
| ALLOW Precision | 89.1% |
| ALLOW Recall | 98.6% |
| False Blocks | 1.4% (20/1397) |
| BLOCK Precision | 0.839 |
| BLOCK Recall | 0.910 |
Recommended threshold: 0.35 (optimized for minimal false blocks while maintaining high ALLOW recall)
import onnxruntime as ort
import numpy as np
from transformers import AutoTokenizer
from huggingface_hub import hf_hub_download
# Download unquantized ONNX model
onnx_path = hf_hub_download("karanchugh/bdc-domain-guardrail-modernbert", "onnx/model.onnx")
tokenizer = AutoTokenizer.from_pretrained("karanchugh/bdc-domain-guardrail-modernbert")
# Create session
session = ort.InferenceSession(onnx_path, providers=['CPUExecutionProvider'])
# Inference with optimal threshold
text = "Can I schedule an oil change?"
inputs = tokenizer(text, return_tensors="np", truncation=True, max_length=256, padding="max_length")
outputs = session.run(None, {
"input_ids": inputs["input_ids"].astype(np.int64),
"attention_mask": inputs["attention_mask"].astype(np.int64),
})
logits = outputs[0][0]
probs = np.exp(logits) / np.exp(logits).sum()
allow_prob = probs[1]
# Use threshold=0.35 for optimal guardrail performance
prediction = "ALLOW" if allow_prob > 0.35 else "BLOCK"
print(f"{prediction}: {allow_prob:.3f}")
from transformers import AutoModelForSequenceClassification, AutoTokenizer
import torch
model = AutoModelForSequenceClassification.from_pretrained("karanchugh/bdc-domain-guardrail-modernbert")
tokenizer = AutoTokenizer.from_pretrained("karanchugh/bdc-domain-guardrail-modernbert")
text = "Can I schedule an oil change?"
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=256)
with torch.no_grad():
outputs = model(**inputs)
probs = torch.softmax(outputs.logits, dim=-1)
allow_prob = probs[0][1].item()
# Use threshold=0.35 for optimal guardrail performance
prediction = "ALLOW" if allow_prob > 0.35 else "BLOCK"
print(f"{prediction}: {allow_prob:.3f}")
model.safetensors: Full merged PyTorch modelonnx/model.onnx: Unquantized ONNX model (571 MB) - recommended for productiontokenizer.json: Fast tokenizerDo NOT use default threshold of 0.5!
The model is optimized for threshold=0.35 which provides:
Using threshold=0.5 will result in 7.7% false blocks (108 blocked valid messages).
GUARDRAIL_USE_DOMAIN_MODEL=true
GUARDRAIL_RELEVANCE_THRESHOLD=0.35 # Critical: use 0.35, not 0.5!
Note: Quantized version (254 MB) showed 6% accuracy degradation and is not recommended.
This model was trained with:
Result: 81% reduction in false blocks compared to baseline (from 7.7% to 1.4%).