id
stringlengths
14
16
text
stringlengths
31
3.14k
source
stringlengths
58
124
266d0daa8f0d-0
.ipynb .pdf RetryOutputParser RetryOutputParser# While in some cases it is possible to fix any parsing mistakes by only looking at the output, in other cases it can’t. An example of this is when the output is not just in the incorrect format, but is partially complete. Consider the below example. from langchain.prompts...
/content/https://python.langchain.com/en/latest/modules/prompts/output_parsers/examples/retry.html
266d0daa8f0d-1
bad_response = '{"action": "search"}' If we try to parse this response as is, we will get an error parser.parse(bad_response) --------------------------------------------------------------------------- ValidationError Traceback (most recent call last) File ~/workplace/langchain/langchain/outpu...
/content/https://python.langchain.com/en/latest/modules/prompts/output_parsers/examples/retry.html
266d0daa8f0d-2
Cell In[6], line 1 ----> 1 parser.parse(bad_response) File ~/workplace/langchain/langchain/output_parsers/pydantic.py:29, in PydanticOutputParser.parse(self, text) 27 name = self.pydantic_object.__name__ 28 msg = f"Failed to parse {name} from completion {text}. Got: {e}" ---> 29 raise OutputParserException(ms...
/content/https://python.langchain.com/en/latest/modules/prompts/output_parsers/examples/retry.html
266d0daa8f0d-3
Action(action='search', action_input='who is leo di caprios gf?') previous PydanticOutputParser next Structured Output Parser By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Apr 26, 2023.
/content/https://python.langchain.com/en/latest/modules/prompts/output_parsers/examples/retry.html
738ac689bec8-0
.ipynb .pdf PydanticOutputParser PydanticOutputParser# This output parser allows users to specify an arbitrary JSON schema and query LLMs for JSON outputs that conform to that schema. Keep in mind that large language models are leaky abstractions! You’ll have to use an LLM with sufficient capacity to generate well-form...
/content/https://python.langchain.com/en/latest/modules/prompts/output_parsers/examples/pydantic.html
738ac689bec8-1
raise ValueError("Badly formed question!") return field # And a query intented to prompt a language model to populate the data structure. joke_query = "Tell me a joke." # Set up a parser + inject instructions into the prompt template. parser = PydanticOutputParser(pydantic_object=Joke) prompt = PromptTemplate( ...
/content/https://python.langchain.com/en/latest/modules/prompts/output_parsers/examples/pydantic.html
738ac689bec8-2
) _input = prompt.format_prompt(query=actor_query) output = model(_input.to_string()) parser.parse(output) Actor(name='Tom Hanks', film_names=['Forrest Gump', 'Saving Private Ryan', 'The Green Mile', 'Cast Away', 'Toy Story']) previous OutputFixingParser next RetryOutputParser By Harrison Chase © Copyright 2...
/content/https://python.langchain.com/en/latest/modules/prompts/output_parsers/examples/pydantic.html
1acb0a74c007-0
.ipynb .pdf OutputFixingParser OutputFixingParser# This output parser wraps another output parser and tries to fix any mmistakes The Pydantic guardrail simply tries to parse the LLM response. If it does not parse correctly, then it errors. But we can do other things besides throw errors. Specifically, we can pass the m...
/content/https://python.langchain.com/en/latest/modules/prompts/output_parsers/examples/output_fixing_parser.html
1acb0a74c007-1
JSONDecodeError Traceback (most recent call last) File ~/workplace/langchain/langchain/output_parsers/pydantic.py:23, in PydanticOutputParser.parse(self, text) 22 json_str = match.group() ---> 23 json_object = json.loads(json_str) 24 return self.pydantic_object.parse_obj(json_obj...
/content/https://python.langchain.com/en/latest/modules/prompts/output_parsers/examples/output_fixing_parser.html
1acb0a74c007-2
338 end = _w(s, end).end() File ~/.pyenv/versions/3.9.1/lib/python3.9/json/decoder.py:353, in JSONDecoder.raw_decode(self, s, idx) 352 try: --> 353 obj, end = self.scan_once(s, idx) 354 except StopIteration as err: JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1) ...
/content/https://python.langchain.com/en/latest/modules/prompts/output_parsers/examples/output_fixing_parser.html
1acb0a74c007-3
from langchain.output_parsers import OutputFixingParser new_parser = OutputFixingParser.from_llm(parser=parser, llm=ChatOpenAI()) new_parser.parse(misformatted) Actor(name='Tom Hanks', film_names=['Forrest Gump']) previous CommaSeparatedListOutputParser next PydanticOutputParser By Harrison Chase © Copyright...
/content/https://python.langchain.com/en/latest/modules/prompts/output_parsers/examples/output_fixing_parser.html
729b68a30218-0
.ipynb .pdf Structured Output Parser Structured Output Parser# While the Pydantic/JSON parser is more powerful, we initially experimented data structures having text fields only. from langchain.output_parsers import StructuredOutputParser, ResponseSchema from langchain.prompts import PromptTemplate, ChatPromptTemplate,...
/content/https://python.langchain.com/en/latest/modules/prompts/output_parsers/examples/structured.html
729b68a30218-1
output = model(_input.to_string()) output_parser.parse(output) {'answer': 'Paris', 'source': 'https://en.wikipedia.org/wiki/Paris'} And here’s an example of using this in a chat model chat_model = ChatOpenAI(temperature=0) prompt = ChatPromptTemplate( messages=[ HumanMessagePromptTemplate.from_template("ans...
/content/https://python.langchain.com/en/latest/modules/prompts/output_parsers/examples/structured.html
535b02a2dca1-0
.ipynb .pdf CommaSeparatedListOutputParser CommaSeparatedListOutputParser# Here’s another parser strictly less powerful than Pydantic/JSON parsing. from langchain.output_parsers import CommaSeparatedListOutputParser from langchain.prompts import PromptTemplate, ChatPromptTemplate, HumanMessagePromptTemplate from langch...
/content/https://python.langchain.com/en/latest/modules/prompts/output_parsers/examples/comma_separated.html
bd4199454a86-0
.rst .pdf Document Loaders Document Loaders# Note Conceptual Guide Combining language models with your own text data is a powerful way to differentiate them. The first step in doing this is to load the data into “documents” - a fancy way of say some pieces of text. This module is aimed at making this easy. A primary dr...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders.html
61ad92cb255f-0
.ipynb .pdf Getting Started Contents One Line Index Creation Walkthrough Getting Started# LangChain primary focuses on constructing indexes with the goal of using them as a Retriever. In order to best understand what this means, it’s worth highlighting what the base Retriever interface is. The BaseRetriever class in ...
/content/https://python.langchain.com/en/latest/modules/indexes/getting_started.html
61ad92cb255f-1
Question answering over documents consists of four steps: Create an index Create a Retriever from that index Create a question answering chain Ask questions! Each of the steps has multiple sub steps and potential configurations. In this notebook we will primarily focus on (1). We will start by showing the one-liner for...
/content/https://python.langchain.com/en/latest/modules/indexes/getting_started.html
61ad92cb255f-2
index.query(query) " The president said that Ketanji Brown Jackson is one of the nation's top legal minds, a former top litigator in private practice, a former federal public defender, and from a family of public school educators and police officers. He also said that she is a consensus builder and has received a broad...
/content/https://python.langchain.com/en/latest/modules/indexes/getting_started.html
61ad92cb255f-3
index.vectorstore.as_retriever() VectorStoreRetriever(vectorstore=<langchain.vectorstores.chroma.Chroma object at 0x119aa5940>, search_kwargs={}) Walkthrough# Okay, so what’s actually going on? How is this index getting created? A lot of the magic is being hid in this VectorstoreIndexCreator. What is this doing? There ...
/content/https://python.langchain.com/en/latest/modules/indexes/getting_started.html
61ad92cb255f-4
Then, as before, we create a chain and use it to answer questions! qa = RetrievalQA.from_chain_type(llm=OpenAI(), chain_type="stuff", retriever=retriever) query = "What did the president say about Ketanji Brown Jackson" qa.run(query) " The President said that Judge Ketanji Brown Jackson is one of the nation's top legal...
/content/https://python.langchain.com/en/latest/modules/indexes/getting_started.html
0e75cf4cf340-0
.rst .pdf Vectorstores Vectorstores# Note Conceptual Guide Vectorstores are one of the most important components of building indexes. For an introduction to vectorstores and generic functionality see: Getting Started We also have documentation for all the types of vectorstores that are supported. Please see below for t...
/content/https://python.langchain.com/en/latest/modules/indexes/vectorstores.html
8a3d34c3d6d1-0
.rst .pdf Text Splitters Text Splitters# Note Conceptual Guide When you want to deal with long pieces of text, it is necessary to split up that text into chunks. As simple as this sounds, there is a lot of potential complexity here. Ideally, you want to keep the semantically related pieces of text together. What “seman...
/content/https://python.langchain.com/en/latest/modules/indexes/text_splitters.html
2fc5d215352b-0
.rst .pdf Retrievers Retrievers# Note Conceptual Guide The retriever interface is a generic interface that makes it easy to combine documents with language models. This interface exposes a get_relevant_documents method which takes in a query (a string) and returns a list of documents. Please see below for a list of all...
/content/https://python.langchain.com/en/latest/modules/indexes/retrievers.html
26d822eb982f-0
.ipynb .pdf s3 Directory Contents Specifying a prefix s3 Directory# This covers how to load document objects from an s3 directory object. from langchain.document_loaders import S3DirectoryLoader #!pip install boto3 loader = S3DirectoryLoader("testing-hwc") loader.load() [Document(page_content='Lorem ipsum dolor sit a...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/s3_directory.html
90494dff95a1-0
.ipynb .pdf Telegram Telegram# This notebook covers how to load data from Telegram into a format that can be ingested into LangChain. from langchain.document_loaders import TelegramChatLoader loader = TelegramChatLoader("example_data/telegram.json") loader.load() [Document(page_content="Henry on 2020-01-01T00:00:02: It...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/telegram.html
4414d3cb1178-0
.ipynb .pdf Copy Paste Contents Metadata Copy Paste# This notebook covers how to load a document object from something you just want to copy and paste. In this case, you don’t even need to use a DocumentLoader, but rather can just construct the Document directly. from langchain.docstore.document import Document text ...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/copypaste.html
a26c7bfe149a-0
.ipynb .pdf YouTube Contents Add video info YouTube loader from Google Cloud Prerequisites 🧑 Instructions for ingesting your Google Docs data YouTube# How to load documents from YouTube transcripts. from langchain.document_loaders import YoutubeLoader # !pip install youtube-transcript-api loader = YoutubeLoader.from...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/youtube.html
a26c7bfe149a-1
Note depending on your set up, the service_account_path needs to be set up. See here for more details. from langchain.document_loaders import GoogleApiClient, GoogleApiYoutubeLoader # Init the GoogleApiClient from pathlib import Path google_api_client = GoogleApiClient(credentials_path=Path("your_path_creds.json")) # ...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/youtube.html
8c6bf65c23f0-0
.ipynb .pdf Hacker News Hacker News# How to pull page data and comments from Hacker News from langchain.document_loaders import HNLoader loader = HNLoader("https://news.ycombinator.com/item?id=34817881") data = loader.load() data
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/hn.html
8c6bf65c23f0-1
data = loader.load() data [Document(page_content="delta_p_delta_x 18 hours ago \n | next [–] \n\nAstrophysical and cosmological simulations are often insightful. They're also very cross-disciplinary; besides the obvious astrophysics, there's networking and sysadmin, parallel computing and algorithm theory ...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/hn.html
8c6bf65c23f0-2
Document(page_content="andrewflnr 19 hours ago \n | prev | next [–] \n\nWhoa. I didn't know the accretion theory of Ia supernovae was dead, much less that it had been since 2011.\n \nreply", lookup_str='', metadata={'source': 'https://news.ycombinator.com/item?id=34817881', 'title': 'What Lights the Univer...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/hn.html
7c891e54180d-0
.ipynb .pdf CSV Loader Contents Customizing the csv parsing and loading Specify a column to be used identify the document source CSV Loader# Load csv files with a single row per document. from langchain.document_loaders.csv_loader import CSVLoader loader = CSVLoader(file_path='./example_data/mlb_teams_2012.csv') data...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/csv.html
7c891e54180d-1
[Document(page_content='Team: Nationals\n"Payroll (millions)": 81.34\n"Wins": 98', lookup_str='', metadata={'source': './example_data/mlb_teams_2012.csv', 'row': 0}, lookup_index=0), Document(page_content='Team: Reds\n"Payroll (millions)": 82.20\n"Wins": 97', lookup_str='', metadata={'source': './example_data/mlb_teams...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/csv.html
7c891e54180d-2
94', lookup_str='', metadata={'source': './example_data/mlb_teams_2012.csv', 'row': 4}, lookup_index=0), Document(page_content='Team: Athletics\n"Payroll (millions)": 55.37\n"Wins": 94', lookup_str='', metadata={'source': './example_data/mlb_teams_2012.csv', 'row': 5}, lookup_index=0), Document(page_content='Team: Rang...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/csv.html
7c891e54180d-3
8}, lookup_index=0), Document(page_content='Team: Angels\n"Payroll (millions)": 154.49\n"Wins": 89', lookup_str='', metadata={'source': './example_data/mlb_teams_2012.csv', 'row': 9}, lookup_index=0), Document(page_content='Team: Tigers\n"Payroll (millions)": 132.30\n"Wins": 88', lookup_str='', metadata={'source': './e...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/csv.html
7c891e54180d-4
85', lookup_str='', metadata={'source': './example_data/mlb_teams_2012.csv', 'row': 13}, lookup_index=0), Document(page_content='Team: Brewers\n"Payroll (millions)": 97.65\n"Wins": 83', lookup_str='', metadata={'source': './example_data/mlb_teams_2012.csv', 'row': 14}, lookup_index=0), Document(page_content='Team: Phil...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/csv.html
7c891e54180d-5
17}, lookup_index=0), Document(page_content='Team: Padres\n"Payroll (millions)": 55.24\n"Wins": 76', lookup_str='', metadata={'source': './example_data/mlb_teams_2012.csv', 'row': 18}, lookup_index=0), Document(page_content='Team: Mariners\n"Payroll (millions)": 81.97\n"Wins": 75', lookup_str='', metadata={'source': '....
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/csv.html
7c891e54180d-6
72', lookup_str='', metadata={'source': './example_data/mlb_teams_2012.csv', 'row': 22}, lookup_index=0), Document(page_content='Team: Marlins\n"Payroll (millions)": 118.07\n"Wins": 69', lookup_str='', metadata={'source': './example_data/mlb_teams_2012.csv', 'row': 23}, lookup_index=0), Document(page_content='Team: Red...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/csv.html
7c891e54180d-7
26}, lookup_index=0), Document(page_content='Team: Rockies\n"Payroll (millions)": 78.06\n"Wins": 64', lookup_str='', metadata={'source': './example_data/mlb_teams_2012.csv', 'row': 27}, lookup_index=0), Document(page_content='Team: Cubs\n"Payroll (millions)": 88.19\n"Wins": 61', lookup_str='', metadata={'source': './ex...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/csv.html
7c891e54180d-8
Customizing the csv parsing and loading# See the csv module documentation for more information of what csv args are supported. loader = CSVLoader(file_path='./example_data/mlb_teams_2012.csv', csv_args={ 'delimiter': ',', 'quotechar': '"', 'fieldnames': ['MLB Team', 'Payroll in millions', 'Wins'] }) data = ...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/csv.html
7c891e54180d-9
[Document(page_content='MLB Team: Team\nPayroll in millions: "Payroll (millions)"\nWins: "Wins"', lookup_str='', metadata={'source': './example_data/mlb_teams_2012.csv', 'row': 0}, lookup_index=0), Document(page_content='MLB Team: Nationals\nPayroll in millions: 81.34\nWins: 98', lookup_str='', metadata={'source': './e...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/csv.html
7c891e54180d-10
'row': 4}, lookup_index=0), Document(page_content='MLB Team: Braves\nPayroll in millions: 83.31\nWins: 94', lookup_str='', metadata={'source': './example_data/mlb_teams_2012.csv', 'row': 5}, lookup_index=0), Document(page_content='MLB Team: Athletics\nPayroll in millions: 55.37\nWins: 94', lookup_str='', metadata={'sou...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/csv.html
7c891e54180d-11
'row': 9}, lookup_index=0), Document(page_content='MLB Team: Angels\nPayroll in millions: 154.49\nWins: 89', lookup_str='', metadata={'source': './example_data/mlb_teams_2012.csv', 'row': 10}, lookup_index=0), Document(page_content='MLB Team: Tigers\nPayroll in millions: 132.30\nWins: 88', lookup_str='', metadata={'sou...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/csv.html
7c891e54180d-12
85', lookup_str='', metadata={'source': './example_data/mlb_teams_2012.csv', 'row': 14}, lookup_index=0), Document(page_content='MLB Team: Brewers\nPayroll in millions: 97.65\nWins: 83', lookup_str='', metadata={'source': './example_data/mlb_teams_2012.csv', 'row': 15}, lookup_index=0), Document(page_content='MLB Team:...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/csv.html
7c891e54180d-13
Document(page_content='MLB Team: Padres\nPayroll in millions: 55.24\nWins: 76', lookup_str='', metadata={'source': './example_data/mlb_teams_2012.csv', 'row': 19}, lookup_index=0), Document(page_content='MLB Team: Mariners\nPayroll in millions: 81.97\nWins: 75', lookup_str='', metadata={'source': './example_data/mlb_te...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/csv.html
7c891e54180d-14
'row': 23}, lookup_index=0), Document(page_content='MLB Team: Marlins\nPayroll in millions: 118.07\nWins: 69', lookup_str='', metadata={'source': './example_data/mlb_teams_2012.csv', 'row': 24}, lookup_index=0), Document(page_content='MLB Team: Red Sox\nPayroll in millions: 173.18\nWins: 69', lookup_str='', metadata={'...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/csv.html
7c891e54180d-15
64', lookup_str='', metadata={'source': './example_data/mlb_teams_2012.csv', 'row': 28}, lookup_index=0), Document(page_content='MLB Team: Cubs\nPayroll in millions: 88.19\nWins: 61', lookup_str='', metadata={'source': './example_data/mlb_teams_2012.csv', 'row': 29}, lookup_index=0), Document(page_content='MLB Team: As...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/csv.html
7c891e54180d-16
Specify a column to be used identify the document source# Use the source_column argument to specify a column to be set as the source for the document created from each row. Otherwise file_path will be used as the source for all documents created from the csv file. This is useful when using documents loaded from CSV fil...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/csv.html
7c891e54180d-17
[Document(page_content='Team: Nationals\n"Payroll (millions)": 81.34\n"Wins": 98', lookup_str='', metadata={'source': 'Nationals', 'row': 0}, lookup_index=0), Document(page_content='Team: Reds\n"Payroll (millions)": 82.20\n"Wins": 97', lookup_str='', metadata={'source': 'Reds', 'row': 1}, lookup_index=0), Document(page...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/csv.html
7c891e54180d-18
metadata={'source': 'Athletics', 'row': 5}, lookup_index=0), Document(page_content='Team: Rangers\n"Payroll (millions)": 120.51\n"Wins": 93', lookup_str='', metadata={'source': 'Rangers', 'row': 6}, lookup_index=0), Document(page_content='Team: Orioles\n"Payroll (millions)": 81.43\n"Wins": 93', lookup_str='', metadata=...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/csv.html
7c891e54180d-19
(millions)": 110.30\n"Wins": 88', lookup_str='', metadata={'source': 'Cardinals', 'row': 11}, lookup_index=0), Document(page_content='Team: Dodgers\n"Payroll (millions)": 95.14\n"Wins": 86', lookup_str='', metadata={'source': 'Dodgers', 'row': 12}, lookup_index=0), Document(page_content='Team: White Sox\n"Payroll (mill...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/csv.html
7c891e54180d-20
'Diamondbacks', 'row': 16}, lookup_index=0), Document(page_content='Team: Pirates\n"Payroll (millions)": 63.43\n"Wins": 79', lookup_str='', metadata={'source': 'Pirates', 'row': 17}, lookup_index=0), Document(page_content='Team: Padres\n"Payroll (millions)": 55.24\n"Wins": 76', lookup_str='', metadata={'source': 'Padre...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/csv.html
7c891e54180d-21
(millions)": 60.91\n"Wins": 72', lookup_str='', metadata={'source': 'Royals', 'row': 22}, lookup_index=0), Document(page_content='Team: Marlins\n"Payroll (millions)": 118.07\n"Wins": 69', lookup_str='', metadata={'source': 'Marlins', 'row': 23}, lookup_index=0), Document(page_content='Team: Red Sox\n"Payroll (millions)...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/csv.html
7c891e54180d-22
'Rockies', 'row': 27}, lookup_index=0), Document(page_content='Team: Cubs\n"Payroll (millions)": 88.19\n"Wins": 61', lookup_str='', metadata={'source': 'Cubs', 'row': 28}, lookup_index=0), Document(page_content='Team: Astros\n"Payroll (millions)": 60.65\n"Wins": 55', lookup_str='', metadata={'source': 'Astros', 'row': ...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/csv.html
7c891e54180d-23
previous Copy Paste next DataFrame Loader Contents Customizing the csv parsing and loading Specify a column to be used identify the document source By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Apr 26, 2023.
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/csv.html
7b0dfe8ade09-0
.ipynb .pdf PDF Contents Using PyPDF Using Unstructured Retain Elements Fetching remote PDFs using Unstructured Using PDFMiner Using PDFMiner to generate HTML text Using PyMuPDF PDF# This covers how to load pdfs into a document format that we can use downstream. Using PyPDF# Load PDF using pypdf into array of documen...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-1
Document(page_content='LayoutParser : A Uni\x0ced 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\nshannons@allenai.org\n2Brown University\nruochen zhang@brown.edu\n3Ha...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-2
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, chara...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-3
An advantage of this approach is that documents can be retrieved with page numbers. from langchain.vectorstores import FAISS from langchain.embeddings.openai import OpenAIEmbeddings faiss_index = FAISS.from_documents(pages, OpenAIEmbeddings()) docs = faiss_index.similarity_search("How will the community be engaged?", k...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-4
are mainly described in academic papers and implementations are often not pub- licly available. To this end, the LayoutParser community platform also enables the sharing of layout pipelines to promote the discussion and reuse of techniques. For each shared pipeline, it has a dedicated project page, with links to the so...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-5
models and whole digitization pipelines to promote reusability and reproducibility. A collection of detailed documentation, tutorials and exemplar projects make LayoutParser easy to learn and use. AllenNLP [ 8] and transformers [ 34] have provided the community with complete DL-based support for developing and deployin...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-6
from langchain.document_loaders import UnstructuredPDFLoader loader = UnstructuredPDFLoader("example_data/layout-parser-paper.pdf") data = loader.load() Retain Elements# Under the hood, Unstructured creates different “elements” for different chunks of text. By default we combine those together, but you can easily keep ...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-7
Document(page_content='LayoutParser: A Unified Toolkit for Deep\nLearning Based Document Image Analysis\nZejiang Shen1 (�), Ruochen Zhang2, Melissa Dell3, Benjamin Charles Germain\nLee4, Jacob Carlson3, and Weining Li5\n1 Allen Institute for AI\nshannons@allenai.org\n2 Brown University\nruochen zhang@brown.edu\n3 Harvar...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-8
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 exten...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-9
hyperref', 'producer': 'pdfTeX-1.40.21', 'creationDate': 'D:20210622012710Z', 'modDate': 'D:20210622012710Z', 'trapped': '', 'encryption': None}, lookup_index=0)
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-10
Fetching remote PDFs using Unstructured# This covers how to load online pdfs into a document format that we can use downstream. This can be used for various online pdf sites such as https://open.umn.edu/opentextbooks/textbooks/ and https://arxiv.org/archive/ Note: all other pdf loaders can also be used to fetch remote ...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-11
[Document(page_content='A WEAK ( k, k ) -LEFSCHETZ THEOREM FOR PROJECTIVE TORIC ORBIFOLDS\n\nWilliam D. Montoya\n\nInstituto de Matem´atica, Estat´ıstica e Computa¸c˜ao Cient´ıfica,\n\nIn [3] we proved that, under suitable conditions, on a very general codimension s quasi- smooth intersection subvariety X in a projectiv...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-12
[7], reduces results known for quasi-smooth hypersurfaces to quasi-smooth intersection subvarieties. The idea in this paper goes the other way around, we translate some results for quasi-smooth intersection subvarieties to\n\nAcknowledgement. I thank Prof. Ugo Bruzzo and Tiago Fonseca for useful discus- sions. I also a...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-13
< σ and σ ∩ σ ′ < σ ′ ;\n\nN R = σ\n\n∪ ⋅ ⋅ ⋅ ∪ σ t .\n\nA rational simplicial complete d -dimensional fan Σ defines a d -dimensional toric variety P d Σ having only orbifold singularities which we assume to be projective. Moreover, T ∶ = N ⊗ Z C ∗ ≃ ( C ∗ ) d is the torus action on P d Σ . We denote by Σ ( i ) the i -d...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-14
next section. Namely: de Rham theorem and Dolbeault theorem for complex orbifolds.\n\nDefinition 2.4. A complex orbifold of complex dimension d is a singular complex space whose singularities are locally isomorphic to quotient singularities C d / G , for finite sub- groups G ⊂ Gl ( d, C ) .\n\nDefinition 2.5. A differentia...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-15
intersection sub- varieties are quasi-smooth subvarieties (see [2] or [7] for more details).\n\nRemark 3.3 . Quasi-smooth subvarieties are suborbifolds of P d Σ in the sense of Satake in [8]. Intuitively speaking they are subvarieties whose only singularities come from the ambient\n\nProof. From the exponential short e...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-16
Theorem for projective orbifolds (see [11] for details) we get an isomorphism of cohomologies :\n\ngiven by the Lefschetz morphism and since it is a morphism of Hodge structures, we have:\n\nH 1 , 1 ( X, Q ) ≃ H dim X − 1 , dim X − 1 ( X, Q )\n\nCorollary 3.6. If the dimension of X is 1 , 2 or 3 . The Hodge conjecture ...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-17
( E ) is\n\nMoreover for X a quasi-smooth intersection subvariety cut off by f 1 , . . . , f s with deg ( f i ) = [ L i ] we relate the hypersurface Y cut off by F = y 1 f 1 + ⋅ ⋅ ⋅ + y s f s which turns out to be quasi-smooth. For more details see Section 2 in [7].\n\nWe will denote P ( E ) as P d + s − 1 Σ ,X to keep t...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-18
d − s prim ( X ) is the quotient H d − s ( X, C )/ i ∗ ( H d − s ( P d Σ , C )) and H d − s prim ( X, Q ) with rational coefficients.\n\nH d − s ( P d Σ , C ) and H d − s ( X, C ) have pure Hodge structures, and the morphism i ∗ is com- patible with them, so that H d − s prim ( X ) gets a pure Hodge structure.\n\nThe nex...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-19
Y the Hodge conjecture holds.\n\nthe Hodge conjecture holds.\n\nProof. If H k,k prim ( X, Q ) = 0 we are done. So let us assume H k,k prim ( X, Q ) ≠ 0. By the Cayley proposition H k,k prim ( Y, Q ) ≃ H 1 , 1 prim ( X, Q ) and by the ( 1 , 1 ) -Lefschetz theorem for projective\n\ntoric orbifolds there is a non-zero alg...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-20
Y = { F = y 1 f 1 + ⋯ + y k f k = 0 } and\n\nfurthermore it has codimension k .\n\nClaim: { C i } ni = 1 is a basis of prim ( ) . It is enough to prove that λ C i is different from zero in H k,k prim ( Y, Q ) or equivalently that the cohomology classes { λ C i } ni = 1 do not come from the ambient space. By contradictio...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-21
and we translate it to Y by contradiction. So, using an analogous argument we have:\n\nargument we have:\n\nProposition 5.3. Let Y = { F = y 1 f s +⋯+ y s f s = 0 } ⊂ P 2 k + 1 Σ ,X be the quasi-smooth hypersurface associated to a quasi-smooth intersection subvariety X = X f 1 ∩ ⋅ ⋅ ⋅ ∩ X f s ⊂ P d Σ such that d + s = ...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-22
Sci. Special Section: Geometry in Algebra and Algebra in Geometry (\n\n). [\n\n] Caramello Jr, F. C. Introduction to orbifolds. a\n\niv:\n\nv\n\n(\n\n). [\n\n] Cox, D., Little, J., and Schenck, H. Toric varieties, vol.\n\nAmerican Math- ematical Soc.,\n\n[\n\n] Griffiths, P., and Harris, J. Principles of Algebraic Geom...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-23
I, vol.\n\nof Cambridge Studies in Advanced Mathematics . Cambridge University Press,\n\n[\n\n] Wang, Z. Z., and Zaffran, D. A remark on the Hard Lefschetz theorem for K¨ahler orbifolds. Proceedings of the American Mathematical Society\n\n,\n\n(Aug\n\n).\n\n[2] Batyrev, V. V., and Cox, D. A. On the Hodge structure of p...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-24
Using PDFMiner# from langchain.document_loaders import PDFMinerLoader loader = PDFMinerLoader("example_data/layout-parser-paper.pdf") data = loader.load() Using PDFMiner to generate HTML text# This can be helpful for chunking texts semantically into sections as the output html content can be parsed via BeautifulSoup to...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-25
cur_fs = fs cur_text = c.text snippets.append((cur_text,cur_fs)) # Note: The above logic is very straightforward. One can also add more strategies such as removing duplicate snippets (as # headers/footers in a PDF appear on multiple pages so if we find duplicatess safe to assume that it is redundant info) from ...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-26
semantic_snippets[cur_idx].page_content += s[0] semantic_snippets[cur_idx].metadata['content_font'] = max(s[1], semantic_snippets[cur_idx].metadata['content_font']) continue # if current snippet's font size > previous section's content but less tha previous section's heading than also make a ne...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-27
Document(page_content='Recently, various DL models and datasets have been developed for layout analysis\ntasks. The dhSegment [22] utilizes fully convolutional networks [20] for segmen-\ntation tasks on historical documents. Object detection-based methods like Faster\nR-CNN [28] and Mask R-CNN [12] are used for identif...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-28
and Exploitation (DAE) platform [15] and the DeepDIVA project [2]\naim to improve the reproducibility of DIA methods (or DL models), yet they\nare not actively maintained. OCR engines like Tesseract [14], easyOCR11 and\npaddleOCR12 usually do not come with comprehensive functionalities for other\nDIA tasks like layout ...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-29
target samples. The community platform enables the easy sharing of DIA\nmodels and whole digitization pipelines to promote reusability and reproducibility.\nA collection of detailed documentation, tutorials and exemplar projects make\nLayoutParser easy to learn and use.\nAllenNLP [8] and transformers [34] have provided...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-30
Using PyMuPDF# This is the fastest of the PDF parsing options, and contains detailed metadata about the PDF and its pages, as well as returns one document per page. from langchain.document_loaders import PyMuPDFLoader loader = PyMuPDFLoader("example_data/layout-parser-paper.pdf") data = loader.load() data[0]
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-31
Document(page_content='LayoutParser: A Unified Toolkit for Deep\nLearning Based Document Image Analysis\nZejiang Shen1 (�), Ruochen Zhang2, Melissa Dell3, Benjamin Charles Germain\nLee4, Jacob Carlson3, and Weining Li5\n1 Allen Institute for AI\nshannons@allenai.org\n2 Brown University\nruochen zhang@brown.edu\n3 Harvar...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-32
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 exten...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-33
hyperref', 'producer': 'pdfTeX-1.40.21', 'creationDate': 'D:20210622012710Z', 'modDate': 'D:20210622012710Z', 'trapped': '', 'encryption': None}, lookup_index=0)
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7b0dfe8ade09-34
Additionally, you can pass along any of the options from the PyMuPDF documentation as keyword arguments in the load call, and it will be pass along to the get_text() call. previous Obsidian next PowerPoint Contents Using PyPDF Using Unstructured Retain Elements Fetching remote PDFs using Unstructured Using PDFMiner...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/pdf.html
7e3e629ee4a0-0
.ipynb .pdf CoNLL-U CoNLL-U# This is an example of how to load a file in CoNLL-U format. The whole file is treated as one document. The example data (conllu.conllu) is based on one of the standard UD/CoNLL-U examples. from langchain.document_loaders import CoNLLULoader loader = CoNLLULoader("example_data/conllu.conllu"...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/CoNLL-U.html
79bd01e7a10e-0
.ipynb .pdf Markdown Contents Retain Elements Markdown# This covers how to load markdown documents into a document format that we can use downstream. from langchain.document_loaders import UnstructuredMarkdownLoader loader = UnstructuredMarkdownLoader("../../../../README.md") data = loader.load() data
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/markdown.html
79bd01e7a10e-1
[Document(page_content="ð\x9f¦\x9cï¸\x8fð\x9f”\x97 LangChain\n\nâ\x9a¡ Building applications with LLMs through composability â\x9a¡\n\nProduction Support: As you move your LangChains into production, we'd love to offer more comprehensive support.\nPlease fill out this form and we'll set up a dedicated support Slack cha...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/markdown.html
79bd01e7a10e-2
Documentation\n\nPlease see here for full documentation on:\n\nGetting started (installation, setting up the environment, simple examples)\n\nHow-To examples (demos, integrations, helper functions)\n\nReference (full API docs)\n Resources (high-level explanation of core concepts)\n\nð\x9f\x9a\x80 What can this help wi...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/markdown.html
79bd01e7a10e-3
which Actions to take, taking that Action, seeing an Observation, and repeating that until done. LangChain provides a standard interface for agents, a selection of agents to choose from, and examples of end to end agents.\n\nð\x9f§\xa0 Memory:\n\nMemory is the concept of persisting state between calls of a chain/agent....
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/markdown.html
79bd01e7a10e-4
Retain Elements# Under the hood, Unstructured creates different “elements” for different chunks of text. By default we combine those together, but you can easily keep that separation by specifying mode="elements". loader = UnstructuredMarkdownLoader("../../../../README.md", mode="elements") data = loader.load() data[0]...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/markdown.html
056f81721b80-0
.ipynb .pdf Image captions Contents Prepare a list of image urls from Wikimedia Create the loader Create the index Query Image captions# This notebook shows how to use the ImageCaptionLoader tutorial to generate a query-able index of image captions from langchain.document_loaders import ImageCaptionLoader Prepare a l...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/image_captions.html
056f81721b80-1
'https://upload.wikimedia.org/wikipedia/commons/thumb/2/21/Passion_fruits_-_whole_and_halved.jpg/270px-Passion_fruits_-_whole_and_halved.jpg', 'https://upload.wikimedia.org/wikipedia/commons/thumb/5/5e/Messier83_-_Heic1403a.jpg/277px-Messier83_-_Heic1403a.jpg', 'https://upload.wikimedia.org/wikipedia/commons/th...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/image_captions.html
056f81721b80-2
list_docs = loader.load() list_docs /Users/saitosean/dev/langchain/.venv/lib/python3.10/site-packages/transformers/generation/utils.py:1313: UserWarning: Using `max_length`'s default (20) to control the generation length. This behaviour is deprecated and will be removed from the config in v5 of Transformers -- we recom...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/image_captions.html
056f81721b80-3
Document(page_content='an image of a painting of a battle scene [SEP]', metadata={'image_path': 'https://upload.wikimedia.org/wikipedia/commons/thumb/2/21/Thure_de_Thulstrup_-_Battle_of_Shiloh.jpg/251px-Thure_de_Thulstrup_-_Battle_of_Shiloh.jpg'}), Document(page_content='an image of a passion fruit and a half cut pass...
/content/https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/image_captions.html