FP16 ONNX export of
openai/privacy-filter
for efficient inference with ONNX Runtime. The model detects eight categories of personally identifiable information (PII) in text and returns BIOES-tagged token spans.
The exported graph has dynamic batch and sequence dimensions, and has been validated against the original PyTorch implementation with 100% argmax agreement on reference prompts.
For GPU inference, substitute
onnxruntime-gpu
for
onnxruntime
.
Usage
Minimal example
from huggingface_hub import snapshot_download
from transformers import AutoTokenizer
import onnxruntime as ort
import numpy as np
import json
repo = "yasserrmd/privacy-filter-ONNX"
local = snapshot_download(repo)
tokenizer = AutoTokenizer.from_pretrained(local)
session = ort.InferenceSession(
f"{local}/onnx/model_fp16.onnx",
providers=["CPUExecutionProvider"], # or ["CUDAExecutionProvider"] for GPU
)
withopen(f"{local}/config.json") as f:
id2label = {int(k): v for k, v in json.load(f)["id2label"].items()}
text = "Hi, I'm Alice Smith, email [email protected]."
enc = tokenizer(text, return_tensors="np", add_special_tokens=False)
logits = session.run(None, {
"input_ids": enc["input_ids"].astype(np.int64),
"attention_mask": enc["attention_mask"].astype(np.int64),
})[0]
labels = [id2label[int(i)] for i in logits[0].argmax(-1)]
tokens = tokenizer.convert_ids_to_tokens(enc["input_ids"][0])
for tok, lbl inzip(tokens, labels):
if lbl != "O":
print(f"{tok:<20}{lbl}")
Complete usage with span decoding
The raw model output is per-token logits over 33 BIOES classes. For coherent spans, decode the logits with a constrained Viterbi pass using the biases in
viterbi_calibration.json
. A reference implementation is included in
examples/detect.py
in the export project; the essential steps are:
Tokenize the input with
return_offsets_mapping=True
to recover character positions.
Run the ONNX session to obtain logits of shape
[1, seq_len, 33]
.
Run Viterbi decoding over the 33 labels with legal BIOES transitions.
Group the resulting label sequence into spans and map token indices back to character spans via the offsets.
The
viterbi_calibration.json
file holds six transition-bias parameters under
operating_points.default.biases
that control the precision/recall trade-off. The defaults in this file are zeroed and match the reference implementation's
default
operating point.
Input and output shapes
Tensor
Shape
Dtype
input_ids
(input)
[batch, sequence]
int64
attention_mask
(input)
[batch, sequence]
int64
logits
(output)
[batch, sequence, 33]
float32
Both
batch
and
sequence
are dynamic at runtime.
Export notes
Exported with
torch.onnx.export(dynamo=True)
from
transformers>=5.6.0.dev0
and
torch>=2.6
.
The 128-expert top-4 MoE blocks in each decoder layer were rewritten to a dense-weighted-sum form to produce an ONNX-traceable graph while preserving reference arithmetic, including the clamped-SwiGLU activation (
alpha=1.702
,
limit=7.0
) and the post-experts scaling.
The router linear remains in FP32 for numerical stability; all other weights are FP16.
Parity validated against the PyTorch reference: max logit difference on the order of 1e-4, argmax agreement 100% across the standard evaluation prompts.
privacy-filter-ONNX huggingface.co is an AI model on huggingface.co that provides privacy-filter-ONNX's model effect (), which can be used instantly with this yasserrmd privacy-filter-ONNX model. huggingface.co supports a free trial of the privacy-filter-ONNX model, and also provides paid use of the privacy-filter-ONNX. Support call privacy-filter-ONNX model through api, including Node.js, Python, http.
privacy-filter-ONNX huggingface.co is an online trial and call api platform, which integrates privacy-filter-ONNX's modeling effects, including api services, and provides a free online trial of privacy-filter-ONNX, you can try privacy-filter-ONNX online for free by clicking the link below.
yasserrmd privacy-filter-ONNX online free url in huggingface.co:
privacy-filter-ONNX is an open source model from GitHub that offers a free installation service, and any user can find privacy-filter-ONNX on GitHub to install. At the same time, huggingface.co provides the effect of privacy-filter-ONNX install, users can directly use privacy-filter-ONNX installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
privacy-filter-ONNX install url in huggingface.co: