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/publish.py from CheezOne/pii-detector-cjk-small: direct link, hf CLI and curl.
- Browser
- Download file 3.05 kB
-
https://huggingface.co/CheezOne/pii-detector-cjk-small/resolve/main/scripts/publish.py
- Command line
-
hf download hf://CheezOne/pii-detector-cjk-small/scripts/publish.py
-
curl -L -o publish.py https://huggingface.co/CheezOne/pii-detector-cjk-small/resolve/main/scripts/publish.py
3.05 kB
| """Publish a trained model directory to the Hugging Face Hub (model repo + training scripts). | |
| Usage: HF_TOKEN=... python publish.py <model_dir> <repo_id> [--private] | |
| Uploads: weights, tokenizer, config, onnx/, README.md, eval JSONs, and scripts/ (for reproducibility). | |
| Never uploads checkpoints, data, or anything containing tokens. | |
| """ | |
| import argparse, os, re, shutil, tempfile | |
| from huggingface_hub import HfApi | |
| SCRIPTS = ["common.py", "prep_openpii.py", "gen_zh_realistic.py", "train.py", "export_onnx.py", | |
| "quant_sweep.py", "bench_redaction.py", "error_analysis.py", "make_card.py", "publish.py"] | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("model_dir"); ap.add_argument("repo_id"); ap.add_argument("--private", action="store_true") | |
| ap.add_argument("--extra", nargs="*", default=[], help="extra files to put under eval/") | |
| a = ap.parse_args() | |
| api = HfApi(token=os.environ["HF_TOKEN"]) | |
| api.create_repo(a.repo_id, repo_type="model", private=a.private, exist_ok=True) | |
| here = os.path.dirname(os.path.abspath(__file__)) | |
| with tempfile.TemporaryDirectory() as tmp: | |
| for f in os.listdir(a.model_dir): | |
| src = os.path.join(a.model_dir, f) | |
| if f in ("ckpt", "train_log.jsonl.bak") or f.startswith("."): | |
| continue | |
| if os.path.isdir(src): | |
| if f == "onnx": | |
| os.makedirs(os.path.join(tmp, "onnx")) | |
| for o in ("model.onnx", "model_quantized.onnx"): | |
| if os.path.exists(os.path.join(src, o)): | |
| shutil.copy(os.path.join(src, o), os.path.join(tmp, "onnx", o)) | |
| continue | |
| dst = os.path.join(tmp, "eval", f) if f.endswith(".json") and f.startswith(("eval", "onnx_report")) else os.path.join(tmp, f) | |
| os.makedirs(os.path.dirname(dst), exist_ok=True); shutil.copy(src, dst) | |
| os.makedirs(os.path.join(tmp, "scripts"), exist_ok=True) | |
| for s in SCRIPTS: | |
| if os.path.exists(os.path.join(here, s)): | |
| shutil.copy(os.path.join(here, s), os.path.join(tmp, "scripts", s)) | |
| for e in a.extra: | |
| os.makedirs(os.path.join(tmp, "eval"), exist_ok=True); shutil.copy(e, os.path.join(tmp, "eval", os.path.basename(e))) | |
| secret = os.environ["HF_TOKEN"].encode() | |
| for root, _, files in os.walk(tmp): # safety: refuse to upload anything that looks like a token | |
| for f in files: | |
| p = os.path.join(root, f) | |
| if os.path.getsize(p) < 5_000_000: | |
| txt = open(p, "rb").read() | |
| assert secret not in txt and not re.search(rb"hf_[A-Za-z0-9]{30,}", txt), f"token-like string in {p}" | |
| print("uploading:", sorted(os.path.relpath(os.path.join(r, f), tmp) for r, _, fs in os.walk(tmp) for f in fs)) | |
| api.upload_folder(folder_path=tmp, repo_id=a.repo_id, repo_type="model", commit_message="Release") | |
| print("https://huggingface.co/" + a.repo_id) | |
| if __name__ == "__main__": | |
| main() | |