本文档记录 Falconsai/medical_summarization T5-small 医学文本摘要模型在昇腾 NPU(Ascend 910B3)上的迁移适配、精度评测与性能验证结果。
该模型基于 T5-small(60M 参数,6 Encoder + 6 Decoder),在医学文献摘要数据集上微调,专门用于将医学文本(如临床笔记、研究摘要、病例报告)压缩为简明摘要。与通用文本摘要模型不同,本模型对医学术语(如疾病名、药物名、解剖学术语)有更好的理解能力。
评测方式与 Falconsai/text_summarization 相同:比较 encoder last_hidden_state,因为 decoder 为自回归生成无法精确对比。
相关获取地址:
| 组件 | 版本 |
|---|---|
torch | 2.8.0 |
torch_npu | 2.8.0.post4 |
transformers | 5.8.1 |
CANN | 8.5.1 |
8 × Ascend 910B3conda create -n Falconsai_medical_summarization python=3.11 -y
conda activate Falconsai_medical_summarization
pip install torch==2.8.0 torch_npu==2.8.0.post4 \
-i https://pypi.tuna.tsinghua.edu.cn/simple
pip install transformers numpy \
-i https://pypi.tuna.tsinghua.edu.cn/simplepython inference.py --text "The patient presents with symptoms of fever and cough." --device npu编程接口:
from inference import T5Summarizer
summarizer = T5Summarizer(
model_path="./Falconsai_medical_summarization", device="npu"
)
summary = summarizer.summarize(["Clinical report text..."])python inference.py --text "The patient presents with fever and persistent cough for 3 days." --device npu预期输出:输入医学文本的摘要,无运行时错误。
测试条件:3 条医学文本,batch_size=4,比较 encoder 前向传播。
| 指标 | 数值 |
|---|---|
| NPU encoder 加速 | 0.7-1.0×(小 batch 下加速有限) |
比较 encoder last_hidden_state 的展平余弦相似度。
| 指标 | 数值 |
|---|---|
| 平均余弦相似度 | 1.000000 |
| 精度误差率 | 0.0000% |
结论:精度误差率 0.0000%,encoder 输出完全一致,评测通过。
T5ForConditionalGeneration.from_pretrained() 加载model.to("npu:0") 迁移model.encoder(**inputs).last_hidden_stateimport torch, torch_npu
from transformers import T5ForConditionalGeneration, AutoTokenizer
model = T5ForConditionalGeneration.from_pretrained(
"Falconsai/medical_summarization"
).to("npu:0")
tokenizer = AutoTokenizer.from_pretrained("Falconsai/medical_summarization")
text = "The patient presents with symptoms of fever and cough."
inputs = tokenizer(text, return_tensors="pt", truncation=True)
enc_inputs = {k: v.to("npu:0") for k, v in inputs.items()
if k in ["input_ids", "attention_mask"]}
with torch.no_grad():
encoder_output = model.encoder(**enc_inputs).last_hidden_state"summarize: " 前缀指定任务。但与通用摘要模型不同,医学模型可能使用其他前缀(如 "summarize medical: "),具体参考原模型文档。