LLM之Prompt工程技能总结(三)

LLM之Prompt工程技能总结(三)

首页卡牌对战代号23游戏更新时间:2024-06-07
Retrieval Augmented Generation (RAG) Prompting

RAG整体是一个研究领域,是比较有市场前景的,可以解决模型幻觉等一些问题,能提高输出的质量以及效果。

这里给出一篇RAG的综述:《Retrieval-Augmented Generation for LargeLanguage Models: A Survey》,分别分析了Naive RAG、Advanced RAG和Modular RAG的优劣势,有时间会专门写一篇RAG方向的文章。

RAG的一个基本流程:

添加图片注释,不超过 140 字(可选)

几种主流RAG方案的流程:

添加图片注释,不超过 140 字(可选)

文章同时介绍了,RAG与Fine-Tuning的区别:

RAG can be likened to providing a model with a tailored textbook for information retrieval, ideal for precise information retrieval tasks. In contrast, FT is comparable to a student internalizing knowledge over time, suitable for scenarios requiring replication of specific structures, styles, or formats.

比如Langchain中RAG的一个Prompt:

You are an assistant for question-answering tasks. Use the following pieces of retrieved context to answer the question. If you don't know the answer, just say that you don't know. Use three sentences maximum and keep the answer concise. Question: {{question}} Context: {{context}} Answer:Automatic Reasoning and Tool-use (ART) Prompting

本质上就是LLM Tool相结合,目前可实现的框架很多,如Langchain,ChatGPT自带的Function Call等。

论文:《ART: Automatic multi-step reasoning and tool-use for large language models》

添加图片注释,不超过 140 字(可选)

Prompt如:

You are an assistant that has access to the following set of tools. Here are the names and descriptions for each tool: {tools} Given the user input, return the name and input of the tool to use. Return your response as a JSON blob with 'name' and 'arguments' keys.

Langchain实现Tool,

from langchain_core.prompts import ChatPromptTemplate from langchain.tools.render import render_text_description from langchain_core.tools import tool @tool def multiply(first_int: int, second_int: int) -> int: """Multiply two integers together.""" return first_int * second_int rendered_tools = render_text_description([multiply]) system_prompt = f"""You are an assistant that has access to the following set of tools. Here are the names and descriptions for each tool: {rendered_tools} Given the user input, return the name and input of the tool to use. Return your response as a JSON blob with 'name' and 'arguments' keys.""" prompt = ChatPromptTemplate.from_messages( [("system", system_prompt), ("user", "{input}")] )

其他Tool实现:

https://python.langchain.com/docs/use_cases/tool_use/

Directional Stimulus Prompting

论文《Guiding Large Language Models via Directional Stimulus Prompting》

大致的思想就是,通过一些实体标签,来约束住LLMs要回答的范围以及内容。从而起到对人工控制关键信息,生成高质量摘要的目的。

添加图片注释,不超过 140 字(可选)

Program-Aided Language Models(PAL) Prompting

论文《PAL: Program-aided Language Models》 论文比较早了,2022年发表。本质上还是一种CoT,而且这种Coding的任务现在用LLMs Tool,挂一个解释器会更准确。所以可能在实际应用场景中,作用不大。但是论文的思想还是值得借鉴的。比如对Programing任务进行拆解,通过CoT的方式最终给出答案。 可以用于苏格拉底式的启发式编程使用。

添加图片注释,不超过 140 字(可选)

ReAct Prompting

论文:《REAC T: SYNERGIZING REASONING AND ACTING IN LANGUAGE MODELS》 核心思想还是通过提出多个thought-action-observation的步骤,用于解决任务轨迹。 其实就是针对某一个任务,按照thought-action-observation这一套流程,步骤,分别执行了n次,然后统计n次执行后的结果,输出最优解。复杂度也挺高,但思想比较简单。

Reflection

Reflection这种Prompting思想,我认为非常有用。会对AGI的技术发展起到关键作用。相关论文:

《Reflexion: Language Agents with Verbal Reinforcement Learning》

步骤:

  1. 生成轨迹
  2. 评估
  3. 执行反思
  4. 生成下个轨迹

添加图片注释,不超过 140 字(可选)

如在decision-making, programming, and reasoning方面的Reflection过程。

添加图片注释,不超过 140 字(可选)

代码:

https://github.com/noahshinn/reflexion

其中在西部小镇的项目中,创建的25个智能体,都具备了Reflection的能力。 《Generative Agents: Interactive Simulacra of Human Behavior》

添加图片注释,不超过 140 字(可选)

添加图片注释,不超过 140 字(可选)

Klaus这个Agent的反思树,观察->反思->观察->反思

A reflection tree for Klaus Mueller. The agent’s observations of the world, represented in the leaf nodes, are recursively synthesized to derive Klaus’s self-notion that he is highly dedicated to his research.

Useful Prompt

Directory structure reference[1]

查看全文
大家还看了
也许喜欢
更多游戏

Copyright © 2024 妖气游戏网 www.17u1u.com All Rights Reserved