Instructions to use japan-opendata/ja-pii-ner-v1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use japan-opendata/ja-pii-ner-v1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("token-classification", model="japan-opendata/ja-pii-ner-v1")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForTokenClassification tokenizer = AutoTokenizer.from_pretrained("japan-opendata/ja-pii-ner-v1") model = AutoModelForTokenClassification.from_pretrained("japan-opendata/ja-pii-ner-v1", device_map="auto") - Transformers.js
How to use japan-opendata/ja-pii-ner-v1 with Transformers.js:
// npm i @huggingface/transformers import { pipeline } from '@huggingface/transformers'; // Allocate pipeline const pipe = await pipeline('token-classification', 'japan-opendata/ja-pii-ner-v1'); - Notebooks
- Google Colab
- Kaggle
Japan Open Data Lab の「日本語AIモデル部品シリーズ」の1つです。シリーズ一覧は サイトのモデルページ と プロフィール にあります。
ja-pii-ner-v1 — Japanese PII Detection (Token Classification)
A small (111M parameters) encoder model that detects 18 types of personally identifiable information (PII) in Japanese text and returns exact character spans. CPU-friendly, ONNX included, Apache 2.0. No real personal data was used for training or evaluation — all data is synthetic.
日本語の文章から18種類の個人情報を文字位置つきで検出する小規模モデルです。 学習と評価に実在の個人情報は使っていません(すべて合成データ)。
English summary
Detects 18 types of personally identifiable information in Japanese text and returns exact character spans. On a held-out test of 10,001 documents (43,064 spans), micro F1 was 0.9770, with zero false positives on 2,068 PII-free documents. The FP32 ONNX model matches PyTorch exactly and runs at about 224 ms per document on CPU. All training and evaluation data is synthetic — no real personal data. Apache 2.0.
What it does## What it does
Given Japanese text, the model returns character spans for these labels:
PERSON, ORGANIZATION, ADDRESS, POSTAL_CODE, PHONE, EMAIL, DATE_OF_BIRTH, MY_NUMBER, BANK_ACCOUNT, CREDIT_CARD, DRIVER_LICENSE, PASSPORT, HEALTH_INSURANCE, EMPLOYEE_ID, IP_ADDRESS, URL_PERSONAL, USERNAME, SECRET
The model only detects. Masking/replacement is up to you — see redact.py
in this repository for a ready-made helper.
Quick start
With transformers:
from transformers import pipeline
ner = pipeline("token-classification",
model="japan-opendata/ja-pii-ner-v1",
aggregation_strategy="simple")
print(ner("担当は山田太郎(電話 090-1234-5678)です。"))
For production use (span merging, long-document chunking, masking), use the
bundled single-file helper — no external calls, only transformers + torch:
from redact import redact
redact("連絡先は taro.yamada@example.com です")
# -> '連絡先は <EMAIL> です'
With ONNX Runtime only (no PyTorch), see examples/onnx_example.py.
For Microsoft Presidio, see presidio_recognizer.py: a custom recognizer
that returns character offsets directly from the model, avoiding the
spaCy-tokenization alignment problems of the stock TransformersNlpEngine
for Japanese.
Evaluation (measured, exact-span match)
Test set: the full test split of nvidia/Nemotron-PII-Japan converted to character spans (10,001 documents, 43,064 gold spans), plus a separately generated no-PII set of 2,068 documents. Threshold-free BIO argmax decoding; no tuning was done against the test set.
Overall:
| Metric | Value |
|---|---|
| Precision (micro) | 0.9965 |
| Recall (micro) | 0.9582 |
| F1 (micro) | 0.9770 |
| False-positive rate on no-PII documents | 0.0000 (0 / 2,068 documents) |
Per label (Precision / Recall / F1):
| Label | P | R | F1 |
|---|---|---|---|
| PERSON | 0.9987 | 0.9577 | 0.9778 |
| ORGANIZATION | 0.9918 | 0.8790 | 0.9320 |
| ADDRESS | 0.9919 | 0.9610 | 0.9762 |
| POSTAL_CODE | 1.0000 | 1.0000 | 1.0000 |
| PHONE | 0.9951 | 0.9562 | 0.9753 |
| 1.0000 | 1.0000 | 1.0000 | |
| DATE_OF_BIRTH | 1.0000 | 1.0000 | 1.0000 |
| MY_NUMBER | 1.0000 | 1.0000 | 1.0000 |
| BANK_ACCOUNT | 1.0000 | 1.0000 | 1.0000 |
| CREDIT_CARD | 1.0000 | 1.0000 | 1.0000 |
| HEALTH_INSURANCE | 1.0000 | 1.0000 | 1.0000 |
| EMPLOYEE_ID | 0.9992 | 0.9990 | 0.9991 |
| IP_ADDRESS | 0.9984 | 0.9984 | 0.9984 |
| URL_PERSONAL | 1.0000 | 1.0000 | 1.0000 |
| USERNAME | 0.9989 | 0.9978 | 0.9984 |
| SECRET | 0.9620 | 0.8000 | 0.8736 |
DRIVER_LICENSE and PASSPORT have no gold spans in this test set (the source dataset does not contain them; they are supplied only by our synthetic data), so they are not evaluated by the numbers above.
CPU speed (Intel i7-11700F, 200 documents, mean per document):
| Runtime | ms/doc | docs/sec |
|---|---|---|
| PyTorch (fp32) | 813.96 | 1.23 |
| ONNX (fp32) | 224.16 | 4.46 |
The ONNX fp32 export reproduces the PyTorch model exactly on the full test set (identical TP/FP/FN on every label).
INT8 note: dynamic INT8 quantization was measured (188 MB, 122 ms/doc) but is not shipped in v1 — micro F1 dropped to 0.8988, with large recall losses on numeric/symbol pattern labels (IP_ADDRESS, URL_PERSONAL, SECRET, BANK_ACCOUNT). Static INT8 quantization degraded the model entirely. fp32 is the supported configuration.
Comparison on the same test set
az225/privacy-masker-ja-pii-ner-30m was evaluated on the identical test set. Only 3 of its labels map 1-to-1 to ours (PERSON, ORGANIZATION, ADDRESS; 24,149 gold spans), so the comparison is restricted to those:
| Model | P | R | F1 (3 labels) |
|---|---|---|---|
| ja-pii-ner-v1 | 0.9947 | 0.9325 | 0.9626 |
| az225/privacy-masker-ja-pii-ner-30m | 0.6343 | 0.6809 | 0.6568 |
Read this with care: the label definitions differ. az225 splits place names into a separate LOCATION label; counting LOCATION as ADDRESS raises its ADDRESS recall to 0.9821. Its PERSON recall (0.9961) is higher than ours (0.9577). The gap above is partly a definitions gap, not only a quality gap.
Training data
- nvidia/Nemotron-PII-Japan (CC BY 4.0, NVIDIA / Elith): 79,998 training documents converted from the published parquet files.
- 25,000 synthetic documents generated by the lab from public parts data: place names from Japan Post postal-code data and the Digital Agency address registry (PDL 1.0), organization names from the National Tax Agency corporate-number registry (PDL 1.0). Generation code and sources are published with the companion dataset.
Base model: tohoku-nlp/bert-base-japanese-v3. Trained for 3 epochs on 104,998 documents.
Limitations
- Trained on synthetic data. Performance on real documents will differ; the numbers above are not a guarantee of complete detection.
- ORGANIZATION recall (0.8790) and SECRET recall (0.8000) are the weakest points. Organization names that look like person names, and secrets in unusual formats, are the typical misses.
- DRIVER_LICENSE and PASSPORT are not covered by the public test set and are therefore unevaluated (see above).
- The source dataset is known to contain some missing gold labels; a small part of the measured false positives may be unlabeled true PII.
- Inputs longer than 512 tokens are truncated by the model itself; use the
chunking in
redact.pyfor long documents.
License
Apache 2.0. The training data licenses are listed above; the base model is distributed under its own terms by its authors.
Links
- Model page on the lab site (JA): https://jpopendata.jp/models/ja-pii-ner-v1/
- Downloads last month
- 113
Model tree for japan-opendata/ja-pii-ner-v1
Base model
tohoku-nlp/bert-base-japanese-v3Dataset used to train japan-opendata/ja-pii-ner-v1
Space using japan-opendata/ja-pii-ner-v1 1
Evaluation results
- Span F1 (micro, exact match) on Nemotron-PII-Japan (test split, converted)self-reported0.977
- Span Precision (micro) on Nemotron-PII-Japan (test split, converted)self-reported0.997
- Span Recall (micro) on Nemotron-PII-Japan (test split, converted)self-reported0.958
