Token Classification
Transformers
ONNX
Safetensors
Transformers.js
modernbert
pii
pii-detection
ner
privacy
anonymization
redaction
de-identification
chinese
japanese
korean
cjk
mmbert
个人信息
脱敏
Eval Results (legacy)
Instructions to use CheezOne/pii-detector-cjk-small with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use CheezOne/pii-detector-cjk-small with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("token-classification", model="CheezOne/pii-detector-cjk-small")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForTokenClassification tokenizer = AutoTokenizer.from_pretrained("CheezOne/pii-detector-cjk-small") model = AutoModelForTokenClassification.from_pretrained("CheezOne/pii-detector-cjk-small", device_map="auto") - Transformers.js
How to use CheezOne/pii-detector-cjk-small with Transformers.js:
// npm i @huggingface/transformers import { pipeline } from '@huggingface/transformers'; // Allocate pipeline const pipe = await pipeline('token-classification', 'CheezOne/pii-detector-cjk-small'); - Notebooks
- Google Colab
- Kaggle
Download scripts/error_analysis.py from CheezOne/pii-detector-cjk-small: direct link, hf CLI and curl.
- Browser
- Download file 1.27 kB
-
https://huggingface.co/CheezOne/pii-detector-cjk-small/resolve/main/scripts/error_analysis.py
- Command line
-
hf download hf://CheezOne/pii-detector-cjk-small/scripts/error_analysis.py
-
curl -L -o error_analysis.py https://huggingface.co/CheezOne/pii-detector-cjk-small/resolve/main/scripts/error_analysis.py
1.27 kB
| """Per-label F1 + sample errors of a checkpoint on a test file.""" | |
| import sys, os, json, collections, torch | |
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | |
| from transformers import AutoTokenizer, AutoModelForTokenClassification | |
| from common import read_jsonl, evaluate, trim | |
| import train as T | |
| torch.set_num_threads(int(os.environ.get("THREADS", "2"))) | |
| md, test, n = sys.argv[1], sys.argv[2], int(sys.argv[3]) | |
| tok = AutoTokenizer.from_pretrained(md); model = AutoModelForTokenClassification.from_pretrained(md) | |
| ex = read_jsonl(test, n); preds = T.predict(model, tok, ex) | |
| r = evaluate(ex, preds) | |
| print(json.dumps(r["overall"])); [print(f" {k:18s} f1={v['f1']:.3f} p={v['precision']:.3f} r={v['recall']:.3f} n={v['support']}") for k, v in r["by_label"].items()] | |
| conf = collections.Counter(); shown = 0 | |
| for e, p in zip(ex, preds): | |
| t = e["text"]; g = {(*trim(t, s, x), l) for s, x, l in e["spans"]}; pp = set(p) | |
| for s, x, l in g - pp: | |
| m = [q for q in pp if q[0] < x and q[1] > s] | |
| conf[(l, m[0][2] if m else "MISSED", "exact-span" if m and (m[0][0], m[0][1]) == (s, x) else "boundary" if m else "")] += 1 | |
| if shown < 12: print(" gold", repr(t[s:x]), l, "->", [(t[a:b], c) for a, b, c in m]); shown += 1 | |
| print(conf.most_common(15)) | |