@@ -5,7 +5,7 @@ WebMainBench 是一个专门用于端到端评测网页正文抽取质量的基
55## 功能特点
66
77### 🎯 ** 核心功能**
8- - ** 多抽取器支持** : 支持 LLM-WebKit、Jina AI 等多种抽取工具
8+ - ** 多抽取器支持** : 支持 trafilatura,resiliparse 等多种抽取工具
99- ** 全面的评测指标** : 包含文本编辑距离、表格结构相似度(TEDS)、公式抽取质量等多维度指标
1010- ** 人工标注支持** : 评测数据集100%人工标注
1111
@@ -56,7 +56,7 @@ from webmainbench import DataLoader, Evaluator, ExtractorFactory
5656dataset = DataLoader.load_jsonl(" your_dataset.jsonl" )
5757
5858# 2. 创建抽取器
59- extractor = ExtractorFactory.create(" llm-webkit " )
59+ extractor = ExtractorFactory.create(" trafilatura " )
6060
6161# 3. 运行评测
6262evaluator = Evaluator()
@@ -81,40 +81,37 @@ print(f"Overall Score: {result.overall_metrics['overall']:.4f}")
8181 "meta" : {
8282 "language" : " en" , # 网页的语言
8383 "style" : " artical" , # 网页的文体
84- "DOM_WIDTH" : 176 ,
85- "DOM_DEPTH" : 27 ,
86- "text_linktext_ratio" : 0.12252270850536746 ,
87- "table_text_ratio" : 0 ,
88- "table_dom_depth" : -1 ,
89- "text_distribution_dispersion" : 0.2663 ,
9084 "table" : [], # [], ["layout"], ["data"], ["layout", "data"]
9185 "equation" : [], # [], ["inline"], ["interline"], ["inline", "interline"]
9286 "code" : [], # [], ["inline"], ["interline"], ["inline", "interline"]
93- "table_complexity_score" : 0 ,
94- "dom_complexity_score" : 0.8442 ,
95- "text_dispersion_score" : 0.2663 ,
96- "content_diversity_score" : 0 ,
97- "link_complexity_score" : 0.1225 ,
98- "overall_complexity_score" : 0.3083 ,
9987 "level" : " mid" # simple, mid, hard
10088 }
10189}
10290```
10391
10492## 支持的抽取器
10593
106- - ** LLM-WebKit ** : 基于大语言模型的智能抽取
107- - ** Jina AI ** : Reader API 服务
94+ - ** trafilatura ** : trafilatura抽取器
95+ - ** resiliparse ** : resiliparse抽取器
10896- ** 自定义抽取器** : 通过继承 ` BaseExtractor ` 实现
10997
98+ ## 评测榜单
99+
100+ | extractor | extractor_version | dataset | total_samples | overall(macro avg) | code_edit | formula_edit | table_TEDS | table_edit | text_edit |
101+ | -----------| -------------------| ---------| ---------------| ---------------------| -----------| --------------| ------------| -----------| -----------|
102+ | llm-webkit | 4.1.1 | WebMainBench1.0 | 545 | 0.8256 | 0.9093 | 0.9399 | 0.7388 | 0.678 | 0.8621 |
103+ | magic-html | 0.1.5 | WebMainBench1.0 | 545 | 0.5141 | 0.4117 | 0.7204 | 0.3984 | 0.2611 | 0.7791 |
104+ | trafilatura_md | 2.0.0 | WebMainBench1.0 | 545 | 0.3858 | 0.1305 | 0.6242 | 0.3203 | 0.1653 | 0.6887 |
105+ | trafilatura_txt | 2.0.0 | WebMainBench1.0 | 545 | 0.2657 | 0 | 0.6162 | 0 | 0 | 0.7126 |
106+ | resiliparse | 0.14.5 | WebMainBench1.0 | 545 | 0.2954 | 0.0641 | 0.6747 | 0 | 0 | 0.7381 |
110107
111108## 高级功能
112109
113110### 多抽取器对比评估
114111
115112``` python
116113# 对比多个抽取器
117- extractors = [" llm-webkit " , " jina-ai " ]
114+ extractors = [" trafilatura " , " resiliparse " ]
118115results = evaluator.compare_extractors(dataset, extractors)
119116
120117for name, result in results.items():
@@ -131,7 +128,6 @@ python examples/multi_extractor_compare.py
131128
1321291 . ** 加载测试数据集** :使用包含代码、公式、表格、文本等多种内容类型的样本数据
1331302 . ** 创建多个抽取器** :
134- - ` llm-webkit ` :支持预处理HTML的智能抽取器
135131 - ` magic-html ` :基于 magic-html 库的抽取器
136132 - ` trafilatura ` :基于 trafilatura 库的抽取器
137133 - ` resiliparse ` :基于 resiliparse 库的抽取器
@@ -152,7 +148,6 @@ python examples/multi_extractor_compare.py
152148` leaderboard.csv ` 内容示例:
153149``` csv
154150extractor,dataset,total_samples,success_rate,overall,code_edit,formula_edit,table_TEDS,table_edit,text_edit
155- llm-webkit,sample_dataset,4,1.0,0.2196,0.5,0.0,0.0,0.0,0.5982
156151magic-html,sample_dataset,4,1.0,0.1526,0.1007,0.0,0.0,0.0,0.6624
157152resiliparse,sample_dataset,4,1.0,0.1379,0.0,0.0,0.0,0.0,0.6897
158153trafilatura,sample_dataset,4,1.0,0.1151,0.1007,0.0,0.0,0.0,0.4746
@@ -204,194 +199,6 @@ class MyExtractor(BaseExtractor):
204199ExtractorFactory.register(" my-extractor" , MyExtractor)
205200```
206201
207- ### 数据集统计分析工具
208-
209- WebMainBench 提供了强大的数据集统计分析工具 ` scripts/statics.py ` ,用于分析数据集的各种特征并自动生成复杂度评分和难易程度分类。
210-
211- #### 功能特性
212-
213- - ** DOM结构分析** :计算网页DOM树的深度和宽度
214- - ** 文本链接比例分析** :统计文本与链接的比例关系
215- - ** 表格复杂度分析** :评估表格内容的复杂程度
216- - ** 内容类型检测** :自动识别公式、代码、表格等特殊内容
217- - ** 复杂度评分** :基于多维度指标计算综合复杂度得分
218- - ** 动态难易程度分类** :基于数据分布自动分类为 simple/mid/hard
219-
220- #### 使用方法
221-
222- ``` bash
223- # 基本用法
224- python scripts/statics.py data/input.jsonl --output data/output_with_stats.jsonl
225-
226- # 使用默认数据集
227- python scripts/statics.py
228- ```
229-
230- #### 参数说明
231-
232- ``` bash
233- # 查看所有可用参数
234- python scripts/statics.py --help
235-
236- ```
237-
238- #### 输出结果
239-
240- 工具会在每条数据的 ` meta ` 字段中添加以下统计信息:
241-
242- ``` json
243- {
244- "meta" : {
245- "DOM_DEPTH" : 25 , // DOM树深度
246- "DOM_WIDTH" : 1200 , // DOM树宽度
247- "text_linktext_ratio" : 0.85 , // 文本链接比例
248- "table_complexity_score" : 0.3 , // 表格复杂度得分
249- "dom_complexity_score" : 0.6 , // DOM复杂度得分
250- "text_dispersion_score" : 0.4 , // 文本分布得分
251- "content_diversity_score" : 0.7 , // 内容多样性得分
252- "link_complexity_score" : 0.5 , // 链接复杂度得分
253- "overall_complexity_score" : 0.52 , // 综合复杂度得分
254- "level" : " mid" // 难易程度 (simple/mid/hard)
255- }
256- }
257- ```
258-
259- #### 复杂度评分算法
260-
261- 综合复杂度得分由以下维度加权计算:
262-
263- - ** DOM结构复杂度 (25%)** :基于DOM深度和宽度,使用动态归一化
264- - ** 文本分布复杂度 (25%)** :基于文本在DOM中的分布离散程度
265- - ** 内容多样性 (25%)** :基于公式、代码、表格等特殊内容的种类
266- - ** 链接复杂度 (25%)** :基于文本与链接的比例关系
267-
268- #### 运行示例
269-
270- ``` bash
271- # 分析数据集并生成统计报告
272- python scripts/statics.py data/sample_dataset.jsonl --output data/analyzed_dataset.jsonl
273-
274- # 输出示例:
275- 🔄 第一阶段: 计算基础统计和复杂度得分...
276- 📊 已处理 100 条数据...
277- 📊 已处理 200 条数据...
278-
279- 🔄 第二阶段: 计算动态阈值和难易程度分类...
280- 📊 复杂度分布阈值计算:
281- 总样本数: 1,827
282- 30%分位数 (simple/mid分界): 0.3245
283- 70%分位数 (mid/hard分界): 0.6789
284- 复杂度得分范围: 0.0944 - 1.0000
285-
286- 📊 难易程度分类结果:
287- Simple: 548 (30.0%)
288- Mid: 731 (40.0%)
289- Hard: 548 (30.0%)
290-
291- 📝 正在写入数据到: data/analyzed_dataset.jsonl
292- ✅ 成功写入 1,827 条数据
293- ```
294-
295- ### 语言分类工具
296-
297- WebMainBench 提供了语言分类工具 ` scripts/language_classify.py ` ,用于为数据集中的文本内容自动添加符合 ISO 639-1 标准的语言标签。
298-
299- #### 主要特性
300-
301- - ** 多种检测方式** :支持基于规则的快速检测和基于LLM的高精度检测
302- - ** ISO 639-1 标准** :返回标准的两字母语言代码(如 en, zh, es)
303- - ** 广泛语言支持** :支持80+种主要语言的检测
304- - ** 批量处理** :高效处理大规模数据集
305- - ** 智能回退** :多字段检测,自动处理缺失数据
306-
307- #### 使用方法
308-
309- ``` bash
310- # 基于规则的快速检测(推荐用于大规模数据)
311- python scripts/language_classify.py data/input.jsonl --output data/output.jsonl
312-
313- # 使用LLM进行高精度检测
314- python scripts/language_classify.py data/input.jsonl --output data/output.jsonl \
315- --use-llm --api-key YOUR_OPENAI_API_KEY
316-
317- # 自定义批处理大小
318- python scripts/language_classify.py data/input.jsonl --output data/output.jsonl \
319- --batch-size 50
320- ```
321-
322- #### Prompt设计建议
323-
324- 如果你使用LLM进行语言检测,工具内置了优化的prompt模板:
325-
326- ** 核心设计原则:**
327- 1 . ** 明确输出格式** :只返回ISO 639-1两字母代码
328- 2 . ** 处理边界情况** :空文本、多语言文本、符号等
329- 3 . ** 语言映射规则** :中文统一返回"zh",未支持语言返回最接近的
330- 4 . ** 文本截断** :只分析前2000字符,提高效率
331-
332- ** 示例Prompt结构:**
333- ```
334- Please identify the primary language of the following text and return ONLY the ISO 639-1 two-letter language code.
335-
336- SUPPORTED LANGUAGES: en (English), zh (Chinese), es (Spanish), ...
337-
338- RULES:
339- 1. Return ONLY the two-letter code
340- 2. For mixed languages, return the DOMINANT language
341- 3. Empty text defaults to "en"
342- 4. Chinese variants all return "zh"
343-
344- TEXT TO ANALYZE: [your text here]
345-
346- LANGUAGE CODE:
347- ```
348-
349- #### 输出结果
350-
351- 工具会在数据的 ` meta.language ` 字段中添加语言标签:
352-
353- ``` json
354- {
355- "convert_main_content" : " Hello, this is sample content." ,
356- "meta" : {
357- "language" : " en"
358- }
359- }
360- ```
361-
362- #### 运行示例
363-
364- ``` bash
365- # 处理示例
366- python scripts/language_classify.py data/sample.jsonl --output data/sample_with_lang.jsonl
367-
368- # 输出:
369- 🔄 开始处理语言分类...
370- 📄 输入文件: data/sample.jsonl
371- 📄 输出文件: data/sample_with_lang.jsonl
372- 🧠 检测方法: 基于规则
373- 📊 已处理 100 条数据...
374- 📊 已处理 200 条数据...
375-
376- ✅ 处理完成!
377- 📊 总计处理: 1,000 条数据
378- 📊 语言分布:
379- en (English): 650 (65.0%)
380- zh (Chinese): 200 (20.0%)
381- es (Spanish): 80 (8.0%)
382- fr (French): 40 (4.0%)
383- de (German): 30 (3.0%)
384- ```
385-
386- #### 支持的语言
387-
388- 工具支持80+种主要语言,包括:
389- - ** 欧洲语言** :英语(en)、西班牙语(es)、法语(fr)、德语(de)、意大利语(it)等
390- - ** 亚洲语言** :中文(zh)、日语(ja)、韩语(ko)、泰语(th)、越南语(vi)等
391- - ** 其他语言** :阿拉伯语(ar)、俄语(ru)、葡萄牙语(pt)、印地语(hi)等
392-
393- 完整列表请运行:` python examples/language_classify_demo.py `
394-
395202## 项目架构
396203
397204```
0 commit comments