非構造化データ用のオープンソースの前処理ツール
unstructuredライブラリは、PDF、HTML、Word Docsなどの画像やテキストドキュメントを摂取および前処理するためのオープンソースコンポーネントを提供します。 unstructuredのユースケースは、LLMのデータ処理ワークフローの合理化と最適化を中心に展開します。 unstructuredモジュラー関数とコネクタは、データの摂取と前処理を簡素化する凝集システムを形成し、異なるプラットフォームに適応できるようにし、構造化された出力に非構造化されたデータを変換するのに効率的になります。
より良い前処理パフォーマンスとセットアップの減少をお探しですか?新しいサーバーレスAPIをご覧ください!構造化されていないサーバーレスAPIは、これまでで最もパフォーマンスのあるAPIであり、ビジネスとLLMのニーズをよりよくサポートするために、より応答性の高い生産級のソリューションを提供します。無料で開始するには、サインアップページページにアクセスしてください。
unstructuredライブラリを使用する方法はいくつかあります。
condaを使用してインストールするには、ドキュメントを参照してください以下の指示は、Dockerを使用して立ち上がって実行して、 unstructuredと対話するのに役立つことを目的としています。マシンにまだDockerをインストールしていない場合は、こちらをご覧ください。
注:X86_64とAppleシリコンハードウェアの両方をサポートするマルチプラットフォーム画像を構築します。 docker pullアーキテクチャの対応する画像をダウンロードする必要がありますが、必要に応じて--platform (例えば--platform linux/amd64 )を指定できます。
mainへのすべてのプッシュ用のDocker画像を作成します。各画像に、対応する短いコミットハッシュ( fbc7a69など)とアプリケーションバージョン(Eg 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であり、定期的に更新されていることに注意してください。地元で画像を構築している場合、 wolfi-baseの上流の変化によりdocker-build失敗する可能性があります。
1つのタイプのデータを解析することを計画している場合、他のデータ型に必要なパッケージ/要件の一部にコメントすることで、画像の構築をスピードアップできます。 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 unstructuredて実行できますpip install "unstructured[docx,pptx]"など、これらのドキュメントに必要なエクストラをインストールできます。システムでまだ利用できない場合は、次のシステム依存関係をインストールします。解析するドキュメントタイプに応じて、これらすべてを必要としない場合があります。
libmagic-dev (filetype検出)poppler-utils (画像とPDF)tesseract-ocr (画像とPDFS、追加の言語サポートのためにtesseract-langをインストール)libreoffice (MS Office Docs)pandoc (Epubs、RTFS、Open Office Docs)。 RTFファイルを処理するには、バージョン2.14.2以降が必要であることに注意してください。 make install-pandocまたは./scripts/install-pandoc.shいずれかを実行すると、正しいバージョンがインストールされます。Windowsにインストールする方法や他の機能の依存関係について学ぶ方法についての提案については、こちらのインストールドキュメントを参照してください。
この時点で、次のコードを実行できるはずです。
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 virtualenvを作成して作業して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を使用している場合は、上記のmake installの一部として事前pre-commitパッケージがインストールされているため、 pre-commit installにフックをインストールするだけです。最後に、 pre-commitを使用することにした場合はpre-commit uninstallでフックをアンインストールすることもできます。
お近くのOSで開発することに加えて、開発環境を提供するDockerを使用するヘルパーも提供します。
make docker-start-devこれにより、ローカルリポジトリが/mnt/local_unstructuredに取り付けられたドッカーコンテナが起動します。このDocker画像を使用すると、OSとリポジトリとの依存関係を心配することなく開発できます。
より包括的なドキュメントについては、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" ) run 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コマンドを使用して、システムの環境情報を収集し、レポートに含めてください。あなたの支援は私たちがソフトウェアを継続的に改善するのに役立ちます - ありがとう!
| セクション | 説明 |
|---|---|
| 会社のウェブサイト | Untructured.io製品および会社情報 |
| ドキュメント | 完全なAPIドキュメント |
| バッチ処理 | 非構造化されたドキュメントのバッチを摂取します |
Scarf(https://scarf.sh)と提携して、匿名化されたユーザー統計を収集して、コミュニティが使用している機能と将来製品の意思決定を優先する方法を理解しています。このデータの収集と使用方法の詳細については、プライバシーポリシーをお読みください。このデータ収集をオプトアウトするには、 unstructuredコマンドを実行する前に、環境変数SCARF_NO_ANALYTICS=trueを設定できます。