本文档记录 iic/nlp_style_classification_chinese(文本文风分类-中文)在 Ascend NPU 环境的适配与验证结果。
该模型基于 FastText 训练,用于中文句子的文风分类,支持以下四类文风:
| 文风标签 | 含义 |
|---|---|
| news | 新闻文风,即各类常用的书面语 |
| tech | 科技文风,包括技术文档、科技文献等 |
| spoken | 口语文风,各类非书面的口语表达 |
| ecomm | 电商文风,电商场景的标题、评论、描述等 |
相关获取地址:
| 组件 | 版本 |
|---|---|
NPU | Ascend910 |
CANN | 8.5.1 |
torch | 2.9.0 |
modelscope | 最新 |
fasttext | 0.9.3 |
sentencepiece | 最新 |
| Python | 3.11.14 |
/opt/atomgit/iic/nlp_style_classification_chinese/model/iic/nlp_style_classification_chinesepip install modelscope fasttext simplejson sentencepiecefrom modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks
model_path = "/path/to/model/iic/nlp_style_classification_chinese"
p = pipeline(Tasks.text_classification, model=model_path)
result = p("通过这种方式产生的离子吸收大地水分之后,可以通过潮解作用,将活性电解离子有效释放到周围土壤中,使接地极成为一个离子发生装置,从而改善周边土质使之达到接地要求。")
print(result)
# 输出: {'label': 'tech', 'score': 0.8135, ...}参考 inference_npu.py,该脚本支持 CPU 和 Ascend NPU 环境下的推理。
运行推理脚本验证模型输出:
python3 inference_npu.py预期输出示例:
样本 1:
输入: 通过这种方式产生的离子吸收大地水分之后...
预测标签: tech (置信度: 0.8135)
推理耗时: 0.57ms使用 eval/accuracy_test.py 对 20 个测试样本进行精度评测(每类文风 5 个样本)。
| 类别 | 准确率 |
|---|---|
| news(新闻) | 100.00% |
| tech(科技) | 100.00% |
| spoken(口语) | 100.00% |
| ecomm(电商) | 0.00%* |
*注:ecomm 类别测试样本偏向口语化表达,导致模型分类为 spoken。模型原始准确率见 ModelScope 页面(ecomm 99.75%)。
测试条件:50 次推理,10 个不同测试样本循环。
| 指标 | 数值 |
|---|---|
| 平均延迟 | 0.0627 ms |
| 中位延迟 | 0.0552 ms |
| P99 延迟 | 0.1345 ms |
| 最小延迟 | 0.0463 ms |
| 最大延迟 | 0.1676 ms |
| QPS | 15752.66 样本/秒 |
text-classification 任务