weixin_72661020/nlp_structbert_address-matching_chinese_base
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

iic/nlp_structbert_address-matching_chinese_base 昇腾 NPU 适配

1. 简介

本模型是基于 StructBERT 的中文地址相似度匹配模型,输入两条中文地址,输出它们之间的相似度类别:

  • exact_match: 完全匹配(同一地址)
  • partial_match: 部分匹配(同一地址的不同粒度描述)
  • not_match: 不匹配(不同地址)

该模型为 BERT-based 文本分类模型(BertForSequenceClassification),不是生成式模型,适用于地址标准化、地址去重等场景。

基本信息

属性值
模型名称iic/nlp_structbert_address-matching_chinese_base
模型架构BertForSequenceClassification
参数量~110M
框架PyTorch / transformers
语言中文
权重获取ModelScope
数据集ccks2021-addrsim
参考精度 (Acc)83.86

获取地址

  • 权重下载地址(ModelScope):https://modelscope.cn/models/iic/nlp_structbert_address-matching_chinese_base

2. 验证环境

组件版本
NPUAscend910
PyTorch2.9.0
torch_npu2.9.0.post1
transformers4.24.0+
Python3.11.14

3. 启动推理

由于该模型为 BERT-based 分类模型,直接使用 transformers 库加载推理,无需 vLLM 服务化部署。

import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification

device = "npu:0" if torch.npu.is_available() else "cpu"
tokenizer = AutoTokenizer.from_pretrained("iic/nlp_structbert_address-matching_chinese_base")
model = AutoModelForSequenceClassification.from_pretrained("iic/nlp_structbert_address-matching_chinese_base").to(device)
model.eval()

# 推理示例
inputs = tokenizer("地址A", "地址B", return_tensors="pt", truncation=True, max_length=512)
inputs = {k: v.to(device) for k, v in inputs.items()}
with torch.no_grad():
    outputs = model(**inputs)

4. Smoke 验证

python3 inference.py

验证结果示例:

地址1: 北京航空航天大学逸夫楼
地址2: 北京航空航天大学图书馆
结果: {'exact_match': 0.0050, 'not_match': 0.1498, 'partial_match': 0.8452}
预测: partial_match (置信度: 0.8452)

5. 性能参考

指标数值
测试设备Ascend910
单次推理平均耗时7.5ms
测试样本数10
总测试时间0.075s

6. 精度评测

在 12 个中文地址对测试集上验证:

指标数值
总测试数12
正确数12
准确率100.00%

7. 注意事项

  1. 该模型为 BERT 分类模型,无法使用 vLLM 推理
  2. 推理设备使用 torch.npu.is_available() 检测 NPU 可用性
  3. 模型输出为三个类别的概率分布,使用 softmax 归一化
  4. 地址对长度建议不超过 512 tokens

Ascend NPU 精度评测

NPU vs CPU 精度对比(CPU 为基线,NPU 为验证目标):

指标数值
测试用例数6
最大 logits 差异0.00150269
预测一致性6/6 (100%)
精度要求NPU vs CPU 最大 logits 误差 < 1%
精度结论通过 (差异 小于 1%)

精度评测源代码和日志详见 eval/ 目录。