Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring PDF loaders: all #28970

Draft
wants to merge 26 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4f4d79e
Refactoring all PDF loader and parser
pprados Dec 30, 2024
3315af6
Refactoring all PDF loader and parser
pprados Dec 30, 2024
5ab608a
cli: bump gritql version (#28981)
morgante Jan 2, 2025
2fc4c6b
infra: speed up unit tests (#28974)
baskaryan Jan 2, 2025
f13bde7
docs: Remove redundant word for improved sentence fluency (#28975)
YanzhongSu Jan 2, 2025
931229f
docs: Minor typo fixed, install necessary pip (#28976)
satheshshiva Jan 2, 2025
224a6e9
docs: add modelscope endpoint (#28941)
Yunnglin Jan 2, 2025
4f3025d
community[patch]: fix instantiation for Slack tools (#28990)
ccurme Jan 2, 2025
f2f78da
(Community): Fix Keyword argument for `AzureAIDocumentIntelligencePar…
keenborder786 Jan 2, 2025
942848e
docs: Update streaming.mdx (#28985)
Muhammad-Mouta Jan 2, 2025
765199d
langchain.agents: corrected documentation (#28986)
hrishi-008 Jan 2, 2025
efd3687
community: update documentation and model IDs for FriendliAI provider…
minpeter Jan 2, 2025
f9a943f
(Core) Small Change in Docstring for method `partial` for `BasePrompt…
keenborder786 Jan 2, 2025
4d05358
docs: update multi_vector.ipynb (#28954)
eltociear Jan 2, 2025
ba11c7b
docs: Remove deprecated `schema()` usage in examples (#28956)
SaeedHassanvand Jan 2, 2025
b5ab049
(Community): `DuckDuckGoSearchAPIWrapper` backend changed from `api` …
keenborder786 Jan 2, 2025
e9d9327
docs: fix typo in how-to guides (#28951)
YanzhongSu Jan 2, 2025
eb5a509
core[patch]: fix deprecation admonition in API ref (#28992)
ccurme Jan 2, 2025
f76aab3
community: Update azureml endpoint (#28953)
ashvin-a Jan 2, 2025
f980513
docs[patch]: fix link (#28994)
ccurme Jan 2, 2025
20c599e
docs: Add FalkorDB Chat Message History and Update Package Registry (…
kingtroga Jan 2, 2025
4344ec0
docs: Add FAISS Filter with Advanced Query Operators Documentation & …
RuofanChen03 Jan 2, 2025
523bd46
docs: add stripe toolkit (#28122)
efriis Jan 3, 2025
5b0eba0
Docs: Add 'Optional' to installation section to fix an issue (#28902)
ahmadelmalah Jan 3, 2025
d9a1b0c
Update PyPDF
pprados Jan 3, 2025
54f3303
Merge branch 'master' into pprados/pdf_loaders
pprados Jan 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
564 changes: 375 additions & 189 deletions docs/docs/how_to/document_loader_custom.ipynb

Large diffs are not rendered by default.

841 changes: 325 additions & 516 deletions docs/docs/how_to/document_loader_pdf.ipynb

Large diffs are not rendered by default.

2,083 changes: 2,033 additions & 50 deletions docs/docs/integrations/document_loaders/pdfminer.ipynb

Large diffs are not rendered by default.

1,105 changes: 1,069 additions & 36 deletions docs/docs/integrations/document_loaders/pdfplumber.ipynb

Large diffs are not rendered by default.

1,148 changes: 1,114 additions & 34 deletions docs/docs/integrations/document_loaders/pymupdf.ipynb

Large diffs are not rendered by default.

108 changes: 76 additions & 32 deletions docs/docs/integrations/document_loaders/pypdfdirectory.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# PyPDFDirectoryLoader\n",
"# PyPDFDirectoryLoader (Deprecated)\n",
"\n",
"Note: This loader is deprecated. Please use [GenericLoader](https://python.langchain.com/docs/how_to/document_loader_custom/#overview) instead.\n",
"\n",
" \n",
"\n",
"This loader loads all PDF files from a specific directory.\n",
"\n",
Expand Down Expand Up @@ -36,13 +40,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"metadata": {
"ExecuteTime": {
"end_time": "2024-12-13T14:39:11.095053Z",
"start_time": "2024-12-13T14:39:11.081014Z"
}
},
"source": [
"# os.environ[\"LANGSMITH_API_KEY\"] = getpass.getpass(\"Enter your LangSmith API key: \")\n",
"# os.environ[\"LANGSMITH_TRACING\"] = \"true\""
]
],
"outputs": [],
"execution_count": 7
},
{
"cell_type": "markdown",
Expand All @@ -55,12 +64,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"metadata": {
"ExecuteTime": {
"end_time": "2024-12-13T14:39:24.982355Z",
"start_time": "2024-12-13T14:39:11.169779Z"
}
},
"source": [
"%pip install -qU langchain_community"
]
"%pip install -qU langchain_community pypdf pillow\n",
"%pip install -qq ../../../../dist/patch_langchain_pdf_loader*.whl"
],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Note: you may need to restart the kernel to use updated packages.\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"execution_count": 8
},
{
"cell_type": "markdown",
Expand All @@ -73,17 +97,22 @@
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"metadata": {
"ExecuteTime": {
"end_time": "2024-12-13T14:39:25.087581Z",
"start_time": "2024-12-13T14:39:25.071818Z"
}
},
"source": [
"from langchain_community.document_loaders import PyPDFDirectoryLoader\n",
"\n",
"directory_path = (\n",
" \"../../docs/integrations/document_loaders/example_data/layout-parser-paper.pdf\"\n",
")\n",
"loader = PyPDFDirectoryLoader(\"example_data/\")"
]
],
"outputs": [],
"execution_count": 9
},
{
"cell_type": "markdown",
Expand All @@ -94,41 +123,51 @@
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-12-13T14:39:26.846482Z",
"start_time": "2024-12-13T14:39:25.235776Z"
}
},
"source": [
"docs = loader.load()\n",
"docs[0]"
],
"outputs": [
{
"data": {
"text/plain": [
"Document(metadata={'source': 'example_data/layout-parser-paper.pdf', 'page': 0}, page_content='LayoutParser : A Unified Toolkit for Deep\\nLearning Based Document Image Analysis\\nZejiang Shen1( \\x00), Ruochen Zhang2, Melissa Dell3, Benjamin Charles Germain\\nLee4, Jacob Carlson3, and Weining Li5\\n1Allen Institute for AI\\[email protected]\\n2Brown University\\nruochen [email protected]\\n3Harvard University\\n{melissadell,jacob carlson }@fas.harvard.edu\\n4University of Washington\\[email protected]\\n5University of Waterloo\\[email protected]\\nAbstract. Recent advances in document image analysis (DIA) have been\\nprimarily driven by the application of neural networks. Ideally, research\\noutcomes could be easily deployed in production and extended for further\\ninvestigation. However, various factors like loosely organized codebases\\nand sophisticated model configurations complicate the easy reuse of im-\\nportant innovations by a wide audience. Though there have been on-going\\nefforts to improve reusability and simplify deep learning (DL) model\\ndevelopment in disciplines like natural language processing and computer\\nvision, none of them are optimized for challenges in the domain of DIA.\\nThis represents a major gap in the existing toolkit, as DIA is central to\\nacademic research across a wide range of disciplines in the social sciences\\nand humanities. This paper introduces LayoutParser , an open-source\\nlibrary for streamlining the usage of DL in DIA research and applica-\\ntions. The core LayoutParser library comes with a set of simple and\\nintuitive interfaces for applying and customizing DL models for layout de-\\ntection, character recognition, and many other document processing tasks.\\nTo promote extensibility, LayoutParser also incorporates a community\\nplatform for sharing both pre-trained models and full document digiti-\\nzation pipelines. We demonstrate that LayoutParser is helpful for both\\nlightweight and large-scale digitization pipelines in real-word use cases.\\nThe library is publicly available at https://layout-parser.github.io .\\nKeywords: Document Image Analysis ·Deep Learning ·Layout Analysis\\n·Character Recognition ·Open Source library ·Toolkit.\\n1 Introduction\\nDeep Learning(DL)-based approaches are the state-of-the-art for a wide range of\\ndocument image analysis (DIA) tasks including document image classification [ 11,arXiv:2103.15348v2 [cs.CV] 21 Jun 2021')"
"Document(metadata={'author': '', 'creationdate': '2021-06-22T01:27:10+00:00', 'creator': 'LaTeX with hyperref', 'keywords': '', 'moddate': '2021-06-22T01:27:10+00:00', 'ptex.fullbanner': 'This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020) kpathsea version 6.3.2', 'producer': 'pdfTeX-1.40.21', 'subject': '', 'title': '', 'trapped': '/False', 'source': 'example_data/layout-parser-paper.pdf', 'total_pages': 16, 'page': 0}, page_content='LayoutParser: A Unified Toolkit for Deep\\nLearning Based Document Image Analysis\\nZejiang Shen1 (\\x00 ), Ruochen Zhang2, Melissa Dell3, Benjamin Charles Germain\\nLee4, Jacob Carlson3, and Weining Li5\\n1 Allen Institute for AI\\[email protected]\\n2 Brown University\\nruochen [email protected]\\n3 Harvard University\\n{melissadell,jacob carlson}@fas.harvard.edu\\n4 University of Washington\\[email protected]\\n5 University of Waterloo\\[email protected]\\nAbstract. Recent advances in document image analysis (DIA) have been\\nprimarily driven by the application of neural networks. Ideally, research\\noutcomes could be easily deployed in production and extended for further\\ninvestigation. However, various factors like loosely organized codebases\\nand sophisticated model configurations complicate the easy reuse of im-\\nportant innovations by a wide audience. Though there have been on-going\\nefforts to improve reusability and simplify deep learning (DL) model\\ndevelopment in disciplines like natural language processing and computer\\nvision, none of them are optimized for challenges in the domain of DIA.\\nThis represents a major gap in the existing toolkit, as DIA is central to\\nacademic research across a wide range of disciplines in the social sciences\\nand humanities. This paper introduces LayoutParser, an open-source\\nlibrary for streamlining the usage of DL in DIA research and applica-\\ntions. The core LayoutParser library comes with a set of simple and\\nintuitive interfaces for applying and customizing DL models for layout de-\\ntection, character recognition, and many other document processing tasks.\\nTo promote extensibility, LayoutParser also incorporates a community\\nplatform for sharing both pre-trained models and full document digiti-\\nzation pipelines. We demonstrate that LayoutParser is helpful for both\\nlightweight and large-scale digitization pipelines in real-word use cases.\\nThe library is publicly available at https://layout-parser.github.io.\\nKeywords: Document Image Analysis · Deep Learning · Layout Analysis\\n· Character Recognition · Open Source library · Toolkit.\\n1 Introduction\\nDeep Learning(DL)-based approaches are the state-of-the-art for a wide range of\\ndocument image analysis (DIA) tasks including document image classification [11,\\narXiv:2103.15348v2 [cs.CV] 21 Jun 2021')"
]
},
"execution_count": 2,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"docs = loader.load()\n",
"docs[0]"
]
"execution_count": 10
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-12-13T14:39:26.908137Z",
"start_time": "2024-12-13T14:39:26.898245Z"
}
},
"source": [
"print(docs[0].metadata)"
],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'source': 'example_data/layout-parser-paper.pdf', 'page': 0}\n"
"{'author': '', 'creationdate': '2021-06-22T01:27:10+00:00', 'creator': 'LaTeX with hyperref', 'keywords': '', 'moddate': '2021-06-22T01:27:10+00:00', 'ptex.fullbanner': 'This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020) kpathsea version 6.3.2', 'producer': 'pdfTeX-1.40.21', 'subject': '', 'title': '', 'trapped': '/False', 'source': 'example_data/layout-parser-paper.pdf', 'total_pages': 16, 'page': 0}\n"
]
}
],
"source": [
"print(docs[0].metadata)"
]
"execution_count": 11
},
{
"cell_type": "markdown",
Expand All @@ -139,9 +178,12 @@
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"metadata": {
"ExecuteTime": {
"end_time": "2024-12-13T14:39:28.341129Z",
"start_time": "2024-12-13T14:39:26.999576Z"
}
},
"source": [
"page = []\n",
"for doc in loader.lazy_load():\n",
Expand All @@ -151,7 +193,9 @@
" # index.upsert(page)\n",
"\n",
" page = []"
]
],
"outputs": [],
"execution_count": 12
},
{
"cell_type": "markdown",
Expand Down
Loading
Loading