Unstructured-IO/unstructured

GitHub: Unstructured-IO/unstructured

该项目是一个开源的非结构化数据预处理工具,致力于将复杂文档转换为适合语言模型使用的结构化格式。

Stars: 15133 | Forks: 1270

![https://pypi.python.org/pypi/unstructured/](https://img.shields.io/pypi/l/unstructured.svg) ![https://pypi.python.org/pypi/unstructured/](https://img.shields.io/pypi/pyversions/unstructured.svg) ![https://GitHub.com/unstructured-io/unstructured.js/graphs/contributors](https://img.shields.io/github/contributors/unstructured-io/unstructured) ![code_of_conduct.md](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg) ![https://GitHub.com/unstructured-io/unstructured.js/releases](https://img.shields.io/github/release/unstructured-io/unstructured) ![https://github.com/Naereen/badges/](https://badgen.net/badge/Open%20Source%20%3F/Yes%21/blue?icon=github) [![下载量](https://static.pepy.tech/badge/unstructured)](https://pepy.tech/project/unstructured) [![下载量](https://static.pepy.tech/badge/unstructured/month)](https://pepy.tech/project/unstructured)

非结构化数据的开源预处理工具

`unstructured` 库提供了开源组件,用于摄取和预处理图像及文本文档,例如 PDF、HTML、Word 文档以及[更多其他格式](https://docs.unstructured.io/open-source/core-functionality/partitioning)。`unstructured` 的使用场景主要围绕为 LLM 简化和优化数据处理工作流。`unstructured` 的模块化函数和连接器形成了一个紧密的系统,简化了数据摄取和预处理的过程,使其能够适应不同的平台,并高效地将非结构化数据转换为结构化输出。 ## :eight_pointed_black_star: 快速开始 有几种方法可以使用 `unstructured` 库: * [在容器中运行该库](https://github.com/Unstructured-IO/unstructured#run-the-library-in-a-container) 或 * 安装该库 1. [从 PyPI 安装](https://github.com/Unstructured-IO/unstructured#installing-the-library) 2. [为本地开发安装](https://github.com/Unstructured-IO/unstructured#installation-instructions-for-local-development) * 若要在 Windows 系统上使用 `conda` 进行安装,请参阅[文档](https://unstructured-io.github.io/unstructured/installing.html#installation-with-conda-on-windows) ### 在容器中运行该库 以下说明旨在帮助您使用 Docker 启动并运行 `unstructured` 以进行交互。 如果您的机器上尚未安装 docker,请参见[此处](https://docs.docker.com/get-docker/)。 注意:我们构建了多平台镜像,以同时支持 x86_64 和 Apple 芯片硬件。`docker pull` 应该会下载与您的架构相对应的镜像,但如果需要,您可以使用 `--platform`(例如 `--platform linux/am64`)进行指定。 我们会为所有推送到 `main` 的代码构建 Docker 镜像。我们使用相应的简短 commit hash(例如 `fbc7a69`)和应用程序版本(例如 `0.5.5-dev1`)为每个镜像打上标签。我们还会使用 `latest` 标签标记最新的镜像。为了利用这一点,请从我们的镜像仓库中执行 `docker pull`。 ``` docker pull downloads.unstructured.io/unstructured-io/unstructured:latest ``` 拉取完成后,您可以使用此镜像创建一个容器并进入其 shell。 ``` # 创建容器 docker run -dt --name unstructured downloads.unstructured.io/unstructured-io/unstructured:latest # 这将让你进入一个正在运行 Docker image 的 bash shell docker exec -it unstructured bash ``` 您也可以构建自己的 Docker 镜像。请注意,基础镜像是 `wolfi-base`,它会 定期更新。如果您在本地构建镜像,由于 `wolfi-base` 的上游更改, `docker-build` 可能会失败。 如果您只打算解析一种类型的数据,可以通过注释掉其他数据类型所需的某些 包/依赖项来加快镜像构建速度。请查看 Dockerfile 以了解哪些行是您的用例所必需的。 ``` make docker-build # 这将让你进入一个正在运行 Docker image 的 bash shell make docker-start-bash ``` 进入运行中的容器后,您可以直接在 Python 解释器的交互模式下进行尝试。 ``` # 这将让你进入一个 python 控制台,以便你可以运行以下 partition 函数 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`,并测试您的安装。 - 通过 `pip install "unstructured[all-docs]"` 安装支持所有文档类型的 Python SDK - 对于不需要任何额外依赖项的纯文本文件、HTML、XML、JSON 和电子邮件,您可以运行 `pip install unstructured` - 要处理其他文档类型,您可以安装这些文档所需的额外依赖项,例如 `pip install "unstructured[docx,pptx]"` - 如果您的系统上尚未提供以下系统依赖项,请安装它们。 根据您要解析的文档类型,您可能不需要所有这些依赖项。 - `libmagic-dev`(文件类型检测) - `poppler-utils`(图像和 PDF) - `tesseract-ocr`(图像和 PDF,安装 `tesseract-lang` 以获得额外的语言支持) - `libreoffice`(MS Office 文档) - `pandoc` 通过 `pypandoc-binary` Python 包自动捆绑(无需系统安装) - 有关如何在 Windows 上安装的建议以及了解其他功能的依赖项,请参阅 此处的安装文档[链接](https://unstructured-io.github.io/unstructured/installing.html)。 此时,您应该能够运行以下代码: ``` 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`。 该项目使用 [uv](https://docs.astral.sh/uv/) 进行依赖项管理。请先安装它: ``` # macOS / Linux curl -LsSf https://astral.sh/uv/install.sh | sh ``` 然后安装所有依赖项(基础、额外、开发、测试和 lint 组): ``` make install ``` 这将运行 `uv sync --locked --all-extras --all-groups`,它将创建一个虚拟环境 并一步完成所有安装。无需手动创建或激活 virtualenv。 要仅安装特定的文档类型额外依赖项: ``` uv sync --extra pdf uv sync --extra csv --extra docx ``` 在更改 `pyproject.toml` 中的依赖项后更新 lock file: ``` make lock ``` * 可选操作: * 要安装用于本地处理图像和 PDF 的额外依赖项,请运行 `uv sync --extra pdf --extra image`。 * 处理图像文件需要用到 `tesseract`。请参阅[此处](https://tesseract-ocr.github.io/tessdoc/Installation.html)获取安装说明。 * 处理 PDF 文件需要用到 `tesseract` 和 `poppler`。[pdf2image 文档](https://pdf2image.readthedocs.io/en/latest/installation.html)提供了在不同平台上安装 `poppler` 的说明。 此外,如果您计划为 `unstructured` 做出贡献,我们提供了一个可选的 `pre-commit` 配置 文件,以确保您的代码符合 `unstructured` 中使用的格式化和 linting 标准。 如果您不希望每次提交前都自动整理代码更改,可以使用 `make check` 来查看 是否应该应用任何 linting 或格式化更改,并使用 `make tidy` 来应用它们。 如果使用可选的 `pre-commit`,您只需使用 `pre-commit install` 安装 hooks,因为 `pre-commit` 包已作为上述 `make install` 的一部分安装。最后,如果您决定使用 `pre-commit`, 您还可以通过 `pre-commit uninstall` 卸载 hooks。 除了在您的本地操作系统上进行开发外,我们还提供了一个使用 docker 的辅助工具来提供开发环境: ``` make docker-start-dev ``` 这将启动一个 docker 容器,并将您的本地仓库挂载到 `/mnt/local_unstructured`。此 docker 镜像允许您进行开发,而无需担心您的操作系统与仓库及其依赖项的兼容性问题。 ## :clap: 快速导览 ### 文档 如需更全面的文档,请访问 https://docs.unstructured.io 。您还可以在文档页面上了解更多关于我们其他产品的信息,包括我们的 SaaS API。 以下是[开源文档页面](https://docs.unstructured.io/open-source/introduction/overview)中的几个页面, 对新用户的查阅非常有帮助: - [快速开始](https://docs.unstructured.io/open-source/introduction/quick-start) - [使用 `unstructured` 开源包](https://docs.unstructured.io/open-source/core-functionality/overview) - [连接器](https://docs.unstructured.io/open-source/ingest/overview) - [基本概念](https://docs.unstructured.io/open-source/concepts/document-elements) - [集成](https://docs.unstructured.io/open-source/integrations) ### PDF 文档解析示例 以下示例展示了如何开始使用 `unstructured` 库。在 unstructured 中解析文档最简单的方法是使用 `partition` 函数。如果您使用 `partition` 函数,`unstructured` 会检测文件类型,并将其路由到适当的特定文件分区函数。如果您使用 `partition` 函数,您可能需要根据文档类型安装额外的依赖项。 例如,要安装 docx 依赖项,您需要运行 `pip install "unstructured[docx]"`。 有关更多详细信息,请参阅我们的[安装指南](https://docs.unstructured.io/open-source/installation/full-installation)。 ``` from unstructured.partition.auto import partition elements = partition("example-docs/layout-parser-paper.pdf") ``` 运行 `print("\n\n".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, ``` 请参阅我们文档中的 [partitioning](https://docs.unstructured.io/open-source/core-functionality/partitioning) 部分,获取完整的选项列表以及有关如何使用特定文件分区函数的说明。 ## :guardsman: 安全策略 请参阅我们的[安全策略](https://github.com/Unstructured-IO/unstructured/security/policy), 了解有关如何报告安全漏洞的信息。 ## :bug: 报告 Bug 遇到 bug?请创建一个新的 [GitHub issue](https://github.com/Unstructured-IO/unstructured/issues/new/choose) 并使用我们的 bug 报告模板来描述问题。为了帮助我们诊断问题,请使用 `python scripts/collect_env.py` 命令收集您系统的环境信息,并将其包含在报告中。您的协助有助于我们不断改进软件——谢谢! ## :books: 了解更多 | 部分 | 描述 | |-|-| | [公司网站](https://unstructured.io) | Unstructured.io 产品和公司信息 | | [文档](https://docs.unstructured.io/) | 完整的 API 文档 | | [批量处理](https://github.com/Unstructured-IO/unstructured-ingest) | 通过 Unstructured 摄取批次文档 | ## :chart_with_upwards_trend: 分析 遥测**默认关闭**。要选择启用,请在导入 `unstructured` 之前设置 `UNSTRUCTURED_TELEMETRY_ENABLED=true`(或 `=1`)。要选择停用,请将 `DO_NOT_TRACK` 或 `SCARF_NO_ANALYTICS` 设置为任何非空值(例如 `true`、`1`、`yes`、`false`、`0` —— 任何非空字符串都会选择停用);选择停用优先。如果您不想选择停用,请取消设置该变量或将其留空。请参阅我们的[隐私政策](https://unstructured.io/privacy-policy)。
标签:DLL 劫持, ETL, JavaCC, Python, RAG, 后端开发, 大语言模型, 文档解析, 无后门, 请求拦截, 逆向工具