ko-pii-detector-ax-crf
Korean PII (Personally Identifiable Information) span detector โ CRF tagging head on top of skt/A.X-Encoder-base. Requires trust_remote_code=True (custom ModernBertCRFTagger architecture) and pyt-crf package.
- Github: id4thomas/ko-pii-detector
- pyt-crf package: id4thomas/pyt-crf
pip install pyt-crf
Performance
Entity-level (exact span match) on held-out test set (14,294 examples):
| metric | precision | recall | f1 |
|---|---|---|---|
| micro avg | 0.9702 | 0.9795 | 0.9748 |
| macro avg | 0.9713 | 0.9765 | 0.9738 |
Per label (f1, entity-level exact match):
| label | f1 | label | f1 |
|---|---|---|---|
| IPIN | 1.0000 | PASSPORT | 0.9769 |
| 0.9988 | ADDRESS | 0.9746 | |
| DATE | 0.9967 | SECRET | 0.9738 |
| CARD_NUMBER | 0.9957 | FRN | 0.9711 |
| CARD_EXPIRY | 0.9938 | USER_ID | 0.9703 |
| ACCOUNT_NUMBER | 0.9931 | PHONE | 0.9484 |
| ZIPCODE | 0.9908 | GENERIC_ID | 0.9269 |
| CVC | 0.9906 | DRIVER_LICENSE | 0.8566 |
| RRN | 0.9882 | ||
| PERSON | 0.9831 |
DRIVER_LICENSE/GENERIC_ID are the weakest labels (high format variance, no fixed pattern to key on). This CRF head consistently outperforms the token-classification variant (id4thomas/ko-pii-detector-ax-tokenclf) across labels, likely from the transition constraints stabilizing span boundaries.
Full precision/recall per label, head-to-head comparison: ko-pii-detector docs/performance.md
Dataset
Trained on BCCard/pii-masking-openpii-finance with additional noise injection (typos, spacing/format variants, obfuscation, partial-value references, distractor IDs, etc. โ see docs/noise.md) to make the model robust to real-world noisy input.
18 span labels:
| label | description |
|---|---|
| PERSON | full name |
| RRN | resident registration number (Korea) |
| FRN | foreign registration number |
| CARD_NUMBER | credit/debit card PAN |
| ACCOUNT_NUMBER | bank account number |
| SECRET | auth secret (password / API key / token) |
| USER_ID | online member ID |
| email address | |
| PHONE | phone number (mobile / landline) |
| PASSPORT | passport number |
| DRIVER_LICENSE | driver's license number |
| GENERIC_ID | generic identifier (no KO counterpart) |
| ADDRESS | address (city / street / building) |
| ZIPCODE | postal code |
| DATE | date / time |
| CARD_EXPIRY | card expiry date |
| CVC | card verification code |
| IPIN | I-PIN number |
Usage Example
import torch
from transformers import AutoModel, AutoTokenizer
# Load tokenizer, model (custom architecture -> trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained("id4thomas/ko-pii-detector-ax-crf", use_fast=True, trust_remote_code=True)
model = AutoModel.from_pretrained("id4thomas/ko-pii-detector-ax-crf", trust_remote_code=True)
model.eval()
id2label = model.config.id2label
# predict
text = "๋ฌธ์์ฌํญ์ 010-1234-5678 ๋๋ hong@example.com ์ผ๋ก ์ฐ๋ฝ ์ฃผ์ธ์."
enc = tokenizer(text, return_tensors="pt", return_offsets_mapping=True)
offsets = enc.pop("offset_mapping")[0].tolist()
with torch.no_grad():
pred_ids = model(**enc, decode=True).predictions[0].tolist() # CRF-decoded tag ids
# merge BIO-tagged tokens into entity spans
entities, cur = [], None
for pred_id, (start, end) in zip(pred_ids, offsets):
if start == end:
continue
tag = id2label.get(pred_id, "O")
if tag == "O":
cur = None
continue
prefix, _, label = tag.partition("-")
if prefix == "B" or cur is None or cur["label"] != label:
cur = {"label": label, "start": start, "end": end}
entities.append(cur)
else:
cur["end"] = end
for ent in entities:
ent["value"] = text[ent["start"]:ent["end"]]
print(ent)
# {'label': 'PHONE', 'start': 6, 'end': 19, 'value': '010-1234-5678'}
# {'label': 'EMAIL', 'start': 23, 'end': 39, 'value': 'hong@example.com'}
More Examples (per label)
One example per label from dataset's held-out validataion
| label | text | predicted entities |
|---|---|---|
| PERSON | ์ค๊ณ ์ฐจ ํ ๋ถ ๊ธ๋ฆฌ ์ธํ ์๊ตฌ๊ถ ์ ์ฒญ - ์ ์ฒญ์ธ ์์์ฐ, ๋ฉดํ๋ฒํธ 64-23-318617-41, ์ฌ์ ์ ์ฉ๋ฑ๊ธ ์์น. | PERSON: ์์์ฐ ยท DRIVER_LICENSE: 64-23-318617-41 |
| RRN | ๊ฐ์กฑ ํฉ์ฐ ์ค์ ๋ฑ๋ก ์์ฒญ: ๋ณธ์ธ 670827-1922483, ๋ฐฐ์ฐ์ 930826-6089963, ํฉ์ฐ ๊ธฐ์ค์ผ 2023๋ 6์ 18์ผ, ํฉ์ฐ ์ค์ 3,400,000์. | RRN: 670827-1922483 ยท FRN: 930826-6089963 ยท DATE: 2023๋ 6์ 18์ผ |
| FRN | ์ด์ฒด ํ๋ ์ํฅ ์ฌ์ฌ์ ์ ๋ถ ํ์ธ์ด ์ถ๊ฐ๋ก ํ์ํฉ๋๋ค. ์ธ๊ตญ์ธ๋ฑ๋ก๋ฒํธ 000609-8628264์ ์ฌ์ง์ฆ๋ช ์๋ฅผ ์ฑ์ผ๋ก ์ ์ถํด ์ฃผ์ธ์. ์ฌ์ฌ๋ฒํธ RV-2210. | FRN: 000609-8628264 |
| CARD_NUMBER | ์ถ๊ฐ ์๋ฅ๋ก๋ 1993HP@tutanota.com์ผ๋ก ์ ์ก๋ AX8F9I3KEY์ GMHFUPB2OC ์ฌ๋ณธ์ด ํ์ํ๋ฉฐ, ์ด๋ฅผ ์ ๊ณตํ์ง ์์ ๊ฒฝ์ฐ ์ธ์ก๊ณต์ ๊ธ์ก์ด 2200047020154130๋งํผ ๊ฐ์ํ ์ ์์ต๋๋ค. | EMAIL: 1993HP@tutanota.com ยท GENERIC_ID: AX8F9I3KEY ยท DRIVER_LICENSE: GMHFUPB2OC ยท CARD_NUMBER: 2200047020154130 |
| ACCOUNT_NUMBER | ์๋ ํ์๋น ์๋์ด์ฒด๋ฅผ ๊ฑธ๋ ค๊ณ ํฉ๋๋ค. ์ถ๊ธ ๊ณ์ข 247-23-769052, ๋งค์ 5์ผ, ๊ธ์ก 420,000์. | ACCOUNT_NUMBER: 247-23-769052 |
| SECRET | ๋ชจ๋ฐ์ผ OTP ์ฌ๋ฑ๋ก ์ค์ ๋๋ค. ๊ณ์ pzmmgtx, ์์ ๋น๋ฐ๋ฒํธ QJ#qhsLRko70, ์ค๋ฅ ์ฝ๋ AU-77. | USER_ID: pzmmgtx ยท SECRET: QJ#qhsLRko70 |
| USER_ID | ์ฐ๊ธ ์กฐํ ์๋น์ค ๊ฐ์ ํ์ธ ๋ฉ์ผ์ ๋๋ค. ์์ด๋ mbllxmb.4, ์ด๊ธฐ ๋น๋ฐ๋ฒํธ dZq70t2fmd0H, ๊ฐ์ ์ผ 2059-07-07. | USER_ID: mbllxmb.4 ยท SECRET: dZq70t2fmd0H ยท DATE: 2059-07-07 |
| yang Moheb ๋๊ป, ๊ทํ์ ํ๋ณด์ ๋ฒค์น๋งํน ์ ์๋ 0 ์ ์ด๋ฉฐ, ์์ธ ๋ด์ฉ์ ๋ฌธ์ธ์ฐ@gmail.com ๋ก ์ก๋ถ๋๋ฆฌ๊ฒ ์ต๋๋ค. | PERSON: Moheb ยท EMAIL: ๋ฌธ์ธ์ฐ@gmail.com | |
| PHONE | ํฅ๋ฏธ ์ฐ์ ๋, ... ๋ด๋น์ ์ฐ๋ฝ์ฒ: (88).0410.3736 ... ์น์ธ์: ๋ผ๋ ๋ถ์๋ | PERSON: ํฅ๋ฏธ ์ฐ์ ยท PHONE: (88).0410.3736 ยท PERSON: ๋ผ๋ ๋ถ์๋ |
| PASSPORT | ์ ๋ฐ ์น๋ฌด์ ๊ธ์ฌ ๊ณ์ข ๊ฐ์ค ์๋ฅ - ์น๋ฌด์ ๊น์์ฒ , ์ฌ๊ถ๋ฒํธ F818J7636, ์น์ ๊ณ์ฝ์ ์ฌ๋ณธ, ๊ฐ์ค ์ง์ ํญ๋ง์ . | PERSON: ๊น์์ฒ ยท PASSPORT: F818J7636 |
| DRIVER_LICENSE | ์ ์ฒญ์๋ ๊ธฐ@hotmail.com ๋ก ๋ณด๋ด์๊ณ , ํ์ ์๋ฅ๋ก๋ VHIO4UYEIC ๊ณผ 1VHIE1OCT3์ด ํฌํจ๋ฉ๋๋ค. | EMAIL: ๊ธฐ@hotmail.com ยท GENERIC_ID: VHIO4UYEIC ยท DRIVER_LICENSE: 1VHIE1OCT3 |
| GENERIC_ID | ๋ฏธ์ฒญ๊ตฌ ๋ณดํ๊ธ ์๋ด๋ฌธ: ๊ณ์ฝ ์๋ณ๋ฒํธ FC9XLY8KJ5 ๊ธฐ์ค ๋ฏธ์ฒญ๊ตฌ ์ค์ ๋ณดํ๊ธ 127,400์์ด ํ์ธ๋ฉ๋๋ค. ์ฑ์์ ์ฒญ๊ตฌํ์ธ์. | GENERIC_ID: FC9XLY8KJ5 |
| ADDRESS | ๋ฐฐ์ก ์ค๋ฅ ๋ณด์ ์๋ด: ์ค๋ฐฐ์ก์ง ์ ์ฃผ๋ ํด๋จ๊ตฐ ๋ ธํ๋ 519-32 ๊ฐ๋๋ฆฌ์ํํธ 121๋ 1364ํธ (์ฐํธ๋ฒํธ 04362)๋ก ๋ฐ์ก๋ ์นด๋๊ฐ ํ์๋์์ผ๋ฉฐ, ... | ADDRESS: ์ ์ฃผ๋ ํด๋จ๊ตฐ ๋ ธํ๋ 519-32 ๊ฐ๋๋ฆฌ์ํํธ 121๋ 1364ํธ ยท ZIPCODE: 04362 |
| ZIPCODE | ์ ๊ท ์ ์ฒญ ์์์๋ ๊ฑฐ์ฃผ ์ฃผ์๊ฐ ํ์ํฉ๋๋ค. ์: ์ฌํ๋ก 50 ๋ฒ์ง, 30140 ์ฐํธ๋ฒํธ, ๋์ ๊ด์ญ์ ์ํ1๋ ์ํ1๋ ์. | ADDRESS: ์ฌํ๋ก 50 ยท ZIPCODE: 30140 ยท ADDRESS: ๋์ ๊ด์ญ์ ์ํ1๋ ์ํ1๋ |
| DATE | ์๋ ํ์ธ์ ๊ตฐ ๋ฆผ๋, ... ๋ ์ง: 25/12/1998, ์ฅ์: 40th Division Road 482, ์ฐ๋ฝ์ฒ: 003-556 3130. | PERSON: ๋ฆผ ยท PERSON: ์์ฑ ยท DATE: 25/12/1998 ยท ADDRESS: 40th Division Road 482 ยท PHONE: 003-556 3130 |
| CARD_EXPIRY | ๋ฉค๋ฒ์ญ ์๋ ๊ฐฑ์ ์ ํด์งํด ์ฃผ์ธ์. ๋ฑ๋ก ์นด๋๋ 4395952462642202์ด๊ณ ์ ํจ๊ธฐ๊ฐ 05/30, CVC 461๊น์ง ํ์ธํด ๋๋ ธ์ต๋๋ค. | CARD_NUMBER: 4395952462642202 ยท CARD_EXPIRY: 05/30 ยท CVC: 461 |
| CVC | ๊ธด๊ธ ์ ์ง ์์ฒญ! ๋ฐฉ๊ธ ํผ์ฑ ์ฌ์ดํธ์ ์นด๋๋ฒํธ 5126587179360798์ ์ ํจ๊ธฐ๊ฐ 03/26, CVC 704๊น์ง ์ ๋ ฅํด ๋ฒ๋ ธ์ต๋๋ค. | CARD_NUMBER: 5126587179360798 ยท CARD_EXPIRY: 03/26 ยท CVC: 704 |
| IPIN | ๊ตฌ์ธ ์ฌ์ดํธ ์ด๋ ฅ์ ๊ณต๊ฐ ์ค์ ๋ณ๊ฒฝ์ ์์ดํ 2938510213123 ์ฌ์ธ์ฆ ํ ๊ฐ๋ฅํฉ๋๋ค. | IPIN: 2938510213123 |
- Downloads last month
- 16
Model tree for id4thomas/ko-pii-detector-ax-crf
Base model
skt/A.X-Encoder-base