Skip to content

Commit 64f8b81

Browse files
authored
Merge pull request #203 from 1041206149/old_new_compare2
feat: 优化webkit抽取效果对比prompt
2 parents 0580267 + c4b6fff commit 64f8b81

File tree

4 files changed

+103
-79
lines changed

4 files changed

+103
-79
lines changed

dingo/model/llm/llm_html_abtract.py renamed to dingo/model/llm/llm_html_extract_compare.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
from dingo.model import Model
77
from dingo.model.llm.base_openai import BaseOpenAI
88
from dingo.model.modelres import ModelRes
9-
from dingo.model.prompt.prompt_html_abstract import PromptHtmlAbstract
9+
from dingo.model.prompt.prompt_html_extract_compare import PromptHtmlExtractCompare
1010
from dingo.model.response.response_class import ResponseScoreTypeNameReason
1111
from dingo.utils import log
1212
from dingo.utils.exception import ConvertJsonError
1313

1414

15-
@Model.llm_register("LLMHtmlAbstract")
16-
class LLMHtmlAbstract(BaseOpenAI):
17-
prompt = PromptHtmlAbstract
15+
@Model.llm_register("LLMHtmlExtractCompare")
16+
class LLMHtmlExtractCompare(BaseOpenAI):
17+
prompt = PromptHtmlExtractCompare
1818

1919
@classmethod
2020
def build_messages(cls, input_data: Data) -> List:
@@ -23,8 +23,8 @@ def build_messages(cls, input_data: Data) -> List:
2323
"role": "user",
2424
"content": cls.prompt.content.format(
2525
input_data.content,
26-
input_data.raw_data["markdown_ours"],
27-
input_data.raw_data["markdown_m10"],
26+
input_data.raw_data["magic_md"],
27+
input_data.raw_data["content"],
2828
),
2929
}
3030
]

dingo/model/prompt/prompt_html_abstract.py

Lines changed: 0 additions & 70 deletions
This file was deleted.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
from dingo.model.model import Model
2+
from dingo.model.prompt.base import BasePrompt
3+
4+
5+
@Model.prompt_register("Html_Extract_Compare", [], ['LLMHtmlExtractCompare'])
6+
class PromptHtmlExtractCompare(BasePrompt):
7+
_metric_info = {
8+
'category': 'SFT Data Assessment Metrics',
9+
'metric_name': 'PromptHtmlExtractCompare',
10+
'description': 'Compares the effectiveness of two HTML extraction tools by evaluating element recognition rate and accuracy across different content types',
11+
'paper_title': '',
12+
'paper_url': '',
13+
'paper_authors': '',
14+
'evaluation_results': ''
15+
}
16+
17+
content = r"""
18+
你是一位专业的 HTML 内容提取评估专家,擅长分析 HTML 代码和 Markdown 文本的转换质量。现在我会提供三段内容:
19+
20+
1. **原始网页的 HTML 代码**:这是网页的完整 HTML 结构。
21+
2. **工具A提取的 Markdown 文本**:这是从 HTML 中提取的、适合大语言模型训练的 Markdown 格式文本。
22+
3. **工具B提取的 Markdown 文本**:这是从 HTML 中提取的、适合大语言模型训练的 Markdown 格式文本。
23+
24+
⚠️ 注意:工具A与工具B的顺序不是固定的,请不要因为顺序而偏好某一工具,必须客观公正地评估两个工具的实际转换质量。
25+
26+
你的任务:
27+
1. 将两个工具提取出来的 Markdown 文本分别与 HTML 代码做对比。严格按以下模块类型检查提取效果:
28+
29+
**原始HTML元素识别:**
30+
- `code`:代码块(`<pre>` `<code>` 标签)
31+
- `math`:数学公式(MathJax、MathML、LaTeX 格式)
32+
- `table`:表格(`<table>` 标签)
33+
- `image`:图片(`<img>` 标签)
34+
- `list`:有序/无序列表(`<ul>` `<ol>` 标签)
35+
- `title`:标题(`<h1>`-`<h6>` 标签)
36+
- `paragraph`:段落文本(`<p>` `<div>` 等文本容器)
37+
- `other`:其他(非以上标签的可见内容)
38+
39+
**Markdown元素统计:**
40+
- 代码块:\`\`\`...\`\`\` 或缩进代码
41+
- 公式:`$...$` `$$...$$` `\\(...\\)` `\\[...\\]`
42+
- 表格:`|...|` 格式
43+
- 图片:`![](...)` 格式
44+
- 列表:`-` `*` `1.` 等标记
45+
- 标题:`#` `##` 等标记
46+
- 段落:普通文本块
47+
48+
2. **评分规则**:评价两个抽取工具的抽取质量,判断哪个工具抽取效果更好。
49+
- **抽取完整性**:检查 Markdown 文本是否完整抽取了 HTML 中的关键内容(如代码块、表格、图片、列表等)。
50+
- **格式准确性**:检查 Markdown 文本的格式是否正确(如代码块缩进、表格对齐、图片链接等)。
51+
- **语义连贯性**:检查 Markdown 文本是否保持了 HTML 内容的语义连贯性(如段落逻辑、标题层次等)。
52+
53+
3. **问题反馈**:严格按上述 8 类模块定位问题,若无问题则返回空列表。
54+
55+
4. **返回结果**:以 JSON 格式返回,包含3个字段:score、name、reason。
56+
- `score`:如果工具A抽取效果更好,score取值为1。如果工具B抽取效果更好,score取值为2。如果工具A和工具B抽取效果基本相同,score取值为0。
57+
- `name`:必须从 8 类模块中选择,且选择差异最大的问题模块。
58+
- `reason`:客观描述两个工具在该模块的表现差异。
59+
60+
示例输出:
61+
```json
62+
{{
63+
"score": [0|1|2],
64+
"name": "[模块类型]",
65+
"reason": "[客观描述两个工具在该模块的具体表现差异]"
66+
}}
67+
```
68+
69+
**注意事项**:
70+
1. 禁止使用预定义模块以外的分类。
71+
2. 重点关注结构化内容(代码、表格、公式、图片等)的转换质量。
72+
3. 段落分析需检查文本连贯性和语义完整性。
73+
74+
### 原始网页的 HTML 代码如下:
75+
76+
```html
77+
{}
78+
```
79+
80+
### 工具A提取的 Markdown 文本如下:
81+
82+
```md
83+
{}
84+
```
85+
86+
### 工具B提取的 Markdown 文本如下:
87+
88+
```md
89+
{}
90+
```
91+
92+
93+
返回结果只有一个 JSON,不要有其他任何解释说明以及分析的信息!
94+
"""

examples/compare/compare_content.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
if __name__ == '__main__':
55
input_data = {
6-
"input_path": "../../test/data/compare/test_compare_content.jsonl",
6+
"input_path": "../../test/data/compare/old_new_compare_10000.jsonl",
77
"dataset": {
88
"source": "local",
99
"format": "jsonl",
@@ -13,7 +13,7 @@
1313
}
1414
},
1515
"executor": {
16-
"prompt_list": ["PromptHtmlAbstract"],
16+
"prompt_list": ["PromptHtmlExtractCompare"],
1717
"batch_size": 10,
1818
"max_workers": 10,
1919
"result_save": {
@@ -24,7 +24,7 @@
2424
},
2525
"evaluator": {
2626
"llm_config": {
27-
"LLMHtmlAbstract": {
27+
"LLMHtmlExtractCompare": {
2828
"key": "",
2929
"api_url": ""
3030
}

0 commit comments

Comments
 (0)