|
| 1 | +<!--Copyright 2026 The HuggingFace Team. All rights reserved. |
| 2 | +
|
| 3 | +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
| 4 | +the License. You may obtain a copy of the License at |
| 5 | +
|
| 6 | +http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +
|
| 8 | +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
| 9 | +an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 10 | +specific language governing permissions and limitations under the License. |
| 11 | +
|
| 12 | +⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be |
| 13 | +rendered properly in your Markdown viewer. |
| 14 | +
|
| 15 | +--> |
| 16 | +*This model was released on 2026-04-22 and added to Hugging Face Transformers on 2026-04-22.* |
| 17 | + |
| 18 | +<div style="float: right;"> |
| 19 | + <div class="flex flex-wrap space-x-1"> |
| 20 | + <img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white"> |
| 21 | + </div> |
| 22 | +</div> |
| 23 | + |
| 24 | +# OpenAI Privacy Filter |
| 25 | + |
| 26 | +OpenAI Privacy Filter is a bidirectional token-classification model for personally identifiable information (PII) detection and masking in text. It is intended for high-throughput data sanitization workflows where teams need a model that they can run on-premises that is fast, context-aware, and tunable. |
| 27 | + |
| 28 | +OpenAI Privacy Filter is pretrained autoregressively to arrive at a checkpoint with similar architecture to gpt-oss, albeit of a smaller size. We then converted that checkpoint into a bidirectional token classifier over a privacy label taxonomy, and post-trained with a supervised classification loss. (For architecture details about gpt-oss, please see the gpt-oss model card.) Instead of generating text token-by-token, this model labels an input sequence in a single forward pass, then decodes coherent spans with a constrained Viterbi procedure. For each input token, the model predicts a probability distribution over the label taxonomy which consists of 8 output categories described below. |
| 29 | + |
| 30 | +Highlights: |
| 31 | + |
| 32 | +- Permissive Apache 2.0 license: ideal for experimentation, customization, and commercial deployment. |
| 33 | +- Small size: Runs in a web browser or on a laptop – 1.5B parameters total and 50M active parameters. |
| 34 | +- Fine-tunable: Adapt the model to specific data distributions through easy and data efficient finetuning. |
| 35 | +- Long-context: 128,000-token context window enables processing long text with high throughput and no chunking. |
| 36 | +- Runtime control: configure precision/recall tradeoffs and detected span lengths through preset operating points. |
| 37 | + |
| 38 | +The example below demonstrates how to detect privacy-sensitive tokens with [`Pipeline`] or the [`AutoModelForTokenClassification`] class. |
| 39 | + |
| 40 | +<hfoptions id="usage"> |
| 41 | +<hfoption id="Pipeline"> |
| 42 | + |
| 43 | +```py |
| 44 | +from transformers import pipeline |
| 45 | + |
| 46 | +classifier = pipeline( |
| 47 | + task="token-classification", |
| 48 | + model="openai/privacy-filter", |
| 49 | +) |
| 50 | +classifier("My name is Alice Smith") |
| 51 | +``` |
| 52 | + |
| 53 | +</hfoption> |
| 54 | +<hfoption id="AutoModelForTokenClassification"> |
| 55 | + |
| 56 | +```py |
| 57 | +import torch |
| 58 | +from transformers import AutoModelForTokenClassification, AutoTokenizer |
| 59 | + |
| 60 | +tokenizer = AutoTokenizer.from_pretrained("openai/privacy-filter") |
| 61 | +model = AutoModelForTokenClassification.from_pretrained("openai/privacy-filter", device_map="auto") |
| 62 | + |
| 63 | +inputs = tokenizer("My name is Alice Smith", return_tensors="pt").to(model.device) |
| 64 | + |
| 65 | +with torch.no_grad(): |
| 66 | + outputs = model(**inputs) |
| 67 | + |
| 68 | +predicted_token_class_ids = outputs.logits.argmax(dim=-1) |
| 69 | +predicted_token_classes = [model.config.id2label[token_id.item()] for token_id in predicted_token_class_ids[0]] |
| 70 | +print(predicted_token_classes) |
| 71 | +``` |
| 72 | + |
| 73 | +</hfoption> |
| 74 | +</hfoptions> |
| 75 | + |
| 76 | +- Developed by: OpenAI |
| 77 | +- Funded by: OpenAI |
| 78 | +- Shared by: OpenAI |
| 79 | +- Model type: Bidirectional token classification model for privacy span detection |
| 80 | +- Language(s): Primarily English; selected multilingual robustness evaluation reported |
| 81 | +- License: [Apache 2.0](LICENSE) |
| 82 | + |
| 83 | +- Source repository: https://github.com/openai/privacy-filter |
| 84 | +- Model weights: https://huggingface.co/openai/privacy-filter |
| 85 | +- Demo: https://huggingface.co/spaces/openai/privacy-filter |
| 86 | + |
| 87 | +## Resources |
| 88 | + |
| 89 | +- [Token classification task guide](../tasks/token_classification) |
| 90 | + |
| 91 | +## OpenAIPrivacyFilterConfig |
| 92 | + |
| 93 | +[[autodoc]] OpenAIPrivacyFilterConfig |
| 94 | + |
| 95 | +## OpenAIPrivacyFilterModel |
| 96 | + |
| 97 | +[[autodoc]] OpenAIPrivacyFilterModel |
| 98 | + - forward |
| 99 | + |
| 100 | +## OpenAIPrivacyFilterForTokenClassification |
| 101 | + |
| 102 | +[[autodoc]] OpenAIPrivacyFilterForTokenClassification |
| 103 | + - forward |
0 commit comments