非结构化数据的开源预处理工具
unstructured库提供了用于摄入和预处理图像和文本文档的开源组件,例如PDFS,HTML,Word Docs等。 unstructured的用例围绕精简和优化LLM的数据处理工作流程。 unstructured模块化功能和连接器形成了一个凝聚系统,可简化数据摄入和预处理,使其适应不同的平台,并有效地将非结构化数据转换为结构化输出。
寻找更好的预处理性能和更少的设置?查看我们的新无服务器API!非结构化的无服务器API是我们迄今为止最出色的API,它提供了一种更快的生产级解决方案,以更好地满足您的业务和LLM需求。前往我们的注册页面,免费入门。
有几种使用unstructured库的方法:
conda安装的,请参考文档以下说明旨在帮助您使用Docker与unstructured交互。如果您还没有在计算机上安装Docker,请参阅此处。
注意:我们构建多平台图像以支持X86_64和Apple Silicon硬件。 docker pull应该下载架构的相应图像,但是您可以使用--platform (例如--platform linux/amd64 )指定。
我们为所有推送到main构建了Docker图像。我们使用相应的简短提交哈希(例如fbc7a69 )和应用程序版本(例如0.5.5-dev1 )标记每个图像。我们还使用最新图像标记latest 。为了利用这一点, docker pull 。
docker pull downloads.unstructured.io/unstructured-io/unstructured:latest拉动后,您可以从此图像创建一个容器,然后将其掩盖到其上。
# create the container
docker run -dt --name unstructured downloads.unstructured.io/unstructured-io/unstructured:latest
# this will drop you into a bash shell where the Docker image is running
docker exec -it unstructured bash您还可以构建自己的Docker映像。请注意,基本图像是wolfi-base ,它会定期更新。如果您在本地构建图像,则可能由于docker-build wolfi-base的上游变化而可能会失败。
如果您仅计划解析一种数据,则可以通过评论其他数据类型所需的一些软件包/要求来加快构建图像的速度。请参阅Dockerfile,以了解您的用例所需的线条。
make docker-build
# this will drop you into a bash shell where the Docker image is running
make docker-start-bash进入运行容器后,您可以直接以Python解释器的交互式模式尝试使用事物。
# this will drop you into a python console so you can run the below partition functions
python3
>>> from unstructured.partition.pdf import partition_pdf
>>> elements = partition_pdf(filename= " example-docs/layout-parser-paper-fast.pdf " )
>>> from unstructured.partition.text import partition_text
>>> elements = partition_text(filename= " example-docs/fake-text.txt " )使用以下说明与unstructured并测试安装。
安装Python SDK以使用pip install "unstructured[all-docs]"来支持所有文档类型
pip install unstructuredpip install "unstructured[docx,pptx]"如果系统尚未在系统上可用,请安装以下系统依赖项。根据您正在解析的文档类型,您可能不需要所有这些。
libmagic-dev (Filetype检测)poppler-utils (图像和PDF)tesseract-ocr (图像和PDF,安装tesseract-lang以获得其他语言支持)libreoffice (MS Office Docs)pandoc (EPUB,RTF和开放式文档)。请注意,要处理RTF文件,您需要2.14.2版或更新版本。运行make install-pandoc或./scripts/install-pandoc.sh将为您安装正确的版本。有关如何在窗口上安装并了解其他功能的依赖项的建议,请参见此处的安装文档。
此时,您应该能够运行以下代码:
from unstructured . partition . auto import partition
elements = partition ( filename = "example-docs/eml/fake-email.eml" )
print ( " n n " . join ([ str ( el ) for el in elements ]))如果您打算为该项目做出贡献,则旨在帮助您在本地使用unstructured本地启动和运行。
建议使用pyenv管理Virtualenv,但不是必需的
brew install pyenv-virtualenvpyenv install 3.10创建一个虚拟的工作并激活它,例如,一个名为unstructured人:
pyenv virtualenv 3.10 unstructured
pyenv activate unstructured
运行make install
选修的:
make install-local-inference 。tesseract 。请参阅此处以获取安装说明。tesseract和poppler 。 PDF2Image文档有有关在各个平台上安装poppler的说明。此外,如果您打算为unstructured做出贡献,我们为您提供一个可选的pre-commit配置文件,以确保您的代码与unstructured中使用的格式和覆盖标准匹配。如果您希望在每个提交之前都不要将代码更改自动介绍,则可以使用make check来查看是否应应用任何贴有或格式化更改,并make tidy应用它们。
如果使用可选的pre-commit ,则只需安装pre-commit install即可安装挂钩,因为在上面提到的make install中安装了pre-commit软件包。最后,如果您决定使用pre-commit您也可以使用pre-commit uninstall 。
除了在您的本地操作系统中开发外,我们还提供了一个助手,可以使用提供开发环境的Docker:
make docker-start-dev这启动了一个docker容器,并将您的本地存储库安装到/mnt/local_unstructured 。此Docker映像使您可以开发不担心操作系统与存储库及其依赖关系的兼容性。
有关更全面的文档,请访问https://docs.unstructured.io。您还可以在文档页面(包括我们的SaaS API)上了解有关我们的其他产品的更多信息。
以下是开源文档页面中的几页,这些页面有助于新用户审查:
unstructured开源软件包以下示例显示了如何开始使用unstructured库。在非结构化中解析文档的最简单方法是使用partition功能。如果使用partition功能, unstructured将检测到文件类型并将其路由到适当的文件特定分区功能。如果您使用的是partition功能,则可能需要安装每个文档类型的其他依赖项。例如,要安装DOCX依赖项,您需要运行pip install "unstructured[docx]" 。有关更多详细信息,请参见我们的安装指南。
from unstructured . partition . auto import partition
elements = partition ( "example-docs/layout-parser-paper.pdf" )运行print("nn".join([str(el) for el in elements]))以获取输出的字符串表示,看起来像:
LayoutParser : A Unified Toolkit for Deep Learning Based Document Image Analysis
Zejiang Shen 1 ( (cid:0) ), Ruochen Zhang 2 , Melissa Dell 3 , Benjamin Charles Germain Lee 4 , Jacob Carlson 3 , and
Weining Li 5
Abstract. Recent advances in document image analysis (DIA) have been primarily driven by the application of neural
networks. Ideally, research outcomes could be easily deployed in production and extended for further investigation.
However, various factors like loosely organized codebases and sophisticated model configurations complicate the easy
reuse of important innovations by a wide audience. Though there have been ongoing efforts to improve reusability and
simplify deep learning (DL) model development in disciplines like natural language processing and computer vision, none
of them are optimized for challenges in the domain of DIA. This represents a major gap in the existing toolkit, as DIA
is central to academic research across a wide range of disciplines in the social sciences and humanities. This paper
introduces LayoutParser, an open-source library for streamlining the usage of DL in DIA research and applications.
The core LayoutParser library comes with a set of simple and intuitive interfaces for applying and customizing DL models
for layout detection, character recognition, and many other document processing tasks. To promote extensibility,
LayoutParser also incorporates a community platform for sharing both pre-trained models and full document digitization
pipelines. We demonstrate that LayoutParser is helpful for both lightweight and large-scale digitization pipelines in
real-word use cases. The library is publicly available at https://layout-parser.github.io
Keywords: Document Image Analysis · Deep Learning · Layout Analysis · Character Recognition · Open Source library ·
Toolkit.
Introduction
Deep Learning(DL)-based approaches are the state-of-the-art for a wide range of document image analysis (DIA) tasks
including document image classification [11,
有关如何使用特定文件分区功能的选项和说明的完整列表,请参见我们文档中的分区部分。
有关如何报告安全漏洞的信息,请参见我们的安全策略。
遇到一个错误?请创建一个新的GitHub问题,并使用我们的错误报告模板来描述问题。为了帮助我们诊断该问题,请使用python scripts/collect_env.py命令来收集系统的环境信息并将其包括在报告中。您的帮助有助于我们不断改进我们的软件 - 谢谢!
| 部分 | 描述 |
|---|---|
| 公司网站 | 非结构化。oio产品和公司信息 |
| 文档 | 完整的API文档 |
| 批处理处理 | 通过非结构化摄入文档批次 |
我们已经与围巾(https://scarf.sh)合作,以收集匿名用户统计信息,以了解我们社区正在使用哪些功能以及如何在将来确定产品决策的优先级。要了解有关我们如何收集和使用此数据的更多信息,请阅读我们的隐私政策。要选择退出此数据集合,您可以在运行任何unstructured命令之前设置环境变量SCARF_NO_ANALYTICS=true 。