Skip to content

Commit 9094fab

Browse files
authored
Merge pull request #224 from chaserRen/rzf-mineru
Add Doc Parse Doc
2 parents 45bab28 + 84e1ecc commit 9094fab

File tree

1 file changed

+159
-0
lines changed

1 file changed

+159
-0
lines changed
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
# VLMDocumentParsingQuality 文档解析评估工具 使用文档
2+
3+
Dingo 提供了一种基于VLM的文档解析质量评估与可视化工具,可帮助您:
4+
- 评估文档解析模型输出质量
5+
- 生成模型质量报告
6+
7+
## 工具介绍
8+
9+
### VLMDocumentParsingQuality:文档解析评估工具
10+
11+
#### 功能说明
12+
该工具用于评估文档解析模型效果,具体功能包括:
13+
- 定义了公式、表格、O分行分段、列表项、代码项、OCR、阅读顺序等维度的文档解析错误类别
14+
- 对比原始文档以及模型解析后的md结果
15+
- 从端到端的维度识别模型存在的错误,并报告错误类型和原因
16+
- 输出详细的评估报告
17+
18+
#### 技术细节
19+
##### 文件结构
20+
21+
```
22+
dingo/
23+
├── model/
24+
│ ├── llm/
25+
│ │ └── vlm_document_parsing.py # 评估器实现
26+
│ └── prompt/
27+
│ └── prompt_document_parsing.py # 评估提示词
28+
│── examples/
29+
│ └── document_parser/
30+
│ └── vlm_document_parser_quality.py # 单条评估示例
31+
└── test/ # 测试输入输出目录
32+
└── data/ # 图像相关数据
33+
├── test_img_md.jsonl # 输入的jsonl示例
34+
└── c6be64e4-1dd4-4bd4-b923-55a63a6de397_page_1.jpg # 输入的示例图片
35+
```
36+
37+
##### 评估提示词
38+
我们的评估效果依赖于精心设计的 Prompt。其核心思想是:
39+
40+
1. 分层错误标签:我们将文档解析问题分为10个大类(一级标签),如公式、表格、OCR识别等。每个大类下又细分了具体的二级标签,以实现更精确的错误归因。
41+
2. 结构化输出:我们要求 VLM 模型为每张图片生成一个结构化的 JSON 报告,直接对应于上文提到的输出格式,便于程序化处理。
42+
43+
44+
#### 输入数据格式
45+
46+
```python
47+
input_data = {
48+
"input_path": "/path/to/your/input.jsonl",
49+
"dataset": {
50+
"source": "local",
51+
"format": "image",
52+
"field": {
53+
"id": "id",
54+
"content": "content", # 模型解析的markdown结果
55+
"image": "img" # 需要解析的image图片
56+
}
57+
},
58+
"executor": {
59+
"prompt_list": ["PromptDocumentParsingQuality"],
60+
"result_save": {
61+
"bad": True,
62+
"good": True
63+
}
64+
},
65+
"evaluator": {
66+
"llm_config": {
67+
"VLMDocumentParsingQuality": {
68+
"key": "",
69+
"api_url": "",
70+
}
71+
}
72+
}
73+
}
74+
```
75+
76+
#### 输出结果格式
77+
78+
```python
79+
# result 是 ModelRes 对象,包含以下字段:
80+
result.type # 错误问题一级标签: prompt中定义的一级错误大类
81+
result.name # 错误问题二级标签: 一级错误大类对应的详细错误标签 List[str]
82+
result.error_status # 错误状态: False 或 True
83+
result.reason # 评估原因: List[str]
84+
```
85+
86+
87+
## 使用示例
88+
89+
### 基础用法
90+
91+
```python
92+
from dingo.config import InputArgs
93+
from dingo.exec import Executor
94+
95+
if __name__ == '__main__':
96+
# 准备数据
97+
input_data = {
98+
"input_path": "../../test/data/test_img_md.jsonl",
99+
"dataset": {
100+
"source": "local",
101+
"format": "image",
102+
"field": {
103+
"id": "id",
104+
"content": "content",
105+
"image": "img"
106+
}
107+
},
108+
"executor": {
109+
"prompt_list": ["PromptDocumentParsingQuality"],
110+
"result_save": {
111+
"bad": True,
112+
"good": True
113+
}
114+
},
115+
"evaluator": {
116+
"llm_config": {
117+
"VLMDocumentParsingQuality": {
118+
"key": "",
119+
"api_url": "",
120+
}
121+
}
122+
}
123+
}
124+
input_args = InputArgs(**input_data)
125+
executor = Executor.exec_map["local"](input_args)
126+
127+
# 执行评估
128+
result = executor.execute()
129+
130+
# 查看结果
131+
print(result)
132+
```
133+
134+
### JSONL数据格式
135+
136+
```jsonl
137+
{"id": "1", "content": "即当 \\(x\\longrightarrow0\\) 时, \\(f(x)\\) 与 \\(6x^{2}\\) 互为等价无穷小量,故 \\(c=6,k=3\\) ,应选A.\n\n# 强化20\n\n【解析】当 \\(x\\longrightarrow0^{2}\\) 时,有\n\n\\(\\alpha^{\\prime}=\\cos x^{2}\\rightarrow1\\) ,即 \\(\\alpha\\!\\sim\\!x\\) (为 \\(x\\) 的1阶无穷小量),\n\n\\(\\beta^{\\prime}\\!=\\!\\tan x\\cdot2x\\!\\sim\\!2x^{2}\\) 即 \\(\\beta\\!\\sim\\!\\frac{2}{3}x^{3}\\) (为 \\(x\\) 的3阶无穷小量),\n\n\\(\\gamma^{\\prime}=\\sin x^{\\frac{3}{7}}\\cdot\\frac{1}{2\\sqrt{x}}-x^{\\frac{3}{7}}\\frac{1}{2\\sqrt{x}}=\\frac{1}{2}x\\) 即 \\(\\gamma\\!\\sim\\!\\frac{1}{4}x^{2}\\) (为 \\(x\\) 的2阶无穷小量),\n\n所以当 \\(x\\longrightarrow0\\) 时无穷小量从低阶到高阶的顺序为 \\(\\alpha,\\gamma,\\beta\\) 故应选B.\n\n# 强化21\n\n【解析】方法一:导数定阶法\n\n由当 \\(x\\longrightarrow0^{2}\\) 时,\n\n\\(\\left[\\int_{0}^{x}\\left(\\mathrm{e}^{t^{2}}-1\\right)\\mathrm{d}t\\right]^{\\prime}=\\mathrm{e}^{x^{2}}-1-x^{2}\\) 故 \\(\\int_{0}^{x}\\left(\\mathrm{e}^{t^{2}}-1\\right)\\mathrm{d}t=\\frac{1}{3}x^{3}\\) 为3阶无穷小量;\\(\\left[\\int_{0}^{x}\\ln\\left(1+\\sqrt{t^{2}}\\right)\\mathrm{d}t\\right]^{\\prime}=\\ln\\left(1+\\sqrt{x^{2}}\\right)\\sim\\sqrt{x^{2}}\\) 故 \\(\\int_{0}^{x}\\ln\\left(1+\\sqrt{t^{2}}\\right)\\mathrm{d}t-\\frac{2}{5}x^{\\frac{2}{3}}\\) 为 \\(\\frac{5}{2}\\) 阶无穷小量;\\(\\left[\\int_{0}^{x}\\sin t^{2}\\mathrm{d}t\\right]^{\\prime}=\\sin(\\sin x)^{2}\\cos x-x^{2}\\) 故 \\(\\int_{0}^{x}\\sin t^{2}\\mathrm{d}t-\\frac{1}{3}x^{3}\\) 为3阶无穷小量;\\(\\left[\\int_{0}^{x}(1-\\cos t)\\,\\mathrm{d}t\\right]^{\\prime}-1-\\cos x-\\frac{1}{2}x^{2}\\) 故 \\(\\int_{0}^{x}(1-\\cos t)\\,\\mathrm{d}t-\\frac{1}{6}x^{3}\\) 为3阶无穷小量;\\(\\left[\\int_{0}^{1-\\cos x}\\sqrt{\\sin^{3}t}\\,\\mathrm{d}t\\right]^{\\prime}=\\sqrt{\\sin^{3}(1-\\cos x)}\\,\\cdot\\,\\sin x-\\frac{1}{2}x^{2}\\right]^{\\frac{3}{2}}\\,\\cdot\\,x=\\frac{1}{2\\sqrt{2}}\\,x^{4}\\) 故 \\(\\int_{0}^{1-\\cos x}\\sqrt{\\sin^{3}t}\\,\\mathrm{d}t\\) 为5阶无穷小量,应选E.\n\n\n\n# 方法二:经验法,见【敲重点】\n\n对于选项A, \\(\\int_{0}^{x}\\left(\\mathrm{e}^{t^{2}}-1\\right)\\mathrm{d}t\\) 为 \\(x\\longrightarrow0^{2}\\) 时的 \\(n(m+1)=1\\times(2+1)=3\\) 阶无穷小量;对于选项B, \\(\\int_{0}^{x}\\ln\\left(1+\\sqrt{t^{2}}\\right)\\mathrm{d}t\\) 为 \\(x\\longrightarrow0^{2}\\) 时的 \\(n(m+1)=1\\times\\left({\\frac{3}{2}}+1\\right)={\\frac{5}{2}}\\) 阶无穷小量;对于选项C, \\(\\int_{0}^{1\\sim x}\\sin t^{2}\\mathrm{d}t\\) 为 \\(x\\longrightarrow0^{2}\\) 时的 \\(n(m+1)=1\\times(2+1)=3\\) 阶无穷小量;对于选项D, \\(\\int_{0}^{x}\\left(1-\\cos t\\right)\\mathrm{d}t\\) 为 \\(x\\longrightarrow0^{2}\\) 时的 \\(n(m+1)=1\\times(2+1)=3\\) 阶无穷小量,对于选项E, \\(\\int_{0}^{1-\\cos x}\\sqrt{\\sin^{3}t}\\,\\mathrm{d}t\\) 为 \\(x\\longrightarrow0^{2}\\) 时的 \\(n(m+1)=2\\times\\left({\\frac{3}{2}}+1\\right)=5\\) 阶无穷小量,故应选E.", "img": "../../test/data/c6be64e4-1dd4-4bd4-b923-55a63a6de397_page_1.jpg"}
138+
```
139+
140+
141+
## 最佳实践
142+
### 评估模型
143+
1. 务必使用VLM模型:
144+
此工具的原理是将图片和文本同时输入给模型进行对比评估。因此,必须使用支持多模态输入的 VLM(视觉语言模型),否则模型将无法处理图片输入。
145+
2. 推荐使用高性能VLM:
146+
推荐使用Gemini 2.5 Pro 这样先进的 VLM。更强大的模型在图像理解、空间关系识别和细微错误发现方面表现更出色,能提供更准确、更可靠的评估结果。
147+
148+
## 完整示例
149+
150+
### 评估示例
151+
参考: `examples/document_parser/vlm_document_parser_quality.py`
152+
153+
### 测试数据
154+
参考: `test/data/test_img_md.jsonl`
155+
156+
157+
## 参考资料
158+
159+
1. [Dingo 文档](https://deepwiki.com/MigoXLab/dingo) - 完整的 API 文档和更多示例

0 commit comments

Comments
 (0)