1. 模型简介
基于 CoRoM (Context-aware Robust Model) 的中文电商领域句子嵌入模型,基于 BERT-base 架构,用于电商场景的语义相似度和检索任务。
2. 昇腾 NPU 适配结果
| 指标 | 值 |
|---|
| Cosine Similarity | 0.999992 |
| Max Abs Error | 0.008105 |
| 平均延迟 | 6.96ms |
| 输出维度 | (1, T, 768) |
| 推理精度 | float32 |
| 设备 | Ascend 910B4 |
3. 环境要求
| 组件 | 版本 |
|---|
| CANN | 8.5.1 |
| torch_npu | 2.9.0.post1 |
| PyTorch | 2.9.0 |
| Python | 3.11 |
| transformers | latest |
| modelscope | latest |
4. 快速使用
export ASCEND_HOME_PATH=/usr/local/Ascend/cann
export LD_LIBRARY_PATH=/usr/local/Ascend/cann/lib64:$LD_LIBRARY_PATH
python inference.py
python evaluate.py
5. 推理输出证据
Model: iic/nlp_corom_sentence-embedding_chinese-base-ecom
Device: npu:0
Output shape: [1, 25, 768]
Output sample: [0.3923669755458832, -0.1256464123725891, -0.12140969187021255, 0.31653329730033875, 0.42105892300605774]
Latency: 6.96ms
--- CPU vs NPU 精度对比 ---
Cosine Similarity: 0.999992
Max Abs Error: 0.008105
SUCCESS
6. CPU vs NPU 精度对比
| 指标 | CPU (float32) | NPU (float32) | 误差 |
|---|
| Cosine Similarity | 基准 | 0.999992 | < 0.00001 |
| Max Abs Error | - | 0.008105 | - |
| 输出维度 | (1, 25, 768) | (1, 25, 768) | 一致 |
7. 模型结构
- Backbone: BERT-base (12 layers)
- Hidden Size: 768
- Attention Heads: 12
- Max Position: 512
- Vocab Size: 21128
- Pooler: first_token_transform