OCR转Markdown评估体系存在根本缺陷

4 阅读6分钟

评估将PDF或文档图像转换为Markdown的OCR系统远比表面看起来复杂。与纯文本OCR不同,OCR转Markdown要求模型同时恢复内容、布局、阅读顺序和表示形式的选择。如今的基准测试试图通过字符串匹配、启发式对齐和特定格式规则的组合来评分,但实际上,这些方法经常将正确的输出误判为失败。

本文概述了为何OCR转Markdown的评估天生就是规定不足的,审视了常见的评估技术及其失败模式,指出了在两个广泛使用的基准测试中观察到的具体问题,并解释了为何尽管不完美,但目前使用LLM作为评估器是最实用的方法。

为何OCR转Markdown难以评估

核心问题在于,OCR转Markdown并不存在单一的正确答案。多个输出可能同样有效:

  • 多列布局可以用不同的阅读顺序进行线性化。
  • 公式可以使用LaTeX、Unicode、HTML或其混合形式表示。
  • 页眉、页脚、水印和边注文本是否算作“内容”取决于任务意图。
  • 空格、标点符号和Unicode规范化通常存在差异,但不影响语义。

从人类或下游系统的角度来看,这些输出是等价的。但从基准测试的角度看,它们通常不等价。

常见评估技术及其局限性

1. 基于字符串的指标 (编辑距离、精确匹配)

大多数OCR转Markdown基准测试依赖于规范化字符串比较或编辑距离。

局限性

  • Markdown被视为扁平字符序列,忽略了其结构。
  • 微小的格式差异会导致巨大的惩罚。
  • 如果文本重叠,结构错误的输出也可能获得高分。
  • 分数与人类判断的相关性很差。

这些指标奖励的是格式合规性,而非正确性。

2. 对顺序敏感的块匹配

一些基准测试将文档分割成块,并对顺序和接近度进行评分。

局限性

  • 有效的替代阅读顺序(例如多列文档)会受到惩罚。
  • 小的页脚或边注文本可能破坏严格的顺序约束。
  • 随着布局复杂性增加,匹配启发式算法的效果会迅速下降。
  • 由于排序假设,正确的内容常常被标记为错误。

3. 通过LaTeX归一化进行公式匹配

侧重数学的基准测试通常期望公式以完整的LaTeX形式呈现。

局限性

  • Unicode或部分渲染的公式会受到惩罚。
  • 使用不同宏的等效LaTeX表达式无法匹配。
  • 不处理混合的LaTeX/Markdown/HTML表示。
  • 渲染正确的公式仍可能在字符串级别检查中失败。

这混淆了表示形式的选择与数学正确性。

4. 特定格式假设

基准测试隐含地编码了偏好的输出风格。

局限性

  • HTML标签(例如 <sub>)会导致匹配失败。
  • Unicode符号(例如 km²)相对于LaTeX等效形式会受到惩罚。
  • 真实数据中空格和标点符号的不一致会放大错误。
  • 符合基准测试格式的模型比更通用的OCR系统得分更高。

现有基准测试中观察到的问题

基准测试A: olmOCRBench

人工检查发现,几个子集嵌入了隐含的内容省略规则:

  • 文档中明显存在的页眉、页脚和水印,在真实数据中被明确标记为应不存在。
  • 旨在提取所有可见文本的模型,因其正确提取而受到惩罚。

这些子集实际上评估的是选择性抑制能力,而不是OCR质量。

此外:

  • 当公式不是完全归一化的LaTeX时,侧重数学的子集就会失败。
  • 由于表示形式的差异,正确的预测也会受到惩罚。

因此,分数在很大程度上取决于模型的输出理念是否符合基准测试的隐藏假设。

示例1

对于上图,某OCR2 模型正确预测了图像右侧的水印,但在真实数据标注中,因正确预测而受到惩罚。

{
"pdf": "headers_footers/ef5e1f5960b9f865c8257f9ce4ff152a13a2559c_page_26.pdf", 
"page": 1, 
"id": "ef5e1f5960b9f865c8257f9ce4ff152a13a2559c_page_26.pdf_manual_01", 
"type": "absent", 
"text": "Document t\\u00e9l\\u00e9charg\\u00e9 depuis www.cairn.info - Universit\\u00e9 de Marne-la-Vall\\u00e9e - - 193.50.159.70 - 20/03/2014 09h07. \\u00a9 S.A.C.", "case_sensitive": false, "max_diffs": 3, "checked": "verified", "first_n": null, "last_n": null, "url": "<https://hal-enpc.archives-ouvertes.fr/hal-01183663/file/14-RAC-RecitsDesTempsDHier.pdf>"}

类型为 absent 意味着在预测数据中,该文本不应存在。

示例2

该基准测试也未考虑文档页脚中出现的文本。

例如在此文档中,根据真实数据,Alcoholics Anonymous\\u00aewww.aa.org 不应出现在文档中,这是不正确的。

{
	"pdf": "headers_footers/3754542bf828b42b268defe21db8526945928834_page_4.pdf", 
	"page": 1, 
	"id": "3754542bf828b42b268defe21db8526945928834_page_4_header_00", 
	"type": "absent", 
	"max_diffs": 0, 
	"checked": "verified", 
	"url": "<https://www.aa.org/sites/default/files/literature/PI%20Info%20Packet%20EN.pdf>", 
	"text": "Alcoholics Anonymous\\u00ae", 
	"case_sensitive": false, "first_n": null, "last_n": null
	}
{
	"pdf": "headers_footers/3754542bf828b42b268defe21db8526945928834_page_4.pdf", 
	"page": 1, 
	"id": "3754542bf828b42b268defe21db8526945928834_page_4_header_01", 
	"type": "absent", 
	"max_diffs": 0, 
	"checked": "verified", 
	"url": "<https://www.aa.org/sites/default/files/literature/PI%20Info%20Packet%20EN.pdf>", 
	"text": "www.aa.org", 
	"case_sensitive": false, "first_n": null, "last_n": null}

基准测试B: OmniDocBench

OmniDocBench 表现出类似的问题,但范围更广:

  • 公式评估依赖于严格的LaTeX字符串等效性。
  • 语义相同的公式因宏、空格或符号差异而失败。
  • 观察到大量真实数据标注错误(缺失标记、数学格式错误、间距不正确)。
  • Unicode规范化和间距差异系统性地降低了分数。
  • 即使正确答案完全存在,预测选择启发式算法也可能失败。

在许多情况下,低分反映的是基准测试本身的缺陷,而非模型错误。

示例1

在上面的例子中,某OCR2模型预测为 5 g silica + 3 g Al$_2$O$_3$,但真实数据期望为 $ 5g \\\\mathrm{\\\\ s i l i c a}+3g \\\\mathrm{\\\\ A l}*{2} \\\\mathrm{O*{3}} $。即使两者都正确,这也会将模型预测标记为错误。

完整的真实数据、预测和测试用例如下:

'pred': 'The collected eluant was concentrated by rotary evaporator to 1 ml. The extracts were finally passed through a final column filled with 5 g silica + 3 g Al$_2$O$_3$ to remove any co-extractive compounds that may cause instrumental interferences durin the analysis. The extract was eluted with 120 ml of DCM:n-hexane (1:1), the first 18 ml of eluent was discarded and the rest were collected, which contains the analytes of interest. The extract was exchanged into n-hexane, concentrated to 1 ml to which 1 μg/ml of internal standard was added.'
'gt': 'The collected eluant was concentrated by rotary evaporator to 1 ml .The extracts were finally passed through a final column filled with $ 5g \\\\mathrm{\\\\ s i l i c a}+3g \\\\mathrm{\\\\ A l}*{2} \\\\mathrm{O*{3}} $ to remove any co-extractive compounds that may cause instrumental
interferences during the analysis. The extract was eluted with 120 ml of DCM:n-hexane (1:1), the first 18 ml of eluent was discarded and the rest were collected, which contains the analytes of interest. The extract was exchanged into n - hexane, concentrated to 1 ml to which $ \\\\mu\\\\mathrm{g / ml} $ of internal standard was added.'

示例2

在OmniDocBench中发现了明显更多的错误标注。在真实数据标注中,1 ml 里的 1 缺失了。

'text': 'The collected eluant was concentrated by rotary evaporator to 1 ml .The extracts were finally passed through a final column filled with $ 5g \\\\mathrm{\\\\ s i l i c a}+3g \\\\mathrm{\\\\ A l}*{2} \\\\mathrm{O*{3}} $ to remove any co-extractive compounds that may cause instrumental interferences during the analysis. The extract was eluted with 120 ml of DCM:n-hexane (1:1), the first 18 ml of eluent was discarded and the rest were collected, which contains the analytes of interest. The extract was exchanged into n - hexane, concentrated to 1 ml to which $ \\\\mu\\\\mathrm{g / ml} $ of internal standard was added.'
```FINISHED