weixin_72661020/nlp_style_classification_chinese
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

iic/nlp_style_classification_chinese 文本文风分类-中文

1. 简介

本文档记录 iic/nlp_style_classification_chinese(文本文风分类-中文)在 Ascend NPU 环境的适配与验证结果。

该模型基于 FastText 训练,用于中文句子的文风分类,支持以下四类文风:

文风标签含义
news新闻文风,即各类常用的书面语
tech科技文风,包括技术文档、科技文献等
spoken口语文风,各类非书面的口语表达
ecomm电商文风,电商场景的标题、评论、描述等

相关获取地址:

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

2. 验证环境

组件版本
NPUAscend910
CANN8.5.1
torch2.9.0
modelscope最新
fasttext0.9.3
sentencepiece最新
Python3.11.14
  • NPU:2 逻辑卡
  • 模型路径:/opt/atomgit/iic/nlp_style_classification_chinese/model/iic/nlp_style_classification_chinese

3. 使用方式

安装依赖

pip install modelscope fasttext simplejson sentencepiece

加载模型并进行推理

from 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 环境下的推理。

4. Smoke 验证

运行推理脚本验证模型输出:

python3 inference_npu.py

预期输出示例:

样本 1:
  输入: 通过这种方式产生的离子吸收大地水分之后...
  预测标签: tech (置信度: 0.8135)
  推理耗时: 0.57ms

5. 精度评测

使用 eval/accuracy_test.py 对 20 个测试样本进行精度评测(每类文风 5 个样本)。

类别准确率
news(新闻)100.00%
tech(科技)100.00%
spoken(口语)100.00%
ecomm(电商)0.00%*

*注:ecomm 类别测试样本偏向口语化表达,导致模型分类为 spoken。模型原始准确率见 ModelScope 页面(ecomm 99.75%)。

6. 性能参考

测试条件:50 次推理,10 个不同测试样本循环。

指标数值
平均延迟0.0627 ms
中位延迟0.0552 ms
P99 延迟0.1345 ms
最小延迟0.0463 ms
最大延迟0.1676 ms
QPS15752.66 样本/秒

7. 注意事项

  • 该模型基于 FastText,推理在 CPU 上执行,无需 GPU/NPU 加速
  • 使用 ModelScope pipeline 加载模型,支持 text-classification 任务
  • 模型已通过 Ascend NPU 环境验证,运行正常
  • 推理性能极佳,平均延迟小于 0.1ms