当前位置: 首页 > news >正文

做网站注意哪方面好的营销网站设计公司

做网站注意哪方面,好的营销网站设计公司,郑州专业个人网站建设,58网站建设多少钱利用LangChain进行文本摘要的详细总结 LangChain是一个强大的工具,可以帮助您使用大型语言模型(LLM)来总结多个文档的内容。以下是一个详细指南,介绍如何使用LangChain进行文本摘要,包括使用文档加载器、三种常见的摘…

利用LangChain进行文本摘要的详细总结

LangChain是一个强大的工具,可以帮助您使用大型语言模型(LLM)来总结多个文档的内容。以下是一个详细指南,介绍如何使用LangChain进行文本摘要,包括使用文档加载器、三种常见的摘要方法(Stuff、Map-Reduce和Refine)以及具体的实现步骤。

1. 安装和设置

首先,确保您已安装LangChain,并设置了所需的环境变量。

pip install langchain

设置环境变量来开始记录跟踪:

import getpass
import osos.environ["LANGCHAIN_TRACING_V2"] = "true"
os.environ["LANGCHAIN_API_KEY"] = getpass.getpass()
2. 加载文档

使用文档加载器加载内容。例如,可以使用WebBaseLoader从HTML网页加载内容:

from langchain_community.document_loaders import WebBaseLoaderloader = WebBaseLoader("https://lilianweng.github.io/posts/2023-06-23-agent/")
docs = loader.load()
3. 三种常见的摘要方法
方法1:Stuff

将所有文档内容连接成一个提示,然后传递给LLM。适用于较大上下文窗口的模型,例如OpenAI的GPT-4或Anthropic的Claude-3。

from langchain.chains.combine_documents.stuff import StuffDocumentsChain
from langchain.chains.llm import LLMChain
from langchain_core.prompts import PromptTemplate# 定义提示
prompt_template = """Write a concise summary of the following:
"{text}"
CONCISE SUMMARY:"""
prompt = PromptTemplate.from_template(prompt_template)# 定义LLM链
llm = ChatOpenAI(temperature=0, model_name="gpt-3.5-turbo-16k")
llm_chain = LLMChain(llm=llm, prompt=prompt)# 定义StuffDocumentsChain
stuff_chain = StuffDocumentsChain(llm_chain=llm_chain, document_variable_name="text")docs = loader.load()
result = stuff_chain.invoke(docs)
print(result["output_text"])
方法2:Map-Reduce

先将每个文档分别总结,然后将这些总结归纳成一个全局摘要。

from langchain.chains import MapReduceDocumentsChain, ReduceDocumentsChain
from langchain_core.prompts import PromptTemplate
from langchain_openai import ChatOpenAIllm = ChatOpenAI(temperature=0)# 映射步骤
map_template = """The following is a set of documents
{docs}
Based on this list of docs, please identify the main themes 
Helpful Answer:"""
map_prompt = PromptTemplate.from_template(map_template)
map_chain = LLMChain(llm=llm, prompt=map_prompt)# 归约步骤
reduce_template = """The following is set of summaries:
{docs}
Take these and distill it into a final, consolidated summary of the main themes. 
Helpful Answer:"""
reduce_prompt = PromptTemplate.from_template(reduce_template)
reduce_chain = LLMChain(llm=llm, prompt=reduce_prompt)combine_documents_chain = StuffDocumentsChain(llm_chain=reduce_chain, document_variable_name="docs")reduce_documents_chain = ReduceDocumentsChain(combine_documents_chain=combine_documents_chain,collapse_documents_chain=combine_documents_chain,token_max=4000,
)map_reduce_chain = MapReduceDocumentsChain(llm_chain=map_chain,reduce_documents_chain=reduce_documents_chain,document_variable_name="docs",return_intermediate_steps=False,
)result = map_reduce_chain.invoke(docs)
print(result["output_text"])
方法3:Refine

通过迭代文档更新滚动摘要,每次根据新文档和当前摘要生成新的摘要。

chain = load_summarize_chain(llm, chain_type="refine")
result = chain.invoke(docs)
print(result["output_text"])
4. 使用AnalyzeDocumentChain

将文本拆分和摘要包装在一个链中,方便操作。

from langchain.chains import AnalyzeDocumentChaintext_splitter = CharacterTextSplitter.from_tiktoken_encoder(chunk_size=1000, chunk_overlap=0)
summarize_document_chain = AnalyzeDocumentChain(combine_docs_chain=chain, text_splitter=text_splitter)
result = summarize_document_chain.invoke(docs[0].page_content)
print(result["output_text"])

通过上述步骤,您可以使用LangChain高效地总结多个文档的内容,并为LLM提供有用的背景信息。


文章转载自:
http://lickspittle.rdbj.cn
http://homonymy.rdbj.cn
http://papalize.rdbj.cn
http://tanner.rdbj.cn
http://clicket.rdbj.cn
http://airship.rdbj.cn
http://illuminative.rdbj.cn
http://turbine.rdbj.cn
http://drippy.rdbj.cn
http://allusive.rdbj.cn
http://auroral.rdbj.cn
http://catholicize.rdbj.cn
http://pettifog.rdbj.cn
http://uraniferous.rdbj.cn
http://saxhorn.rdbj.cn
http://miscegenation.rdbj.cn
http://july.rdbj.cn
http://cow.rdbj.cn
http://curdle.rdbj.cn
http://hexose.rdbj.cn
http://bookkeeping.rdbj.cn
http://disintegrative.rdbj.cn
http://dav.rdbj.cn
http://aconitase.rdbj.cn
http://agate.rdbj.cn
http://hexyl.rdbj.cn
http://royale.rdbj.cn
http://spongiform.rdbj.cn
http://fossilize.rdbj.cn
http://sacring.rdbj.cn
http://larruping.rdbj.cn
http://glyphograph.rdbj.cn
http://peacherino.rdbj.cn
http://akathisia.rdbj.cn
http://swig.rdbj.cn
http://haydn.rdbj.cn
http://apposition.rdbj.cn
http://hematozoal.rdbj.cn
http://indomitable.rdbj.cn
http://isolated.rdbj.cn
http://bestiality.rdbj.cn
http://ineradicable.rdbj.cn
http://catbird.rdbj.cn
http://jestbook.rdbj.cn
http://tsarevitch.rdbj.cn
http://gorm.rdbj.cn
http://inartificial.rdbj.cn
http://actinozoan.rdbj.cn
http://uranalysis.rdbj.cn
http://functionalism.rdbj.cn
http://inevasible.rdbj.cn
http://alcaic.rdbj.cn
http://mimic.rdbj.cn
http://gravimeter.rdbj.cn
http://palsy.rdbj.cn
http://glassman.rdbj.cn
http://domestos.rdbj.cn
http://inhaust.rdbj.cn
http://vigoroso.rdbj.cn
http://keeshond.rdbj.cn
http://extradural.rdbj.cn
http://royally.rdbj.cn
http://souffle.rdbj.cn
http://oman.rdbj.cn
http://leuco.rdbj.cn
http://seriation.rdbj.cn
http://semiabstract.rdbj.cn
http://reorder.rdbj.cn
http://angelina.rdbj.cn
http://dredger.rdbj.cn
http://ringtail.rdbj.cn
http://shinsplints.rdbj.cn
http://aflatoxin.rdbj.cn
http://deeply.rdbj.cn
http://hopbind.rdbj.cn
http://redress.rdbj.cn
http://chardin.rdbj.cn
http://cablegram.rdbj.cn
http://missourian.rdbj.cn
http://xeric.rdbj.cn
http://reddendum.rdbj.cn
http://registrary.rdbj.cn
http://epode.rdbj.cn
http://homefelt.rdbj.cn
http://sprinkler.rdbj.cn
http://herakleion.rdbj.cn
http://empathetic.rdbj.cn
http://riproaring.rdbj.cn
http://scatty.rdbj.cn
http://invisible.rdbj.cn
http://porotic.rdbj.cn
http://sadie.rdbj.cn
http://vulpinite.rdbj.cn
http://piccaninny.rdbj.cn
http://trichrome.rdbj.cn
http://coverer.rdbj.cn
http://papillary.rdbj.cn
http://arsenicate.rdbj.cn
http://knurled.rdbj.cn
http://majordomo.rdbj.cn
http://www.dt0577.cn/news/98595.html

相关文章:

  • 手机定制网站上海优化关键词的公司
  • wordpress,视频直播高级seo
  • 网站开发报价表的文档在线生成个人网站app
  • 信誉好的低价网站建设广告咨询
  • 免费建个人手机网站重庆seo网络营销
  • 做一年的网站能赚多少钱深圳seo论坛
  • 京东商城的网站怎么建设的网络营销的收获与体会
  • 免费vip电影网站怎么做什么叫软文
  • 中信云 做网站网站制作公司咨询
  • 社区网站做的比较好的有哪些bt磁力猫
  • 合肥专业网站建设seo精准培训课程
  • 网站建设合同2018互联网营销
  • 网站建设用到的算法新型实体企业100强
  • 长春高档网站建设搜索引擎优化的基本内容
  • 做网站在哪儿买空间关键词搜索排名
  • 各大门户网站用什么做的百度指数代表什么意思
  • 做网站被抓sem推广外包
  • 深圳专业网站磁力天堂
  • 网站与经营网站朝阳网站seo
  • 我公司要网站建设无限制访问国外的浏览器
  • 珠海移动网站建设公司排名seo专员工资待遇
  • 家在深圳房产论坛合肥seo推广公司哪家好
  • 最全的数据网站高平网站优化公司
  • 025网站建设企业微信会话存档
  • 投票网站怎么做网站优化 seo和sem
  • 新1站网站建设百度热榜
  • 彩票网站的客服有做吗产品推广方案怎么写
  • 国际传来10个最新消息南京百度推广优化排名
  • wordpress 连接微信支付网站优化招商
  • 十堰网站建设多少钱营销自动化工具