> ## Content Index
> Fetch the complete content index at: https://www.hubwiz.com/blog/llms.txt
> Use this file to discover other available public pages before exploring further.

# 用MonkeyOCR提取结构化数据
- URL: https://www.hubwiz.com/blog/extract-structured-data-with-monkeyocr/
- Published: 2025-06-17T01:48:10.000Z
- Updated: 2025-06-17T01:48:10.000Z
- Description: MonkeyOCR是一个视觉语言模型，能够智能地解析收据、发票、表格和其他无结构的文档图像，将其转换为干净的结构化数据。
- Author: admin
- Tags: MODEL-ZOO, MONKEYOCR, OCR, #Import 2026-10-14 14:41

在文档理解不断发展的世界中，OCR与大型语言模型（LLMs）的融合开启了前所未有的能力。Hugging Face上有一个令人兴奋的开源模型是[MonkeyOCR](https://huggingface.co/echo840/MonkeyOCR?ref=hubwiz.com)，这是一个视觉语言系统，旨在智能地解析收据、发票、表格和其他无结构的文档图像，将其转换为干净的结构化数据。

## 1、什么是MonkeyOCR？

**MonkeyOCR** 是一个基于LLM的OCR模型，它超越了文本检测。它理解文档的**结构**、**布局**和**语义**，并可以以**JSON格式**输出数据，使其非常适合：

- 发票解析
- 收据数字化
- 身份文件提取
- 企业文档处理工作流

MonkeyOCR的关键特性：

- **端到端文档理解**
- 结构化输出（例如，JSON或键值对）
- 基于视觉语言架构构建（例如，Donut、LayoutLM或Pix2Struct）
- 处理布局、字体和噪声的变化
- 可部署用于实际的发票、收据和PDF解析用例

## 2、在Python中使用MonkeyOCR

> *以下假设模型是一个Hugging Face兼容的VisionEncoderDecoder或其他类似架构。*

```
from transformers import DonutProcessor, VisionEncoderDecoderModel  
from PIL import Image  
import torch  

# 加载MonkeyOCR模型和处理器  
processor = DonutProcessor.from_pretrained("echo840/MonkeyOCR")  
model = VisionEncoderDecoderModel.from_pretrained("echo840/MonkeyOCR")  
model.to("cuda" if torch.cuda.is_available() else "cpu")  

# 加载图像  
image = Image.open("receipt_sample.jpg").convert("RGB")  
pixel_values = processor(image, return_tensors="pt").pixel_values  

# 运行推理  
decoder_input_ids = processor.tokenizer("<s>", add_special_tokens=False, return_tensors="pt").input_ids  
output = model.generate(pixel_values, decoder_input_ids=decoder_input_ids, max_length=512)  

# 解码  
result = processor.batch_decode(output, skip_special_tokens=True)[0]  
print("📄 提取的JSON:")  
print(result)

```

示例输出：

```
{  
  "vendor": "星巴克",  
  "date": "2025-06-11",  
  "total": "$7.75",  
  "items": [  
    {"name": "拿铁", "price": "$4.50"},  
    {"name": "羊角面包", "price": "$3.25"}  
  ]  
}

```

应用场景：

- **费用跟踪**自动化
- **扫描收据的数字记账**
- **客户入职流程中的ID解析**
- 输入LLM链和AI代理（通过LangChain、RAG等）

## 3、模型架构（假设）

MonkeyOCR可能基于一种**Donut风格的编码器-解码器**，其中：

- 图像由视觉Transformer（ViT）编码
- 文本由语言模型自回归解码
- 最终输出通过提示控制模板进行结构化

这使得它通用且可与其他管道组合使用。

## 4、结束语

MonkeyOCR代表了一种新的LLM驱动的OCR工具浪潮——这些工具不仅读取文本，还理解文档。无论你是在构建企业自动化管道、文档助手，还是只是想从收据中提取干净的JSON，**Hugging Face上的MonkeyOCR是一个很好的起点**。

---

原文链接：[MonkeyOCR: Extracting Structured Data from Documents with Vision-Language Models](https://medium.com/@bravekjh/monkeyocr-extracting-structured-data-from-documents-with-vision-language-models-8cdfe5046bb7?ref=hubwiz.com)

汇智网翻译整理，转载请标明出处