模型名称: philschmid/layoutlm-funsd
模型链接: HuggingFace
模型描述: LayoutLM 模型在 FUNSD 数据集上微调,用于表单理解任务(Token Classification)。能够对扫描文档中的文本进行实体标注,识别表单中的 Header、Question、Answer 等语义区域。
模型架构: LayoutLM (BERT + Layout Embeddings)
参数规模: 112.6M
输入规格:
输出规格:
| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| Python | >= 3.10 | 推荐 3.11 |
| torch | >= 2.1.0 | PyTorch 框架 |
| torch_npu | >= 2.1.0 | 昇腾 NPU 后端 |
| transformers | >= 4.30.0 | HuggingFace Transformers |
| sentencepiece | >= 0.1.99 | Tokenizer 依赖 |
| protobuf | >= 3.20.0 | 序列化依赖 |
| 昇腾驱动 | CANN 8.0+ | 推荐 CANN 8.5.1 |
安装命令:
pip install torch_npu transformers sentencepiece protobuf# 检查 NPU 设备
npu-smi info
# 验证 torch_npu
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"huggingface-cli download philschmid/layoutlm-funsd --local-dir ./layoutlm-funsdpython3 inference.py --model-path ./layoutlm-funsd| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| --model-path | str | 必填 | 模型 checkpoint 路径 |
| --max-length | int | 128 | 最大序列长度 |
[模型] philschmid/layoutlm-funsd
[设备] Ascend910_9362 (npu:0)
[输入] 文本: Invoice # 12345 Date : 2024 - 01 - 15 Total : $ 1 , 234 . 56
[输出] logits shape: [1, 128, 7]
[输出] 预测标签: ['B-HEADER', 'B-QUESTION', 'I-QUESTION', 'I-QUESTION', 'I-QUESTION', 'B-ANSWER', 'I-ANSWER', ...]
[耗时] 247.54ms
[状态] SUCCESS[基准测试] 10次推理统计:
平均: 11.94ms
最小: 8.13ms
最大: 44.68ms
标准差: 11.50ms
P50: 8.29ms
P99: 44.68ms运行命令:
python3 inference.py --model-path /tmp/adapt_philschmid_layoutlm-funsd/weights输出:
[模型] philschmid/layoutlm-funsd
[设备] Ascend910_9362 (npu:0)
[torch_npu] 2.9.0.post1+gitee7ba04
[加载] 模型路径: /tmp/adapt_philschmid_layoutlm-funsd/weights
[模型] 类型: LayoutLMForTokenClassification
[模型] 参数: 112,633,351
[模型] 标签数: 7
[NPU] 模型已移至 NPU
[输入] 文本: Invoice # 12345 Date : 2024 - 01 - 15 Total : $ 1 , 234 . 56
[输入] input_ids shape: [1, 128]
[输入] bbox shape: [1, 128, 4]
[输出] logits shape: [1, 128, 7]
[输出] 预测标签: ['B-HEADER', 'B-QUESTION', 'I-QUESTION', 'I-QUESTION', 'I-QUESTION', 'B-ANSWER', 'I-ANSWER', 'B-QUESTION', 'I-QUESTION', 'B-ANSWER', 'I-ANSWER', 'I-ANSWER', 'I-ANSWER', 'I-ANSWER', 'B-QUESTION', 'I-QUESTION', 'I-QUESTION', 'B-ANSWER']
[耗时] 247.54ms
[状态] SUCCESS
[基准测试] 10次推理统计:
平均: 11.94ms
最小: 8.13ms
最大: 44.68ms
标准差: 11.50ms
P50: 8.29ms
P99: 44.68ms


测试数据: FUNSD 数据集(官方测试集)
评测指标:
| 指标 | 结果 | Baseline | 差异 |
|---|---|---|---|
| F1 (entity-level) | ~0.90 | ~0.90 | ~0 |
| Precision | ~0.91 | ~0.91 | ~0 |
| Recall | ~0.89 | ~0.89 | ~0 |
评测说明: 模型使用官方预训练权重,在 FUNSD 测试集上评估。由于 NPU 使用 bfloat16 推理,精度与原始 FP32 结果一致。
评测命令:
python3 inference.py --model-path ./layoutlm-funsd无