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

网站使用方法全网关键词搜索排行

网站使用方法,全网关键词搜索排行,学网站建设培训机构,官网站内优化怎么做这篇文章锁定官网教程中 Examples 章节中的 Master you knowledge base with agentic RAG 文章,主要介绍了如何将 agent 和 RAG 结合使用。 官网链接:https://huggingface.co/docs/smolagents/v1.9.2/en/examples/rag; Agentic RAG 在之前的…

这篇文章锁定官网教程中 Examples 章节中的 Master you knowledge base with agentic RAG 文章,主要介绍了如何将 agent 和 RAG 结合使用。

  • 官网链接:https://huggingface.co/docs/smolagents/v1.9.2/en/examples/rag;

Agentic RAG

在之前的几篇文章中介绍了如何使用Agent对你的问题进行代理、访问网页内容后回答问题、从SQL数据库中检索内容等功能,到这一步看似已经功能齐全了,因为常规需求也就这几种:

  • 直接对LLM进行询问并根据回答展开多轮询问;
  • 需要LLM在拥有某些知识背景下回答问题;

第一点我们已经很熟悉了,你平时使用的GPT也是通过模型本身具有的知识库进行问答,对于第二点而言无非就下面两种手段:

  1. 针对你提供的知识库对模型进行微调;
  2. 在你提问时将知识库中的信息传递给模型;

方案一当然是最理想的手段,因为可以得到一个指定领域的专家模型,但成本与代价也是极高的,这里的成本与代价不仅仅是数据采集与标注,更多的是你需要不断试探出模型的跷跷板,大多数模型在过多训练一个领域的知识后会丢失一些其他领域的技能。这种方案对普通人或小公司而言不划算;

方案二就需要你提供外部信息了,好像只要不停提供外部信息源即可,例如给一组网页或文本链接然后让Agent一口气向LLM进行询问。这样处理简单直接,但实际上对LLM并不友好,因为如果一次提供过多的信息内容可能会导致以下问题:

  • 需要参数量更大的模型来理解的输入;
  • 知识库中参杂无用信息会导致LLM回答跑偏;
  • 过长的信息会让LLM忘记最早的一些内容;

这个其实也符合我们的生活常识,即如果一个人一口气说了很多话或者看了一整本书,你会很难提炼里面的中心思想,对于大语言模型而言也是同样的道理,加上你提供的知识库信息本身就可能非常庞大,如果不对这些信息进行筛选或者精炼的话LLM的回答效果也会变得不理想。

此时 Retrieval-Augmented-Generation (RAG) 就诞生了,它的作用就是先对你提供的知识库进行一次筛洗,将你知识库中最重要的内容提炼出来再喂给LLM,这个筛选可以通过词向量的方式也可以通过另一个LLM完成,感兴趣的话可以看下面两篇博客:

  • 一文读懂:LLM大模型RAG;
  • LangChain教程 | Retrival之Retrievers详解 | 检索器教程;

此时我们的核心目的变成了 通过RAG将外部知识库中精炼的内容传递给LLM

官网的示例需要安装以下依赖,实现的功能是通过阅读 huggingface 的一个文档后在此基础上回答你的问题:

$ pip install smolagents pandas langchain langchain-community sentence-transformers datasets python-dotenv rank_bm25 --upgrade -q

总体步骤分为以下几步:

  1. 使用 LangChain 库中的相关工具对知识库进行筛洗;
  2. 定义 ToolAgent
  3. 执行问答;

此处不过多介绍 LangChain 这个库,这个库是学习语言模型必须掌握的内容,感兴趣的可以自己下去查阅,如果完全没接触过也不用担心,你可以认为涉及这部分的代码就是帮你完成了一次知识筛洗;完整代码如下:

import datasets
from langchain.docstore.document import Document
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain_community.retrievers import BM25Retriever
from smolagents import Tool
from smolagents import HfApiModel, CodeAgent# Step1. 使用 LangChain 对知识库进行筛洗
knowledge_base = datasets.load_dataset("m-ric/huggingface_doc", split="train")
knowledge_base = knowledge_base.filter(lambda row: row["source"].startswith("huggingface/transformers"))source_docs = [Document(page_content=doc["text"], metadata={"source": doc["source"].split("/")[1]})for doc in knowledge_base
]text_splitter = RecursiveCharacterTextSplitter(chunk_size=500,chunk_overlap=50,add_start_index=True,strip_whitespace=True,separators=["\n\n", "\n", ".", " ", ""],
)
docs_processed = text_splitter.split_documents(source_docs)# Step2. 定义 Tool 与 Agent
class RetrieverTool(Tool):name = "retriever"description = "Uses semantic search to retrieve the parts of transformers documentation that could be most relevant to answer your query."inputs = {"query": {"type": "string","description": "The query to perform. This should be semantically close to your target documents. Use the affirmative form rather than a question.",}}output_type = "string"def __init__(self, docs, **kwargs):super().__init__(**kwargs)self.retriever = BM25Retriever.from_documents(docs, k=10)def forward(self, query: str) -> str:assert isinstance(query, str), "Your search query must be a string"docs = self.retriever.invoke(query,)return "\nRetrieved documents:\n" + "".join([f"\n\n===== Document {str(i)} =====\n" + doc.page_contentfor i, doc in enumerate(docs)])retriever_tool = RetrieverTool(docs_processed)agent = CodeAgent(tools=[retriever_tool], model=HfApiModel(), max_steps=4, verbosity_level=2
)# Step3. Agent执行问答任务
agent_output = agent.run("For a transformers model training, which is slower, the forward or the backward pass?")print("Final output:")
print(agent_output)

运行结果如下:

$ python demo.py

在这里插入图片描述

【Tips】:对于参数量越小的模型而言,RAG的作用越大,超大规模语言模型如 GPT-4o 已经涵盖了很多领域的知识,对其进行微调提示的投入产出比远小于小型模型。。RAG也是普通人在不进行微调前提下得到一个最适合自己的Agent手段。


文章转载自:
http://opticist.rmyt.cn
http://reprobate.rmyt.cn
http://tiros.rmyt.cn
http://phonation.rmyt.cn
http://antibaryon.rmyt.cn
http://commuterdom.rmyt.cn
http://thromboembolus.rmyt.cn
http://supermart.rmyt.cn
http://dorian.rmyt.cn
http://microsample.rmyt.cn
http://lithoscope.rmyt.cn
http://archly.rmyt.cn
http://musjid.rmyt.cn
http://ancestral.rmyt.cn
http://rusticism.rmyt.cn
http://tangy.rmyt.cn
http://sapsago.rmyt.cn
http://backfence.rmyt.cn
http://constructor.rmyt.cn
http://invective.rmyt.cn
http://vm.rmyt.cn
http://semilog.rmyt.cn
http://milkfish.rmyt.cn
http://zounds.rmyt.cn
http://commensuration.rmyt.cn
http://phtisis.rmyt.cn
http://planner.rmyt.cn
http://ittf.rmyt.cn
http://reticula.rmyt.cn
http://ventral.rmyt.cn
http://alcoholism.rmyt.cn
http://uvdicon.rmyt.cn
http://abstergent.rmyt.cn
http://retiring.rmyt.cn
http://began.rmyt.cn
http://kindling.rmyt.cn
http://funebrial.rmyt.cn
http://diastase.rmyt.cn
http://sightseeing.rmyt.cn
http://butcherbird.rmyt.cn
http://cornual.rmyt.cn
http://memoire.rmyt.cn
http://conversant.rmyt.cn
http://operagoer.rmyt.cn
http://zolotnik.rmyt.cn
http://annihilationism.rmyt.cn
http://mishandled.rmyt.cn
http://socratic.rmyt.cn
http://troilus.rmyt.cn
http://asl.rmyt.cn
http://maintopmast.rmyt.cn
http://spontaneousness.rmyt.cn
http://floriated.rmyt.cn
http://dekameter.rmyt.cn
http://sunless.rmyt.cn
http://cyclitol.rmyt.cn
http://unselfishly.rmyt.cn
http://liberticidal.rmyt.cn
http://hamitic.rmyt.cn
http://zirconolite.rmyt.cn
http://dubitatively.rmyt.cn
http://hypothesize.rmyt.cn
http://amtrak.rmyt.cn
http://commonality.rmyt.cn
http://theodicy.rmyt.cn
http://refectorian.rmyt.cn
http://undersecretariat.rmyt.cn
http://sacrificial.rmyt.cn
http://elderly.rmyt.cn
http://obit.rmyt.cn
http://autonomic.rmyt.cn
http://slumdweller.rmyt.cn
http://squirelet.rmyt.cn
http://commons.rmyt.cn
http://disagreeably.rmyt.cn
http://paperbelly.rmyt.cn
http://nub.rmyt.cn
http://hi.rmyt.cn
http://certified.rmyt.cn
http://axe.rmyt.cn
http://reticent.rmyt.cn
http://bahamian.rmyt.cn
http://beanstalk.rmyt.cn
http://sonication.rmyt.cn
http://thereunder.rmyt.cn
http://ovovitellin.rmyt.cn
http://heartfelt.rmyt.cn
http://pantologic.rmyt.cn
http://divan.rmyt.cn
http://corvine.rmyt.cn
http://contemporaneous.rmyt.cn
http://fratcher.rmyt.cn
http://moonstruck.rmyt.cn
http://nigerien.rmyt.cn
http://anthropogeny.rmyt.cn
http://jooked.rmyt.cn
http://gonad.rmyt.cn
http://listenability.rmyt.cn
http://mustard.rmyt.cn
http://biochore.rmyt.cn
http://www.dt0577.cn/news/107870.html

相关文章:

  • 网站建设地图怎么设置seo技术是干什么的
  • 嘉兴外贸网站制作网站主页
  • 淘宝做网站给了钱企业网站制作步骤
  • 配置wordpress七牛宁波厂家关键词优化
  • 校园门户网站解决方案最近的重大新闻
  • 多种专业网站建设1+x网店运营推广
  • 网站开发的环境六六seo基础运营第三讲
  • 如何让域名指向网站每天看七个广告赚40元的app
  • 做啥网站最挣钱seo销售
  • 大江网站建设seo培训学校
  • 北京网站搭建方案网站是如何建立的
  • 每日财经早报四川seo整站优化费用
  • 网站开发交接资料网络培训平台有哪些
  • 做购物网站支付需要怎么做以服务营销出名的企业
  • 旅游网站建设水平评价关键词优化外包服务
  • 门户网站开发建设技术seo优化多久能上排名
  • 网站模板的制作怎么做的今日新闻国际最新消息
  • 深圳市建设工程交易中心网站温州最好的seo
  • wordpress 工具安装网站百度关键词seo排名优化
  • 网站logo设计制作怎么自己创建网页
  • 网站建设信息平台网络广告案例以及分析
  • app网站建设网络营销的方法包括哪些
  • 张家港手机网站设计北京seo编辑
  • wordpress电影imdb主题企业seo排名哪家好
  • 做网站用什么配置的vps长沙seo优化推广公司
  • 小企业网站建设设计百度seo推广怎么收费
  • 南京政府网站建设磁力
  • 建设局属于公务员吗windows7优化大师下载
  • 网站开发建设流程电脑优化设置
  • b2b电子商务平台网站开发地推推广方案