Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKQA over structured dataSQLRetrieval-augmented generation (RAG)Interacting with APIsChatbotsExtractionSummarizationTaggingWeb scrapingSynthetic data generationGraph queryingSummarizationOn this pageSummarizationUse case‚ÄãSuppose you have a set of documents (PDFs, Notion pages, customer questions, etc.) and you want to summarize the content. LLMs are a great tool for this given their proficiency in understanding and synthesizing text.In this walkthrough we'll go over how to perform document summarization using LLMs.Overview‚ÄãA central question for building a summarizer is how to pass your documents into the LLM's context window. Two common approaches for this are:Stuff: Simply "stuff" all your documents into a single prompt. This is the simplest approach (see here for more on the StuffDocumentsChains, which is used for this method).Map-reduce: Summarize each document on it's own in a "map" step and then "reduce" the summaries into a final summary (see here for more on the MapReduceDocumentsChain, which is used for this method).Quickstart‚ÄãTo give you a sneak preview, either pipeline can be wrapped in a single object: load_summarize_chain. Suppose we want to summarize a blog post. We can create this in a few lines of code.First set environment variables and install packages:pip install openai tiktoken chromadb langchain# Set env var OPENAI_API_KEY or load from a .env file# import dotenv# dotenv.load_dotenv()    Requirement already satisfied: openai in /Users/bagatur/langchain/.venv/lib/python3.9/site-packages (0.27.8)    Requirement already satisfied: tiktoken in /Users/bagatur/langchain/.venv/lib/python3.9/site-packages (0.4.0)    Requirement already satisfied: chromadb in /Users/bagatur/langchain/.venv/lib/python3.9/site-packages (0.4.4)    Requirement already satisfied: langchain in /Users/bagatur/langchain/.venv/lib/python3.9/site-packages
Open In Colab
Open In Colab ->: Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKQA over structured dataSQLRetrieval-augmented generation (RAG)Interacting with APIsChatbotsExtractionSummarizationTaggingWeb scrapingSynthetic data generationGraph queryingSummarizationOn this pageSummarizationUse case‚ÄãSuppose you have a set of documents (PDFs, Notion pages, customer questions, etc.) and you want to summarize the content. LLMs are a great tool for this given their proficiency in understanding and synthesizing text.In this walkthrough we'll go over how to perform document summarization using LLMs.Overview‚ÄãA central question for building a summarizer is how to pass your documents into the LLM's context window. Two common approaches for this are:Stuff: Simply "stuff" all your documents into a single prompt. This is the simplest approach (see here for more on the StuffDocumentsChains, which is used for this method).Map-reduce: Summarize each document on it's own in a "map" step and then "reduce" the summaries into a final summary (see here for more on the MapReduceDocumentsChain, which is used for this method).Quickstart‚ÄãTo give you a sneak preview, either pipeline can be wrapped in a single object: load_summarize_chain. Suppose we want to summarize a blog post. We can create this in a few lines of code.First set environment variables and install packages:pip install openai tiktoken chromadb langchain# Set env var OPENAI_API_KEY or load from a .env file# import dotenv# dotenv.load_dotenv()    Requirement already satisfied: openai in /Users/bagatur/langchain/.venv/lib/python3.9/site-packages (0.27.8)    Requirement already satisfied: tiktoken in /Users/bagatur/langchain/.venv/lib/python3.9/site-packages (0.4.0)    Requirement already satisfied: chromadb in /Users/bagatur/langchain/.venv/lib/python3.9/site-packages (0.4.4)    Requirement already satisfied: langchain in /Users/bagatur/langchain/.venv/lib/python3.9/site-packages