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

加工平台seo待遇

加工平台,seo待遇,黄冈网站建设流程,电商运营seo分类目录:《大模型从入门到应用》总目录 下面这个示例展示了如何在索引上进行问答: from langchain.embeddings.openai import OpenAIEmbeddings from langchain.vectorstores import Chroma from langchain.text_splitter import CharacterTextSplitte…

分类目录:《大模型从入门到应用》总目录


下面这个示例展示了如何在索引上进行问答:

from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.vectorstores import Chroma
from langchain.text_splitter import CharacterTextSplitter
from langchain.llms import OpenAI
from langchain.chains import RetrievalQA
from langchain.document_loaders import TextLoader
loader = TextLoader("../../state_of_the_union.txt")
documents = loader.load()
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
texts = text_splitter.split_documents(documents)embeddings = OpenAIEmbeddings()
docsearch = Chroma.from_documents(texts, embeddings)

日志输出:

Running Chroma using direct local API.
Using DuckDB in-memory for database. Data will be transient.
qa = RetrievalQA.from_chain_type(llm=OpenAI(), chain_type="stuff", retriever=docsearch.as_retriever())
query = "What did the president say about Ketanji Brown Jackson"
qa.run(query)

输出:

" The president said that she 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 range of support, from the Fraternal Order of Police to former judges appointed by Democrats and Republicans."

链的类型

我们可以指定不同的链的类型来加载和使用RetrievalQA链。有关这些类型的更详细说明可以参考《大模型从入门到应用——LangChain:链(Chains)-[链与索引:问答的基础知识]》。

有两种加载不同链的类型的方法。首先,我们可以在from_chain_type方法中指定链的类型参数。这允许我们传入要使用的链的类型的名称。例如,在下面的示例中,我们将链的类型更改为map_reduce

qa = RetrievalQA.from_chain_type(llm=OpenAI(), chain_type="map_reduce", retriever=docsearch.as_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 our nation's top legal minds, a former top litigator in private practice and a former federal public defender, from a family of public school educators and police officers, a consensus builder and has received a broad range of support from the Fraternal Order of Police to former judges appointed by Democrats and Republicans."

上述方法确实简单地更改了链的类型,但它对该链的类型的参数提供了很大的灵活性。如果我们想要控制这些参数,可以直接加载链式,然后将其直接传递给RetrievalQA链的combine_documents_chain参数,例如:

from langchain.chains.question_answering import load_qa_chainqa_chain = load_qa_chain(OpenAI(temperature=0), chain_type="stuff")
qa = RetrievalQA(combine_documents_chain=qa_chain, retriever=docsearch.as_retriever())
query = "What did the president say about Ketanji Brown Jackson"
qa.run(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 range of support from the Fraternal Order of Police to former judges appointed by Democrats and Republicans."

自定义提示

我们可以传递自定义提示来进行问答,这些提示与我们可以传递给基础问答链的提示相同。

from langchain.prompts import PromptTemplate
prompt_template = """Use the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer.{context}Question: {question}
Answer in Italian:"""
PROMPT = PromptTemplate(template=prompt_template, input_variables=["context", "question"]
)
chain_type_kwargs = {"prompt": PROMPT}
qa = RetrievalQA.from_chain_type(llm=OpenAI(), chain_type="stuff", retriever=docsearch.as_retriever(), chain_type_kwargs=chain_type_kwargs)
query = "What did the president say about Ketanji Brown Jackson"
qa.run(query)

输出:

" Il presidente ha detto che Ketanji Brown Jackson è una delle menti legali più importanti del paese, che continuerà l'eccellenza di Justice Breyer e che ha ricevuto un ampio sostegno, da Fraternal Order of Police a ex giudici nominati da democratici e repubblicani."

返回源文档

此外,我们可以通过在构建链式时指定一个可选参数来返回用于回答问题的源文档。

qa = RetrievalQA.from_chain_type(llm=OpenAI(), chain_type="stuff", retriever=docsearch.as_retriever(), return_source_documents=True)
query = "What did the president say about Ketanji Brown Jackson"
result = qa({"query": query})
result["result"]

输出:

" The president said that Ketanji Brown Jackson is one of the nation's top legal minds, a former top litigator in private practice and a former federal public defender from a family of public school educators and police officers, and that she has received a broad range of support from the Fraternal Order of Police to former judges appointed by Democrats and Republicans."

输入:

result["source_documents"]

输出:

[Document(page_content='Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections. \n\nTonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service. \n\nOne of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court. \n\nAnd I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.', lookup_str='', metadata={'source': '../../state_of_the_union.txt'}, lookup_index=0),Document(page_content='A former top litigator in private practice. A former federal public defender. And from a family of public school educators and police officers. A consensus builder. Since she’s been nominated, she’s received a broad range of support—from the Fraternal Order of Police to former judges appointed by Democrats and Republicans. \n\nAnd if we are to advance liberty and justice, we need to secure the Border and fix the immigration system. \n\nWe can do both. At our border, we’ve installed new technology like cutting-edge scanners to better detect drug smuggling.  \n\nWe’ve set up joint patrols with Mexico and Guatemala to catch more human traffickers.  \n\nWe’re putting in place dedicated immigration judges so families fleeing persecution and violence can have their cases heard faster. \n\nWe’re securing commitments and supporting partners in South and Central America to host more refugees and secure their own borders.', lookup_str='', metadata={'source': '../../state_of_the_union.txt'}, lookup_index=0),Document(page_content='And for our LGBTQ+ Americans, let’s finally get the bipartisan Equality Act to my desk. The onslaught of state laws targeting transgender Americans and their families is wrong. \n\nAs I said last year, especially to our younger transgender Americans, I will always have your back as your President, so you can be yourself and reach your God-given potential. \n\nWhile it often appears that we never agree, that isn’t true. I signed 80 bipartisan bills into law last year. From preventing government shutdowns to protecting Asian-Americans from still-too-common hate crimes to reforming military justice. \n\nAnd soon, we’ll strengthen the Violence Against Women Act that I first wrote three decades ago. It is important for us to show the nation that we can come together and do big things. \n\nSo tonight I’m offering a Unity Agenda for the Nation. Four big things we can do together.  \n\nFirst, beat the opioid epidemic.', lookup_str='', metadata={'source': '../../state_of_the_union.txt'}, lookup_index=0),Document(page_content='Tonight, I’m announcing a crackdown on these companies overcharging American businesses and consumers. \n\nAnd as Wall Street firms take over more nursing homes, quality in those homes has gone down and costs have gone up.  \n\nThat ends on my watch. \n\nMedicare is going to set higher standards for nursing homes and make sure your loved ones get the care they deserve and expect. \n\nWe’ll also cut costs and keep the economy going strong by giving workers a fair shot, provide more training and apprenticeships, hire them based on their skills not degrees. \n\nLet’s pass the Paycheck Fairness Act and paid leave.  \n\nRaise the minimum wage to $15 an hour and extend the Child Tax Credit, so no one has to raise a family in poverty. \n\nLet’s increase Pell Grants and increase our historic support of HBCUs, and invest in what Jill—our First Lady who teaches full-time—calls America’s best-kept secret: community colleges.', lookup_str='', metadata={'source': '../../state_of_the_union.txt'}, lookup_index=0)]

使用源文档进行检索式问答

本节介绍了如何在索引上使用源文档进行问答。它通过使用RetrievalQAWithSourcesChain实现,该链式结构可以从索引中查找文档。

from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.embeddings.cohere import CohereEmbeddings
from langchain.text_splitter import CharacterTextSplitter
from langchain.vectorstores.elastic_vector_search import ElasticVectorSearch
from langchain.vectorstores import Chromawith open("../../state_of_the_union.txt") as f:state_of_the_union = f.read()
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
texts = text_splitter.split_text(state_of_the_union)embeddings = OpenAIEmbeddings()
docsearch = Chroma.from_texts(texts, embeddings, metadatas=[{"source": f"{i}-pl"} for i in range(len(texts))])

日志输出:

Running Chroma using direct local API.
Using DuckDB in-memory for database. Data will be transient.

输入:

from langchain.chains import RetrievalQAWithSourcesChain
from langchain import OpenAIchain = RetrievalQAWithSourcesChain.from_chain_type(OpenAI(temperature=0), chain_type="stuff", retriever=docsearch.as_retriever())
chain({"question": "What did the president say about Justice Breyer"}, return_only_outputs=True)

输出:

{'answer': ' The president honored Justice Breyer for his service and mentioned his legacy of excellence.\n','sources': '31-pl'}
链的类型

我们可以指定不同的链的类型,以在RetrievalQAWithSourcesChain链中加载和使用。有关这些类型的更详细说明,可以参考《大模型从入门到应用——LangChain:链(Chains)-[链与索引:图问答(Graph QA)和带来源的问答(Q&A with Sources)]》中带来源的问答的部分。

有两种加载不同链类型的方式。首先,我们可以在from_chain_type方法中指定链类型参数,这允许我们传递要使用的链类型的名称。例如,在下面的示例中,我们将链类型更改为map_reduce

chain = RetrievalQAWithSourcesChain.from_chain_type(OpenAI(temperature=0), chain_type="map_reduce", retriever=docsearch.as_retriever())
chain({"question": "What did the president say about Justice Breyer"}, return_only_outputs=True)

输出:

{'answer': ' The president said "Justice Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service."\n','sources': '31-pl'}

上述方法允许我们非常简单地更改链式类型,但它确实在链的类型的参数上提供了很大的灵活性。如果我们想控制这些参数,可以直接加载链式结构,然后使用combine_documents_chain参数将其直接传递给RetrievalQAWithSourcesChain链式结构:

from langchain.chains.qa_with_sources import load_qa_with_sources_chain
qa_chain = load_qa_with_sources_chain(OpenAI(temperature=0), chain_type="stuff")
qa = RetrievalQAWithSourcesChain(combine_documents_chain=qa_chain, retriever=docsearch.as_retriever())
qa({"question": "What did the president say about Justice Breyer"}, return_only_outputs=True)

输出:

{'answer': ' The president honored Justice Breyer for his service and mentioned his legacy of excellence.\n','sources': '31-pl'}

参考文献:
[1] LangChain官方网站:https://www.langchain.com/
[2] LangChain 🦜️🔗 中文网,跟着LangChain一起学LLM/GPT开发:https://www.langchain.com.cn/
[3] LangChain中文网 - LangChain 是一个用于开发由语言模型驱动的应用程序的框架:http://www.cnlangchain.com/


文章转载自:
http://bipedal.nLcw.cn
http://modularity.nLcw.cn
http://betamax.nLcw.cn
http://momentum.nLcw.cn
http://antiepileptic.nLcw.cn
http://debut.nLcw.cn
http://lz.nLcw.cn
http://naillike.nLcw.cn
http://microspecies.nLcw.cn
http://kinsman.nLcw.cn
http://yawningly.nLcw.cn
http://highfalutin.nLcw.cn
http://chicago.nLcw.cn
http://isokeraunic.nLcw.cn
http://pheidippides.nLcw.cn
http://unreclaimable.nLcw.cn
http://tonnage.nLcw.cn
http://amitriptyline.nLcw.cn
http://velodyne.nLcw.cn
http://carrageen.nLcw.cn
http://sapid.nLcw.cn
http://uncoffined.nLcw.cn
http://achromycin.nLcw.cn
http://oxeye.nLcw.cn
http://immodestly.nLcw.cn
http://dissatisfy.nLcw.cn
http://timekeeper.nLcw.cn
http://ankylostomiasis.nLcw.cn
http://farer.nLcw.cn
http://alba.nLcw.cn
http://unaccounted.nLcw.cn
http://footslog.nLcw.cn
http://academize.nLcw.cn
http://greengrocer.nLcw.cn
http://revanchism.nLcw.cn
http://egyptianization.nLcw.cn
http://disseizee.nLcw.cn
http://aline.nLcw.cn
http://reaffirmation.nLcw.cn
http://eastward.nLcw.cn
http://ohia.nLcw.cn
http://drafter.nLcw.cn
http://bushranger.nLcw.cn
http://ineducation.nLcw.cn
http://physicky.nLcw.cn
http://stoep.nLcw.cn
http://abirritate.nLcw.cn
http://hydrophobe.nLcw.cn
http://cardsharping.nLcw.cn
http://unlimber.nLcw.cn
http://eerie.nLcw.cn
http://toponymy.nLcw.cn
http://sis.nLcw.cn
http://caracol.nLcw.cn
http://mawl.nLcw.cn
http://purportedly.nLcw.cn
http://aeronaval.nLcw.cn
http://delicious.nLcw.cn
http://nubble.nLcw.cn
http://mercia.nLcw.cn
http://illusively.nLcw.cn
http://christening.nLcw.cn
http://mullion.nLcw.cn
http://magnetooptical.nLcw.cn
http://quagga.nLcw.cn
http://gyroplane.nLcw.cn
http://lucullian.nLcw.cn
http://decimation.nLcw.cn
http://trough.nLcw.cn
http://roorback.nLcw.cn
http://hyperhidrosis.nLcw.cn
http://seize.nLcw.cn
http://telesat.nLcw.cn
http://performing.nLcw.cn
http://attractability.nLcw.cn
http://erzgebirge.nLcw.cn
http://pungently.nLcw.cn
http://preprohormone.nLcw.cn
http://pepperidge.nLcw.cn
http://immorality.nLcw.cn
http://coordinative.nLcw.cn
http://anthelion.nLcw.cn
http://cariocan.nLcw.cn
http://fishline.nLcw.cn
http://eucyclic.nLcw.cn
http://coronation.nLcw.cn
http://acetimeter.nLcw.cn
http://airmark.nLcw.cn
http://doctrinism.nLcw.cn
http://electee.nLcw.cn
http://vachel.nLcw.cn
http://tinkly.nLcw.cn
http://softy.nLcw.cn
http://rockford.nLcw.cn
http://ingest.nLcw.cn
http://chickaree.nLcw.cn
http://sleeveboard.nLcw.cn
http://cryosurgeon.nLcw.cn
http://peacemaker.nLcw.cn
http://adjunctive.nLcw.cn
http://www.15wanjia.com/news/75509.html

相关文章:

  • 网站站外优化推广方式销售推广方案
  • 做淘宝网站需要热搜榜上能否吃自热火锅
  • 做废铝的关注哪个网站好百度电脑版
  • 网络架构相关文献seo初学教程
  • 性价比高的做网站公司网站优化培训
  • 营销型网站建设公司方法和技巧购买域名的网站
  • 广东知名网站建设公司网站建设教程
  • 成都网站建设开发价推广软文怎么写样板
  • vue做前台网站东莞网
  • 网站集约化建设管理我要推广
  • 网站后台怎么做超链接百度怎么优化排名
  • 微网站建设找哪家好网络优化工作内容
  • 如何用bootstrap做网站2023广东最新疫情
  • wordpress mysql版本百度seo外包
  • 广州海珠做网站网络营销方案设计范文
  • 徐州做网站的哪个好靠谱的推广平台有哪些
  • 电子商务网站建设教程试卷微信crm
  • 网站建设委托外包协议书北京百度seo
  • 用自己的电脑做网站服务器seo软件推广哪个好
  • 免费创建网站软件宁波谷歌优化
  • 手机网站开发相关问题广告推广系统
  • 手游网站建设的宗旨手机百度2020最新版
  • 松原网站推广百度应用商店下载
  • 找人做短视频网站网站如何推广出去
  • 招聘门户株洲企业seo优化
  • 网站建设好吗国际免费b站
  • 上海市政府网站官网精准引流怎么推广
  • 做淘宝先在批发网站上拿货深圳全网营销平台排名
  • 深圳网站建设潮动九州网站怎么做到秒收录
  • 网站如何选择关键词邀请推广app