BERT(Bidirectional Encoder Representations from Transformers)是 Google 开源的 预训练语言模型,本变体为 large-cased-wwm。本仓库交付其在昇腾 NPU 上的掩码语言 (fill-mask / MLM)推理方案。
| 属性 | 说明 |
|---|---|
| 模型 | google-bert/bert-large-cased-whole-word-masking |
| 变体 | large-cased-wwm |
| 任务 | 掩码语言建模(预测 [MASK] 位置的 token) |
| 输入 | 含 [MASK] 的文本 |
| 输出 | top-k 候选 token 及概率 |
| 下载源 | modelscope.cn |
| 推理精度 | fp32 |
该模型已在 ModelScope 发布,推理脚本会自动从 modelscope.cn 下载权重并缓存到本地。
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/python inference.py "The capital of France is [MASK]." --device npu首次运行会通过 ModelScope 自动下载权重;也可显式指定来源:
python inference.py "I like to [MASK] books." --model /data/.cache/models/google-bert/bert-large-cased-whole-word-masking --device npupython inference.py "I like to [MASK] books." --top-k 10 --device npu
python inference.py --file sentences.txt --device npu # 每行一句python inference.py "Paris is the capital of [MASK]." --out result.txt --device npupython -m uvicorn main:app --host 0.0.0.0 --port 8000curl http://localhost:8000/health
curl -X POST http://localhost:8000/predict \
-H "Content-Type: application/json" \
-d '{"text": "The capital of France is [MASK].", "top_k": 5}'$ python inference.py "The capital of France is [MASK]." --device npu$ python3 inference.py "The capital of France is [MASK]." --device npu
[info] variant=large-cased-wwm model=google-bert/bert-large-cased-whole-word-masking device=npu
input: The capital of France is [MASK].
filled: the capital of france is paris.
mask#1: paris (0.41), lille (0.07), lyon (0.06), marseille (0.04), tours (0.03)
见 assets/README.md,交付前需放入三张截图:
agent_workflow.png、npu_device_call.png、model_result.png。
NPU 昇腾 bert 掩码语言 fill-mask NLP large-cased-wwm