国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當前位置: 首頁 > news >正文

加工平臺快抖霸屏樂云seo

加工平臺,快抖霸屏樂云seo,廣州高鐵新建站在哪里,產(chǎn)品查詢展示型網(wǎng)站分類目錄:《大模型從入門到應用》總目錄 下面這個示例展示了如何在索引上進行問答: 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方法中指定鏈的類型參數(shù)。這允許我們傳入要使用的鏈的類型的名稱。例如,在下面的示例中,我們將鏈的類型更改為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."

上述方法確實簡單地更改了鏈的類型,但它對該鏈的類型的參數(shù)提供了很大的靈活性。如果我們想要控制這些參數(shù),可以直接加載鏈式,然后將其直接傳遞給RetrievalQA鏈的combine_documents_chain參數(shù),例如:

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."

返回源文檔

此外,我們可以通過在構建鏈式時指定一個可選參數(shù)來返回用于回答問題的源文檔。

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)]

使用源文檔進行檢索式問答

本節(jié)介紹了如何在索引上使用源文檔進行問答。它通過使用RetrievalQAWithSourcesChain實現(xiàn),該鏈式結構可以從索引中查找文檔。

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方法中指定鏈類型參數(shù),這允許我們傳遞要使用的鏈類型的名稱。例如,在下面的示例中,我們將鏈類型更改為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'}

上述方法允許我們非常簡單地更改鏈式類型,但它確實在鏈的類型的參數(shù)上提供了很大的靈活性。如果我們想控制這些參數(shù),可以直接加載鏈式結構,然后使用combine_documents_chain參數(shù)將其直接傳遞給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官方網(wǎng)站:https://www.langchain.com/
[2] LangChain 🦜?🔗 中文網(wǎng),跟著LangChain一起學LLM/GPT開發(fā):https://www.langchain.com.cn/
[3] LangChain中文網(wǎng) - LangChain 是一個用于開發(fā)由語言模型驅動的應用程序的框架:http://www.cnlangchain.com/

http://m.aloenet.com.cn/news/28366.html

相關文章:

  • 難道做網(wǎng)站的工資都不高嗎百度銷售推廣
  • 南寧網(wǎng)站建設代理婚戀網(wǎng)站排名前十名
  • 東坑鎮(zhèn)仿做網(wǎng)站baidu百度
  • 網(wǎng)站做404好處直播:英格蘭vs法國
  • 商丘市網(wǎng)站建設公司合肥網(wǎng)站優(yōu)化軟件
  • 求職簡歷模板電子版免費seo怎么做優(yōu)化計劃
  • 黃埔區(qū)做網(wǎng)站英文外鏈seo兼職
  • 中學生制作網(wǎng)站怎么做百度廣告買下的訂單在哪里找
  • 中國十大建筑設計事務所北京自動seo
  • 做公眾號關注網(wǎng)站整站關鍵詞快速排名
  • 畢業(yè)設計做網(wǎng)站怎么答辯千牛怎么做免費推廣引流
  • 發(fā)布網(wǎng)站建設信息百度網(wǎng)站推廣價格
  • 項目營銷策劃方案360優(yōu)化大師官方下載
  • dede可以做視頻網(wǎng)站百度關鍵詞指數(shù)排行
  • 羅源網(wǎng)站建設seo搜索引擎優(yōu)化技術教程
  • iis7 無法添加網(wǎng)站網(wǎng)站優(yōu)化聯(lián)系
  • 云南城市建設職業(yè)學院網(wǎng)站軟文推廣渠道
  • 移動端的網(wǎng)站怎么做今日全國最新疫情通報
  • 幾分鐘弄清楚php做網(wǎng)站手機系統(tǒng)優(yōu)化
  • 昆明網(wǎng)絡營銷網(wǎng)站怎么提高seo關鍵詞排名
  • 寶豐網(wǎng)站建設長春網(wǎng)站建設
  • 淘寶客網(wǎng)站虛擬主機盤多多百度網(wǎng)盤搜索引擎
  • 如何管理好一個網(wǎng)站怎樣才能注冊自己的網(wǎng)站
  • web網(wǎng)站雙語切換怎么做在線seo短視頻
  • 有關網(wǎng)站建設的公眾號2022最好的百度seo
  • 怎么做網(wǎng)站的步驟網(wǎng)站制作的要點和步驟詳解
  • 網(wǎng)站接入地查詢互聯(lián)網(wǎng)最賺錢的行業(yè)
  • 轉轉怎么做釣魚網(wǎng)站知名網(wǎng)絡營銷推廣
  • 桂林手機網(wǎng)站建設seo推廣經(jīng)驗
  • 購物網(wǎng)站建設機構網(wǎng)絡營銷策略分析方法