本文档记录 madhurjindal/autonlp-Gibberish-Detector-492513457 在 Ascend 910B3 NPU 环境下的适配与验证结果。
该模型基于 DistilBERT(distilbert-base-uncased)在 AutoNLP 平台上微调,用于文本乱码/垃圾内容检测。模型可将输入文本分类为 4 个类别:
clean:正常文本mild gibberish:轻微乱码noise:噪声文本word salad:无意义词语组合模型在测试集上达到 97.36% 的准确率和 F1 分数,适用于聊天机器人输入验证、内容审核、文本质量控制等场景。
本仓库提供:
相关获取地址:
| 组件 | 版本 |
|---|---|
torch | 2.8.0 |
torch_npu | 2.8.0.post4 |
transformers | 4.57.6 |
Ascend 910B3,1 逻辑卡DistilBertForSequenceClassification76812667M30,5224 类启动前可先检查 NPU 可用性:
python3 -c "import torch; print(f'NPU available: {torch.npu.is_available()}')"环境准备:
pip install torch torch_npu transformers
export ASCEND_RT_VISIBLE_DEVICES=0已验证通过的推理命令:
单条文本推理:
python inference.py --text "I love machine learning and artificial intelligence!"批量推理:
python inference.py --input-file texts.txtCPU 推理(参考基准):
python inference.py --device cpu --text "test text"输出格式:
{
"model": "madhurjindal--autonlp-Gibberish-Detector-492513457",
"device": "npu:0",
"num_texts": 1,
"inference_time_seconds": 0.0012,
"results": [
{
"text": "I love machine learning!",
"prediction": "clean",
"confidence": 0.9985,
"probabilities": {
"clean": 0.9985,
"mild gibberish": 0.0012,
"noise": 0.0002,
"word salad": 0.0001
}
}
]
}python inference.py --text "I love machine learning!"
python inference.py --text "asdfghjkl qwertyuiop zxcvbnm"预期输出:
clean,置信度 > 0.95noise 或 word salad验证结果:
cleannoise测试条件:8 条文本,batch_size=32,max_length=64。
| 指标 | CPU | NPU |
|---|---|---|
avg_time | 0.3222 s | 0.0117 s |
throughput | 24.83 texts/s | 685.12 texts/s |
speedup | - | 27.54x |
精度评测采用预测一致率和概率误差双指标。
| 指标 | 数值 |
|---|---|
| 测试样本数 | 8 |
| 最大概率绝对误差 | 1.0577e-03 |
| 平均概率绝对误差 | 1.6567e-04 |
| 预测一致率 | 8/8 (100.00%) |
| 错误率 | 0.00% |
| 精度要求(错误率 < 1%) | 通过 |
结论:NPU 与 CPU 的分类预测结果完全一致(100%),概率误差极小,精度通过验证。
max_length=64,超出部分会被截断,建议输入不超过 64 token。clean 为正常文本;mild gibberish 为轻微乱码(如部分错别字);noise 为纯噪声(如随机按键);word salad 为有语法但无意义的词语组合。