腾讯安全玄武实验室 Hide-and-Seek (HaS) 隐私保护文本生成模型(中/英),底模 BLOOM,约 820M 参数。
本仓库在 昇腾 Ascend 910 (torch_npu) 上完成推理适配,固定使用 npu:0,全程仅使用昇腾 NPU 硬件后端。
SecurityXuanwuLab/HaS-820mBloomForCausalLM(hidden_size=1536, n_layer=24, n_head=16, vocab_size=46145, torch_dtype=float16)hide(敏感实体匿名化改写)+ seek(根据改写结果还原原始含义)npu:0;PyTorch 2.9.0 + torch_npu 2.9.0.post1| 任务 | 说明 |
|---|---|
hide | 对输入文本做敏感实体匿名化改写(如人名、品牌、手机型号) |
seek | hide 之后再根据改写前后的文本还原原始含义(完整链路) |
torch.npu.is_available() == Truerequirements.txt权重默认缓存到 ./model_weights/SecurityXuanwuLab__HaS-820m/,启动时优先加载本地缓存,未命中才从
hf-mirror.com 镜像自动下载(huggingface.co 直连超时)。
export HF_ENDPOINT=https://hf-mirror.compython3 inference.py --text "张伟用苹果(iPhone 13)换了一箱好吃的苹果。"完整链路(hide + seek):
python3 inference.py --text "张伟用苹果(iPhone 13)换了一箱好吃的苹果。" --task seekuvicorn inference:app --host 0.0.0.0 --port 8101调用:
# hide(默认)
curl -s -X POST http://127.0.0.1:8101/predict \
-H "Content-Type: application/json" \
-d '{"text":"张伟用苹果(iPhone 13)换了一箱好吃的苹果。"}'
# seek 全链路
curl -s -X POST http://127.0.0.1:8101/predict \
-H "Content-Type: application/json" \
-d '{"text":"张伟用苹果(iPhone 13)换了一箱好吃的苹果。","task":"seek"}'返回 JSON:
{
"model": "SecurityXuanwuLab/HaS-820m",
"device": "npu:0",
"task": "hide",
"input_text": "张伟用苹果(iPhone 13)换了一箱好吃的苹果。",
"hidden_text": "……"
}GenerationConfig(max_new_tokens=int(len(input_ids[0])*1.3), do_sample=False, num_beams=3, repetition_penalty=5.0)GenerationConfig(max_new_tokens=int(len(input_ids[0])*1.3), do_sample=False, num_beams=3)num_beams=1, do_sample=False),并在结果中标注 beam_fallback: true。has-820m-npu/
├── inference.py # CLI + FastAPI 双模式入口
├── README.md
├── requirements.txt
├── .gitignore # 排除 model_weights/ logs/ __pycache__/
├── model_weights/ # 权重缓存(不入库)
├── logs/ # 运行日志 / ASCEND 运行路径
└── assets/ # 截图