智辉网络

智辉网络

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

admin
LLM之Prompt工程技能总结(二)-第1张-游戏资讯-智辉网络

前言:

今天小伙伴们对“赛尔号布莱克技能表大全”大约比较关切,朋友们都想要剖析一些“赛尔号布莱克技能表大全”的相关文章。那么小编也在网摘上网罗了一些关于“赛尔号布莱克技能表大全””的相关资讯,希望兄弟们能喜欢,看官们快快来了解一下吧!
LLM之Prompt工程技能总结(一)Active-Prompt

论文《Active Prompting with Chain-of-Thought for Large Language Models》:作者发现,LLM在某些特别任务上回答问题时,会存在不确定性。即生成的答案多样,不确定。为解决这一问题,通过主动学习的方式,从大量未标注的问题中选择最具有不确定性的问题进行人工注释,以此来构建有效的提示(prompt),从而提高大型语言模型(LLMs)解决复杂推理任务的能力。

Paper Image:

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

步骤如上图所示,分四步:

不确定性估计:让LLM尝试解决这个数据集中的问题,并观察它在哪些问题上表现得最不确定。比如,我们让模型尝试解答每个问题若干次,并记录下来它给出的不同答案。如果一个问题的答案在多次尝试中变化很大,那么我们认为模型在这个问题上的不确定性很高。选择问题进行注释:根据不确定性的评估,选择一些最不确定的问题。人工注释推理链:为这些选定的问题编写详细的推理链。使用新的注释推理:再次使用LLM解答问题时,会在输入中包含这些人工注释的推理链示例。LLM在解答新的、未见过的问题时,就可以参考这些示例中的推理过程,从而提高解答问题的能力。Multimodal CoT Prompting

论文《Multimodal Chain-of-Thought Reasoning in Language Models》,Paper Image: Multimodal CoT Task

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

CoT比较注重语言的形式,处理文本比较有优势,Multimodal CoT主要是将文本和视觉结合到一个两阶段的框架中,两阶段共享想通的模型结构,但输入和输出不同。

Stage1: rationale generation,将输入问题在不同模态(文本和图像)下进行处理,生成中间的推理链;Stage2: answer inference. 将这些推理链与原始问题一起用于推断最终的答案。

Both stages share the same model architecture but differ in the input and output. In the first stage, we feed the model with language and vision inputs to generate rationales. In the second stage, we append the original language input with the rationale generated from the first stage. Then, we feed the updated language input with the original vision input to the model to infer the answer.

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

Self-Consistency CoT

论文:《SELF-CONSISTENCY IMPROVES CHAIN OF THOUGHT REASONING IN LANGUAGE MODELS》 感觉没啥创意,核心思想就是先通过CoT的方式,生成多条推理链。再分别用多条推理链去去推理,选择概率较高的结果作为最终结果,虽然能提升准确率,但也比较浪费资源。

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

The self-consistency method contains three steps: (1) prompt a language model usingchain-of-thought (CoT) prompting; (2) replace the “greedy decode” in CoT prompting by sampling from the language model’s decoder to generate a diverse set of reasoning paths; (3) marginalize out the reasoning paths and aggregate by choosing the most consistent answer in the final answer set.

Generated Knowledge Prompting

论文《Generated Knowledge Prompting for Commonsense Reasoning》,这篇论文比较早2022年的,其实后来的Few-shot Prompting跟此方法类似,或者说Few-shot Prompting包含了该Prompting的写法。核心思想就是在不需要访问结构化知识库或着进行特定任务微调的情况下,通过生成知识来提升大模型在常识推理任务上的性能。主要分两步:

知识生成:使用语言模型根据问题生成知识声明,然后将这些知识作为输入提示与问题一起用于推断答案。这一步骤不需要任何结构化的知识库。知识集成:生成的知识被整合到决策过程中,以增强语言模型用于推理的能力。这个过程通过提高零样本或微调模型在特定任务上的表现。

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

一个论文中的Prompt例子:

Prompt:Generate some knowledge about the input. Examples:Input: What type of water formation is formed by clouds?Knowledge: Clouds are made of water vapor.Input: What can prevent food spoilage?Knowledge: Dehydrating food is used for preserving food.Input: The process by which genes are passed isKnowledge: Genes are passed from parent to offspring.Input: The stomach does what in the body?Knowledge: The stomach is part of the digestive system.Input: What can cause rocks to break down?Knowledge: Mechanical weathering is when rocks are broken down by mechanical means.Input: {question}Knowledge:
Prompt Chaining

Prompt Chaining涉及使用一个提示的输出作为另一个提示的输入。通过链接提示在一起。通过引导LLMs一系列子任务,从而实现一个复杂的目标。这种Prompting的思想就是将任务拆分,每个子任务就是一个chain,在Langchain比较常见。

以下场景可以使用Prompt Chaining:

Multi-step tasks: 如果任务需要多个不同的步骤,Workflow的方式,Chaining Prompts可以确保每一步执行完成后,完成一个复杂的任务。Complex instructions: 指令比较负责,单个Prompt包含的指令和细节较多,LLMs难以始终如一的完成这些指令和细节。可以将任务拆解为一系列连锁的子任务,可以提高每个子任务的完成度。Verifying outputs: 可以使用Chaining要求LLMs去重复验证其输出的结果,并可以要求对结果进行改进。Parallel processing: 并行处理,如果任务有多个独立的子任务,可以为子任务创建单独的提示,并行运行。

高效Prompt Chaining Tips:

Keep subtasks simple and clearUse XML tags

https://docs.anthropic.com/claude/docs/chain-prompts

Multi-step

提取引用信息,一个task:

Here is a document, in <document></document> XML tags:<document>{{DOCUMENT}}</document>Please extract, word-for-word, any quotes relevant to the question {{QUESTION}}. Please enclose the full list of quotes in <quotes></quotes> XML tags. If there are no quotes in this document that seem relevant to this question, please say "I can't find any relevant quotes".

将提取的引用信息结果,作为Knowledge,回答问题, 两个task:

I want you to use a document and relevant quotes from the document to answer a question.Here is the document:<document>{{DOCUMENT}}</document>Here are direct quotes from the document that are most relevant to the question:<quotes>{{QUOTES}}</quotes>Please use these to construct an answer to the question "{{QUESTION}}"Ensure that your answer is accurate and doesn't contain any information not directly supported by the quotes.
Validating outputs

比如一个task,先根据文章内容,来列举文章的语法错误:

Here is an article:<article>{{ARTICLE}}</article>Please identify any grammatical errors in the article. Please only respond with the list of errors, and nothing else. If there are no grammatical errors, say "There are no errors."

两个task,分析文章的语法错误,与列举的语法Errors list作比较:

Here is an article:<article>{{ARTICLE}}</article>Please identify any grammatical errors in the article that are missing from the following list:<list>{{ERRORS}}</list>If there are no errors in the article that are missing from the list, say "There are no additional errors."
Parallel processing

生成不同版本的文章:

Here is a concept: {{CONCEPT}}I want you to write a three sentence outline of an essay about this concept that is appropriate for this level of reader: {{LEVEL}}Please only respond with your outline, one sentence per line, in <outline></outline> XML tags. Don't say anything else.
Tree of Thoughts (ToT)

ToT的思想是模拟人的思考过程,构建思考树,来探索不同的解决方案路径。可以提高LLMs的能力,能更加有效的对复杂任务进行深入推理,找到更加合理的、有效的解决方案。

两篇论文,分别总结分析了ToT的思想,以及ToT区别于其他CoT在应用场景上的优势。 《Large Language Model Guided Tree-of-Thought》 《Tree of Thoughts: Deliberate Problem Solving with Large Language Models》

ToT与CoT、CoT-SC的结构对比:

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

ToT的思考过程,以及在System中的架构:

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

ToT的流程非常有意思,可以结合BFS和DFS的算法来制定整个ToT的策略,当局部最优不等于全局最优时,可能会产生不同的结果。BFS的方案,认为是局部最优就决定了全局最优,会对每一步制定多个plan,再对每个plan的结果进行奇数次的选举,得票最高的plan会作为这一步的策略,再进行第二个任务的plan。直到最后,会生成一条plan链,推理出最终的结果。

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

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

论文官方代码:

https://github.com/dave1010/tree-of-thought-prompting

但个人认为,ToT的这种策略在规定plan数量以及step数量时,不宜过长。plan为3就够了,step最好不超过5。



标签 赛尔号布莱克技能表大全