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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- zh
|
| 5 |
+
- en
|
| 6 |
+
base_model:
|
| 7 |
+
- Qwen/Qwen3-VL-8B-Instruct
|
| 8 |
+
pipeline_tag: image-text-to-text
|
| 9 |
+
tags:
|
| 10 |
+
- Declaration-Form
|
| 11 |
+
- Audit
|
| 12 |
+
- vision
|
| 13 |
+
- multimodal
|
| 14 |
+
- customs
|
| 15 |
+
- document-understanding
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Declaration-Form-Audit
|
| 20 |
+
|
| 21 |
+
专为报关单证智能审核优化的多模态视觉语言模型。
|
| 22 |
+
|
| 23 |
+
## 🎯 模型功能
|
| 24 |
+
|
| 25 |
+
本模型专注于进出口报关单证的智能审核任务,具备以下核心能力:
|
| 26 |
+
|
| 27 |
+
### 单证信息提取
|
| 28 |
+
- **证书类型识别**:卫生证书、原产地证书、检验报告、合同、发票等
|
| 29 |
+
- **关键字段提取**:证书编号、集装箱号、件数、净重、毛重
|
| 30 |
+
- **商品明细解析**:逐行提取表格数据(商品名称、数量、金额等)
|
| 31 |
+
- **日期信息提取**:签发日期、有效期、生产日期
|
| 32 |
+
|
| 33 |
+
### 表格数据处理
|
| 34 |
+
- 支持复杂多列表格的逐行扫描
|
| 35 |
+
- 准确识别数字、日期、文本混合内容
|
| 36 |
+
- 自动处理表格合并单元格和分栏结构
|
| 37 |
+
|
| 38 |
+
### 多语言OCR
|
| 39 |
+
- 中文、英文、西班牙语、日文、俄文等多语言混合识别
|
| 40 |
+
- 支持手写体和印刷体混合文档
|
| 41 |
+
- 模糊字符智能识别优化
|
| 42 |
+
|
| 43 |
+
### 单证比对审核
|
| 44 |
+
- 比对报关单与随附证书的一致性
|
| 45 |
+
- 识别数据异常和潜在风险点
|
| 46 |
+
- 生成结构化审核结果
|
| 47 |
+
|
| 48 |
+
## 🔧 模型训练
|
| 49 |
+
|
| 50 |
+
### 训练方法
|
| 51 |
+
本模型采用初期审单领域知识注入(CPT)+多阶段监督微调(SFT)+ 2阶段强化学习(RL)**的训练策略:
|
| 52 |
+
|
| 53 |
+
1. **视觉-语言对齐阶段**:增强模型对单证图像的理解能力
|
| 54 |
+
2. **领域数据适配阶段**:学习海关报关单证的专业术语和格式
|
| 55 |
+
3. **任务专项优化阶段**:针对表格提取、字段识别等具体任务强化训练
|
| 56 |
+
4. **多任务融合阶段**:综合提升各项审核能力
|
| 57 |
+
|
| 58 |
+
### 训练数据规模
|
| 59 |
+
- 监督学习阶段:约70万条高质量标注样本
|
| 60 |
+
- 强化学习阶段:约15万条审核任务数据
|
| 61 |
+
- 覆盖20+国家/地区的单证格式
|
| 62 |
+
|
| 63 |
+
## 📄 疑难PDF处理能力
|
| 64 |
+
|
| 65 |
+
### 低质量图像优化
|
| 66 |
+
本模型在训练中特别针对实际业务中的疑难PDF进行了优化:
|
| 67 |
+
|
| 68 |
+
1. 特殊类型的证书编号:
|
| 69 |
+
|
| 70 |
+

|
| 71 |
+
|
| 72 |
+
2. 负责表格数据提取及汇总:
|
| 73 |
+
|
| 74 |
+

|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
3. 不规范表格的提取:
|
| 78 |
+

|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
4. 跨页单据的提取累加:
|
| 82 |
+
|
| 83 |
+

|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
### 实测效果
|
| 88 |
+
|
| 89 |
+
| 测试场景 | 准确率 |
|
| 90 |
+
|---------|-------|
|
| 91 |
+
| 证书编号识别 | 99%+ |
|
| 92 |
+
| 集装箱号提取 | 98%+ |
|
| 93 |
+
| 表格数据提取 | 99%+ |
|
| 94 |
+
| 件数重量识别 | 99%+ |
|
| 95 |
+
|
| 96 |
+
## 🚀 快速开始
|
| 97 |
+
|
| 98 |
+
### 安装依赖
|
| 99 |
+
|
| 100 |
+
```bash
|
| 101 |
+
pip install transformers torch pillow
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
### Python推理
|
| 105 |
+
|
| 106 |
+
```python
|
| 107 |
+
from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
|
| 108 |
+
from PIL import Image
|
| 109 |
+
import torch
|
| 110 |
+
|
| 111 |
+
# 加载模型
|
| 112 |
+
model = Qwen2VLForConditionalGeneration.from_pretrained(
|
| 113 |
+
"shihao1989/Declaration-Form-Audit",
|
| 114 |
+
torch_dtype=torch.bfloat16,
|
| 115 |
+
device_map="auto"
|
| 116 |
+
)
|
| 117 |
+
processor = AutoProcessor.from_pretrained("shihao1989/Declaration-Form-Audit")
|
| 118 |
+
|
| 119 |
+
# 准备输入
|
| 120 |
+
image = Image.open("certificate.jpg")
|
| 121 |
+
messages = [
|
| 122 |
+
{
|
| 123 |
+
"role": "user",
|
| 124 |
+
"content": [
|
| 125 |
+
{"type": "image"},
|
| 126 |
+
{
|
| 127 |
+
"type": "text",
|
| 128 |
+
"text": "请提取这份证书的证书编号、集装箱号、件数和净重。"
|
| 129 |
+
}
|
| 130 |
+
]
|
| 131 |
+
}
|
| 132 |
+
]
|
| 133 |
+
|
| 134 |
+
# 推理
|
| 135 |
+
text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 136 |
+
inputs = processor(text=[text], images=[image], return_tensors="pt").to("cuda")
|
| 137 |
+
|
| 138 |
+
output = model.generate(**inputs, max_new_tokens=512, temperature=0.1)
|
| 139 |
+
result = processor.batch_decode(output, skip_special_tokens=True)[0]
|
| 140 |
+
print(result)
|
| 141 |
+
```
|
| 142 |
+
|
| 143 |
+
### vLLM部署(生产推荐)
|
| 144 |
+
|
| 145 |
+
```bash
|
| 146 |
+
docker run -d \
|
| 147 |
+
--name declaration-audit \
|
| 148 |
+
--runtime=nvidia \
|
| 149 |
+
-e NVIDIA_VISIBLE_DEVICES=0 \
|
| 150 |
+
--ipc=host \
|
| 151 |
+
-p 8000:8000 \
|
| 152 |
+
vllm/vllm-openai:latest \
|
| 153 |
+
--model shihao1989/Declaration-Form-Audit \
|
| 154 |
+
--trust-remote-code \
|
| 155 |
+
--max-model-len 32000 \
|
| 156 |
+
--gpu-memory-utilization 0.9
|
| 157 |
+
```
|
| 158 |
+
|
| 159 |
+
### API调用
|
| 160 |
+
|
| 161 |
+
```python
|
| 162 |
+
import requests
|
| 163 |
+
import base64
|
| 164 |
+
|
| 165 |
+
with open("certificate.jpg", "rb") as f:
|
| 166 |
+
image_b64 = base64.b64encode(f.read()).decode()
|
| 167 |
+
|
| 168 |
+
response = requests.post("http://localhost:8000/v1/chat/completions", json={
|
| 169 |
+
"model": "shihao1989/Declaration-Form-Audit",
|
| 170 |
+
"messages": [
|
| 171 |
+
{
|
| 172 |
+
"role": "user",
|
| 173 |
+
"content": [
|
| 174 |
+
{"type": "text", "text": "提取证书编号和净重"},
|
| 175 |
+
{"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{image_b64}"}}
|
| 176 |
+
]
|
| 177 |
+
}
|
| 178 |
+
],
|
| 179 |
+
"max_tokens": 512,
|
| 180 |
+
"temperature": 0.1
|
| 181 |
+
})
|
| 182 |
+
|
| 183 |
+
print(response.json()["choices"][0]["message"]["content"])
|
| 184 |
+
```
|
| 185 |
+
|
| 186 |
+
## 💡 最佳实践
|
| 187 |
+
|
| 188 |
+
### Prompt设计建议
|
| 189 |
+
|
| 190 |
+
**推荐格式(结构化输出):**
|
| 191 |
+
```
|
| 192 |
+
请从这份原产地证书中提取以下字段,返回JSON格式:
|
| 193 |
+
{
|
| 194 |
+
"cert_code": "证书编号",
|
| 195 |
+
"containers": ["集装箱号列表"],
|
| 196 |
+
"packages": 件数(整数),
|
| 197 |
+
"net_weight_kg": 净重(数字)
|
| 198 |
+
}
|
| 199 |
+
只输出JSON,不要有额外文字。
|
| 200 |
+
```
|
| 201 |
+
|
| 202 |
+
**关键原则:**
|
| 203 |
+
- 明确指定提取字段和格式
|
| 204 |
+
- 提供字段的可能名称(如"证书编号/Certificate No.")
|
| 205 |
+
- 使用JSON等结构化格式便于后处理
|
| 206 |
+
|
| 207 |
+
## 📜 许可证
|
| 208 |
+
|
| 209 |
+
本模型遵循 Apache 2.0 许可证。
|
| 210 |
+
|
| 211 |
+
## 🙏 致谢
|
| 212 |
+
|
| 213 |
+
- Qwen团队提供的优秀基座模型
|
| 214 |
+
- 海关业务专家提供的领域知识指导
|
| 215 |
+
|
| 216 |
+
## 📮 联系方式
|
| 217 |
+
|
| 218 |
+
如有问题或建议,欢迎通过Hugging Face Discussions交流。
|