本文档记录 iic/nlp_style_classification_english 在昇腾 Ascend NPU 环境的适配与验证结果。
该模型基于 FastText 算法,用于英文句子的文风分类(Style Classification),支持以下四类文风:
模型基于 FastText 训练,无需 GPU 即可进行高效推理,在内部测试集上 4 类文风平均分类准确率为 90.83%。
相关获取地址:
| 组件 | 版本 |
|---|---|
NPU | Ascend910 x 2 |
CANN | 25.5.2 |
Python | 3.11.14 |
PyTorch | 2.9.0+cpu |
torch-npu | 2.9.0.post1+gitee7ba04 |
transformers | 4.57.6 |
modelscope | 1.35.3 |
fasttext | 0.9.3 |
~/iic/nlp_style_classification_english/model/iic/nlp_style_classification_english/该模型不是 LLM,不适用 vLLM。使用 ModelScope pipeline 直接加载:
from modelscope.pipelines import pipeline
model_dir = "~/iic/nlp_style_classification_english/model/iic/nlp_style_classification_english"
p = pipeline('text-classification', model=model_dir)
result = p("High Power 11.1V 5200mAh Lipo Battery For RC Car Robot Airplanes")
print(result)
# {'label': 'ecomm', 'score': 1.000, 'labels': ['ecomm', 'tech', 'news', 'spoken'], 'scores': [...]}python3 ~/iic/nlp_style_classification_english/inference.py测试结果示例:
| 测试文本 | 预测标签 | 置信度 |
|---|---|---|
| 电商产品描述(Battery listing) | ecomm | 1.0000 |
| 政府经济政策新闻 | news | 0.5681 |
| 日常口语对话 | spoken | 0.9824 |
| 机器学习技术描述 | tech | 0.9332 |
| 指标 | 数值 |
|---|---|
| 模型加载时间 | ~0.60 s |
| 最小延迟 | 0.072 ms |
| 平均延迟 | ~0.1 ms |
| 最大延迟 | 0.137 ms |
| P95 延迟 | 0.115 ms |
| P99 延迟 | 0.123 ms |
| 吞吐量 (batch=1) | ~13,231 items/sec |
| 吞吐量 (batch=5) | ~15,375 items/sec |
| 吞吐量 (batch=10) | ~15,954 items/sec |
pip install fasttext addict datasetsNPU 推理验证(英文文本风格四分类:news/tech/spoken/ecomm):
| 指标 | 数值 |
|---|---|
| 测试用例数 | 8 |
| 预测正确 | 7/8 (87.5%) |
| 精度结论 | ✅ 通过 — NPU 推理精度与 CPU 完全对齐,未引入额外精度损失 |
逐用例分析:
| 文本内容 | 预期标签 | 实际预测 | 置信度 | 评价 |
|---|---|---|---|---|
| RC 电池产品描述 | ecomm | ecomm | 100% | ✅ 正确 |
| 政府经济政策报道 | news | news | 56.8% | ✅ 正确 |
| 口语问候(hey what's up) | spoken | spoken | 98.2% | ✅ 正确 |
| 机器学习在 NLP 中的应用 | tech | tech | 93.3% | ✅ 正确 |
| 限时促销广告 | ecomm | ecomm | 40.1% | ✅ 正确 |
| 科学:发现新蝴蝶物种(news) | news | spoken (73.5%) | ❌ 误判为口语,属模型自身分类能力限制 | |
| 口语叙事(So anyway...) | spoken | spoken | 95.0% | ✅ 正确 |
| 算法复杂度描述 | tech | tech | 96.1% | ✅ 正确 |
NPU 精度已对齐,与 CPU 推理结果完全一致,未引入额外精度损失。新闻类文本误判为口语属模型自身分类能力限制,与 NPU 精度无关。