Token Classification
Transformers
Safetensors
Korean
English
openai_privacy_filter
ner
pii
privacy
pii-masking
korean
finance
bioes
viterbi
mixture-of-experts
Instructions to use BCCard/MoAI-Privacy-Filter with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use BCCard/MoAI-Privacy-Filter with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("token-classification", model="BCCard/MoAI-Privacy-Filter")# Load model directly from transformers import AutoTokenizer, AutoModelForTokenClassification tokenizer = AutoTokenizer.from_pretrained("BCCard/MoAI-Privacy-Filter") model = AutoModelForTokenClassification.from_pretrained("BCCard/MoAI-Privacy-Filter", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update
Browse files
README.md
CHANGED
|
@@ -26,9 +26,7 @@ metrics:
|
|
| 26 |
---
|
| 27 |
|
| 28 |
# 1. Overview
|
| 29 |
-
A Korean/English **PII detection model for the finance domain**, built by full fine-tuning
|
| 30 |
-
[`openai/privacy-filter`](https://huggingface.co/openai/privacy-filter) (1.4B MoE, 50M active) on synthetic finance-domain PII data. It tags **18 PII entity types** (73 BIOES classes) at token level and is intended as the **NER layer of a multi-layer PII-masking gateway** in front of LLM services —
|
| 31 |
-
behind a regex backstop for fully structured identifiers, never as a standalone compliance guarantee.
|
| 32 |
|
| 33 |
On held-out validation it reaches **strict span-F1 0.956 (ko) / 0.969 (en)**. On an independent, adversarially-hardened Golden Set it holds **0.944 (ko) / 0.907 (en)** with **masking coverage 0.996 (ko) / 0.998 (en)** — i.e. ≥99.5% of gold PII characters are covered by predicted spans.
|
| 34 |
|
|
@@ -36,14 +34,14 @@ On held-out validation it reaches **strict span-F1 0.956 (ko) / 0.969 (en)**. On
|
|
| 36 |
* **Base model**: [`openai/privacy-filter`](https://huggingface.co/openai/privacy-filter) — 1.4B-parameter MoE (128 experts, 50M active), 8 layers, hidden 640, bidirectional banded attention (±128), o200k tokenizer
|
| 37 |
* **Domain / Language**: Finance (BC Card — cards, accounts, national IDs, customer service text) / Korean + English
|
| 38 |
* **Task**: Token classification (BIOES) → character-offset PII spans → masking
|
| 39 |
-
* **Labels (18)**: `PERSON, RRN, FRN, CARD_NUMBER, ACCOUNT_NUMBER, SECRET, USER_ID, EMAIL, PHONE, PASSPORT, DRIVER_LICENSE, GENERIC_ID, ADDRESS, ZIPCODE, DATE, CARD_EXPIRY, CVC, IPIN`
|
| 40 |
* **Method**: Full fine-tuning (all parameters incl. experts & router) with a re-initialized 73-class head (rows copied from the base head by taxonomy mapping)
|
| 41 |
-
* **Decoding**:
|
| 42 |
* **Format**: BF16 (attention `sinks` kept FP32), single safetensors + tokenizer + label taxonomy + Viterbi calibration sidecar
|
| 43 |
-
* **Sequence length**: trained on sequences ≤768 tokens — chunk longer inputs
|
| 44 |
-
* **Intended use**
|
| 45 |
-
|
| 46 |
-
|
| 47 |
|
| 48 |
## 1.2. Label Taxonomy (N=18)
|
| 49 |
The 18 labels re-map the upstream ai4privacy source labels to the granularity a Korean financial masking policy needs - merging fragments into single spans (`GIVENNAME`/`SURNAME` → `PERSON`, `CITY`/`STREET`/`BUILDINGNUM` → `ADDRESS`) and adding Korea-specific classes absent upstream (`RRN`, `FRN`, `IPIN`, `CARD_EXPIRY`, `CVC`, `SECRET`). `data source` records the row-source buckets in which each label occurs: `ko` means `openpii-1.5m-ko`, `en` means `openpii-1.5m-en`, and `domain` means locally synthesized rows.
|
|
@@ -52,7 +50,7 @@ The 18 labels re-map the upstream ai4privacy source labels to the granularity a
|
|
| 52 |
|-------|-------------|-------------|
|
| 53 |
| `PERSON` | full name (surname + given, single span) | ko, en, domain |
|
| 54 |
| `RRN` | resident registration number (Korea) | ko, domain |
|
| 55 |
-
| `FRN` | foreign registration number | domain |
|
| 56 |
| `CARD_NUMBER` | credit/debit card PAN | ko, en, domain |
|
| 57 |
| `ACCOUNT_NUMBER` | bank account number | ko, domain |
|
| 58 |
| `SECRET` | auth secret (password / API key / token) | ko, domain |
|
|
@@ -61,15 +59,15 @@ The 18 labels re-map the upstream ai4privacy source labels to the granularity a
|
|
| 61 |
| `PHONE` | phone number (mobile / landline) | ko, en, domain |
|
| 62 |
| `PASSPORT` | passport number | ko, en, domain |
|
| 63 |
| `DRIVER_LICENSE` | driver's license number | ko, en, domain |
|
| 64 |
-
| `GENERIC_ID` | generic identifier
|
| 65 |
| `ADDRESS` | address (city / street / building, single span) | ko, en, domain |
|
| 66 |
| `ZIPCODE` | postal code | ko, en, domain |
|
| 67 |
| `DATE` | date / time | ko, en, domain |
|
| 68 |
| `CARD_EXPIRY` | card expiry date | domain |
|
| 69 |
| `CVC` | card verification code | domain |
|
| 70 |
-
| `IPIN` | I-PIN number | domain |
|
| 71 |
|
| 72 |
-
Each entity type has `B-`, `I-`, `E-` and `S-` boundary classes, plus the background class `O`. This yields 73 output classes.
|
| 73 |
|
| 74 |
## 1.3. Usage
|
| 75 |
|
|
@@ -87,31 +85,40 @@ enc = tokenizer(text, return_offsets_mapping=True, add_special_tokens=False, ret
|
|
| 87 |
offsets = enc.pop("offset_mapping")[0].tolist()
|
| 88 |
|
| 89 |
with torch.no_grad():
|
| 90 |
-
logits = model(**enc).logits
|
| 91 |
-
|
| 92 |
-
#
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
```
|
| 101 |
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
>
|
| 105 |
-
> `viterbi_calibration.json` follows the upstream operating-point schema: its six transition biases
|
| 106 |
-
> shift the precision↔recall trade-off at deploy time without retraining (all `0.0` = neutral).
|
| 107 |
|
| 108 |
## 1.4. Training Data
|
| 109 |
| Dataset | Role | Size |
|
| 110 |
|---------|------|------|
|
| 111 |
-
| (Public) [BCCard/pii-masking-openpii-finance](https://huggingface.co/datasets/BCCard/pii-masking-openpii-finance) (v2) | Training /
|
| 112 |
-
| (Private) BCCard/pii-masking-openpii-finance-test (v2) | Golden Set (release
|
| 113 |
|
| 114 |
-
* Sources: curated Korean subset of `ai4privacy/pii-masking-openpii-1.5m` (label taxonomy remapped, name spans merged & naturalized) + finance-domain synthetic templates + **~30% English replay** (forgetting guard)
|
| 115 |
* Hard-example design baked into v2: surface-similar non-PII decoys (FP suppression), label-confusion pairs in one sentence (RRN↔FRN, DRIVER_LICENSE↔GENERIC_ID), weak-context true PII (FN suppression), long-span address boundary variants
|
| 116 |
* All values are synthetic; validity-pattern collisions with real identifiers are removed at generation time (e.g. card numbers are forced to fail Luhn)
|
| 117 |
|
|
@@ -124,7 +131,7 @@ with torch.no_grad():
|
|
| 124 |
| Batch | effective 16 (per-device × world × accum), fixed across hardware layouts |
|
| 125 |
| LR / scheduler | 1e-4 / linear decay, warmup 3% |
|
| 126 |
| Optimizer | AdamW (fused), weight decay 0.0, max_grad_norm 1.0 |
|
| 127 |
-
| Epochs | 5 — best checkpoint by validation span micro-F1,
|
| 128 |
| Precision | FP32 master weights + BF16 autocast; MoE router/experts explicitly kept FP32 during compute |
|
| 129 |
| Hardware | 1× NVIDIA H100 (~5h) |
|
| 130 |
|
|
@@ -146,7 +153,6 @@ with torch.no_grad():
|
|
| 146 |
|
| 147 |
## 2.2. Results
|
| 148 |
### `validation` dataset
|
| 149 |
-
|
| 150 |
| Metric | v2 model / v2 validation |
|
| 151 |
|---|---:|
|
| 152 |
| micro F1 | 0.9599 |
|
|
@@ -159,6 +165,8 @@ with torch.no_grad():
|
|
| 159 |
| **ko masking coverage** | **0.9987** |
|
| 160 |
| **en masking coverage** | **0.9965** |
|
| 161 |
|
|
|
|
|
|
|
| 162 |
* These values were measured post-hoc by running the exported `final-bf16` artifact over all 14,543 v2 validation rows (ko 10,460 / en 4,083) through the deployment-equivalent chain: constrained Viterbi, actual tokenizer character offsets and whitespace refinement.
|
| 163 |
* Overall micro F1 and masking coverage pool all ko/en spans or characters before scoring. Overall macro F1 pools per-label TP/FP/FN across both languages and then averages the 18 label F1 values.
|
| 164 |
* Character coverage counts are ko **482,861 / 483,488** and en **264,979 / 265,898** gold PII characters.
|
|
@@ -186,7 +194,7 @@ Independently generated Golden Set — deliberately harder than validation: weak
|
|
| 186 |
* Label-swap errors (e.g. en `ACCOUNT_NUMBER` predicted as `GENERIC_ID`/`CARD_NUMBER`) keep **coverage 1.0** — the value is still masked; only the label name is wrong
|
| 187 |
|
| 188 |
## 2.3. Reading the numbers
|
| 189 |
-
Strict exact-match span-F1 on an adversarial test is a deliberately harsh score: a one-character boundary miss or a swapped label counts as a full error. For
|
| 190 |
|
| 191 |
<br>
|
| 192 |
|
|
@@ -201,7 +209,7 @@ Strict exact-match span-F1 on an adversarial test is a deliberately harsh score:
|
|
| 201 |
<br>
|
| 202 |
|
| 203 |
# 3. Future Work
|
| 204 |
-
* **v3 data**
|
| 205 |
* **Operating point** - recall-leaning Viterbi transition biases tuned on validation or a dedicated calibration set without Golden Set feedback
|
| 206 |
* **Serving** - target-hardware latency, throughput and memory benchmarks for the separately published INT8 weight-only ONNX artifact
|
| 207 |
|
|
|
|
| 26 |
---
|
| 27 |
|
| 28 |
# 1. Overview
|
| 29 |
+
A Korean/English **PII detection model for the finance domain**, built by full fine-tuning [`openai/privacy-filter`](https://huggingface.co/openai/privacy-filter) (1.4B MoE, 50M active) on synthetic finance-domain PII data. It tags **18 PII entity types** (73 BIOES classes) at token level and is intended as the **NER layer of a multi-layer PII-masking gateway** in front of LLM services, as well as a PII detection component for offline privacy review and audit workflows.
|
|
|
|
|
|
|
| 30 |
|
| 31 |
On held-out validation it reaches **strict span-F1 0.956 (ko) / 0.969 (en)**. On an independent, adversarially-hardened Golden Set it holds **0.944 (ko) / 0.907 (en)** with **masking coverage 0.996 (ko) / 0.998 (en)** — i.e. ≥99.5% of gold PII characters are covered by predicted spans.
|
| 32 |
|
|
|
|
| 34 |
* **Base model**: [`openai/privacy-filter`](https://huggingface.co/openai/privacy-filter) — 1.4B-parameter MoE (128 experts, 50M active), 8 layers, hidden 640, bidirectional banded attention (±128), o200k tokenizer
|
| 35 |
* **Domain / Language**: Finance (BC Card — cards, accounts, national IDs, customer service text) / Korean + English
|
| 36 |
* **Task**: Token classification (BIOES) → character-offset PII spans → masking
|
| 37 |
+
* **Labels (18)**: `PERSON`, `RRN`, `FRN`, `CARD_NUMBER`, `ACCOUNT_NUMBER`, `SECRET`, `USER_ID`, `EMAIL`, `PHONE`, `PASSPORT`, `DRIVER_LICENSE`, `GENERIC_ID`, `ADDRESS`, `ZIPCODE`, `DATE`, `CARD_EXPIRY`, `CVC`, `IPIN`
|
| 38 |
* **Method**: Full fine-tuning (all parameters incl. experts & router) with a re-initialized 73-class head (rows copied from the base head by taxonomy mapping)
|
| 39 |
+
* **Decoding**: constrained BIOES Viterbi (not per-token argmax) + whitespace span refinement — the bundled `viterbi_calibration.json` exposes precision↔recall operating-point biases without retraining
|
| 40 |
* **Format**: BF16 (attention `sinks` kept FP32), single safetensors + tokenizer + label taxonomy + Viterbi calibration sidecar
|
| 41 |
+
* **Sequence length**: trained on sequences ≤ 768 tokens — chunk longer inputs
|
| 42 |
+
* **Intended use**:
|
| 43 |
+
1. In-house PII masking gateway (detect → mask before text reaches an LLM)
|
| 44 |
+
2. Offline privacy review and audit support (PII discovery in stored text, logs and documents)
|
| 45 |
|
| 46 |
## 1.2. Label Taxonomy (N=18)
|
| 47 |
The 18 labels re-map the upstream ai4privacy source labels to the granularity a Korean financial masking policy needs - merging fragments into single spans (`GIVENNAME`/`SURNAME` → `PERSON`, `CITY`/`STREET`/`BUILDINGNUM` → `ADDRESS`) and adding Korea-specific classes absent upstream (`RRN`, `FRN`, `IPIN`, `CARD_EXPIRY`, `CVC`, `SECRET`). `data source` records the row-source buckets in which each label occurs: `ko` means `openpii-1.5m-ko`, `en` means `openpii-1.5m-en`, and `domain` means locally synthesized rows.
|
|
|
|
| 50 |
|-------|-------------|-------------|
|
| 51 |
| `PERSON` | full name (surname + given, single span) | ko, en, domain |
|
| 52 |
| `RRN` | resident registration number (Korea) | ko, domain |
|
| 53 |
+
| `FRN` | foreign registration number (Korea) | domain |
|
| 54 |
| `CARD_NUMBER` | credit/debit card PAN | ko, en, domain |
|
| 55 |
| `ACCOUNT_NUMBER` | bank account number | ko, domain |
|
| 56 |
| `SECRET` | auth secret (password / API key / token) | ko, domain |
|
|
|
|
| 59 |
| `PHONE` | phone number (mobile / landline) | ko, en, domain |
|
| 60 |
| `PASSPORT` | passport number | ko, en, domain |
|
| 61 |
| `DRIVER_LICENSE` | driver's license number | ko, en, domain |
|
| 62 |
+
| `GENERIC_ID` | generic identifier without a more specific taxonomy class | ko, en, domain |
|
| 63 |
| `ADDRESS` | address (city / street / building, single span) | ko, en, domain |
|
| 64 |
| `ZIPCODE` | postal code | ko, en, domain |
|
| 65 |
| `DATE` | date / time | ko, en, domain |
|
| 66 |
| `CARD_EXPIRY` | card expiry date | domain |
|
| 67 |
| `CVC` | card verification code | domain |
|
| 68 |
+
| `IPIN` | I-PIN number (Korea only) | domain |
|
| 69 |
|
| 70 |
+
Each entity type has `B-`, `I-`, `E-` and `S-` boundary classes, plus the background class `O`. This yields 73 output classes.
|
| 71 |
|
| 72 |
## 1.3. Usage
|
| 73 |
|
|
|
|
| 85 |
offsets = enc.pop("offset_mapping")[0].tolist()
|
| 86 |
|
| 87 |
with torch.no_grad():
|
| 88 |
+
logits = model(**enc).logits.float() # [B, T, 73]
|
| 89 |
+
|
| 90 |
+
# Decode logits[0] with constrained BIOES Viterbi and map token tags through offsets.
|
| 91 |
+
print(tuple(logits.shape))
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
Raw logits shape and decoded spans:
|
| 95 |
+
|
| 96 |
+
```text
|
| 97 |
+
(1, 30, 73)
|
| 98 |
+
[
|
| 99 |
+
{'start': 3, 'end': 6, 'label': 'PERSON'},
|
| 100 |
+
{'start': 8, 'end': 22, 'label': 'RRN'},
|
| 101 |
+
{'start': 26, 'end': 39, 'label': 'PHONE'}
|
| 102 |
+
]
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
The offsets use Python's half-open character interval `[start, end)`. Masking is downstream policy logic. For example, the spans above can produce:
|
| 106 |
+
|
| 107 |
+
```text
|
| 108 |
+
고객 [PERSON]님([RRN])께서 [PHONE]로 연락 요청하셨습니다.
|
| 109 |
```
|
| 110 |
|
| 111 |
+
For batches, enable right padding and pass only `input_ids` and `attention_mask` to the model. `offset_mapping` stays outside the model and is used only to map decoded token tags back to the original text. Convert logits to FP32 before constrained Viterbi decoding, as shown above.
|
| 112 |
+
|
| 113 |
+
> **Decoding note** - this model, like its base, is trained with a supervised token-level BIOES classification objective and is intended to be decoded with **constrained Viterbi** over the BIOES transition grammar, not independent per-token argmax. Independent argmax can emit invalid BIOES sequences and is not the decoding path used for the reported metrics. The bundled `viterbi_calibration.json` follows the upstream operating-point schema. Its six transition biases allow users to adjust the precision-recall trade-off without retraining. All-zero biases mean no additive operating-point adjustment; BIOES transition constraints remain active.
|
|
|
|
|
|
|
| 114 |
|
| 115 |
## 1.4. Training Data
|
| 116 |
| Dataset | Role | Size |
|
| 117 |
|---------|------|------|
|
| 118 |
+
| (Public) [BCCard/pii-masking-openpii-finance](https://huggingface.co/datasets/BCCard/pii-masking-openpii-finance) (v2) | Training / Validation | ~58.5k train rows · ~14.5k validation rows |
|
| 119 |
+
| (Private) BCCard/pii-masking-openpii-finance-test (v2) | Golden Set (release evaluation; not used for training/tuning) | 2,000 rows (ko 1,460 / en 540) |
|
| 120 |
|
| 121 |
+
* Sources: curated Korean subset of `ai4privacy/pii-masking-openpii-1.5m` (label taxonomy remapped, name spans merged & naturalized) + finance-domain synthetic templates + **~30% English replay** (catastrophic forgetting guard)
|
| 122 |
* Hard-example design baked into v2: surface-similar non-PII decoys (FP suppression), label-confusion pairs in one sentence (RRN↔FRN, DRIVER_LICENSE↔GENERIC_ID), weak-context true PII (FN suppression), long-span address boundary variants
|
| 123 |
* All values are synthetic; validity-pattern collisions with real identifiers are removed at generation time (e.g. card numbers are forced to fail Luhn)
|
| 124 |
|
|
|
|
| 131 |
| Batch | effective 16 (per-device × world × accum), fixed across hardware layouts |
|
| 132 |
| LR / scheduler | 1e-4 / linear decay, warmup 3% |
|
| 133 |
| Optimizer | AdamW (fused), weight decay 0.0, max_grad_norm 1.0 |
|
| 134 |
+
| Epochs | 5 — best checkpoint by validation span micro-F1, decoded with the same constrained Viterbi as deployment |
|
| 135 |
| Precision | FP32 master weights + BF16 autocast; MoE router/experts explicitly kept FP32 during compute |
|
| 136 |
| Hardware | 1× NVIDIA H100 (~5h) |
|
| 137 |
|
|
|
|
| 153 |
|
| 154 |
## 2.2. Results
|
| 155 |
### `validation` dataset
|
|
|
|
| 156 |
| Metric | v2 model / v2 validation |
|
| 157 |
|---|---:|
|
| 158 |
| micro F1 | 0.9599 |
|
|
|
|
| 165 |
| **ko masking coverage** | **0.9987** |
|
| 166 |
| **en masking coverage** | **0.9965** |
|
| 167 |
|
| 168 |
+
**Observed masking coverage is 99.8% overall and at least 99.6% in both the Korean and English validation slices.** This leakage-oriented metric is reported as a diagnostic rather than a release gate.
|
| 169 |
+
|
| 170 |
* These values were measured post-hoc by running the exported `final-bf16` artifact over all 14,543 v2 validation rows (ko 10,460 / en 4,083) through the deployment-equivalent chain: constrained Viterbi, actual tokenizer character offsets and whitespace refinement.
|
| 171 |
* Overall micro F1 and masking coverage pool all ko/en spans or characters before scoring. Overall macro F1 pools per-label TP/FP/FN across both languages and then averages the 18 label F1 values.
|
| 172 |
* Character coverage counts are ko **482,861 / 483,488** and en **264,979 / 265,898** gold PII characters.
|
|
|
|
| 194 |
* Label-swap errors (e.g. en `ACCOUNT_NUMBER` predicted as `GENERIC_ID`/`CARD_NUMBER`) keep **coverage 1.0** — the value is still masked; only the label name is wrong
|
| 195 |
|
| 196 |
## 2.3. Reading the numbers
|
| 197 |
+
Strict exact-match span-F1 on an adversarial test is a deliberately harsh score: a one-character boundary miss or a swapped label counts as a full error. For diagnosing character-level exposure, masking coverage is the direct diagnostic metric: **0.44% (ko) / 0.16% (en) of gold PII characters uncovered**, concentrated in weak-context person names.
|
| 198 |
|
| 199 |
<br>
|
| 200 |
|
|
|
|
| 209 |
<br>
|
| 210 |
|
| 211 |
# 3. Future Work
|
| 212 |
+
* **v3 data enhancements** - weak-context person-name hard positives, more diverse cue words for alphanumeric IDs, and privacy-safe failure collection from shadow-mode operation
|
| 213 |
* **Operating point** - recall-leaning Viterbi transition biases tuned on validation or a dedicated calibration set without Golden Set feedback
|
| 214 |
* **Serving** - target-hardware latency, throughput and memory benchmarks for the separately published INT8 weight-only ONNX artifact
|
| 215 |
|