赛尔号布莱克技能表大全(布莱克的全部技能有哪些)

最近研究在AGI方面投入精力较多,通过Workflow的方式,做了一些LLM+知识库+Tools的Agent。其中Workflow的实现,一种是通过Prompt来编排,另一种是LangGraph的方式。而Prompt书写质量的好坏,也严重影响了最后的效果。整理了当前主流的Prompt写法。其中包括一些Prompt示例,以及一些Prompting的思想。梳理、总结分析了20篇关于Prompt Engineering的论文。

Zero-shot Prompting

Zero-shot指的是在预训练和微调阶段,没有针对某个特定的任务进行训练,但依然在该任务上有准确的预测能力。说明模型的泛化能力、抽象推理能力、知识迁移能力、语义理解和高效的特征表示学习能力不错。指令微调可以提高模型的Zero-shot能力,论文参考《FINETUNED LANGUAGE MODELS ARE ZERO-SHOT LEARNERS》

Zero-shot可以处理以下任务:

理解未见命令(Understanding Unseen Commands)

Understand and Execute commands it has never encountered during its training phase.

任务: 解释一项模型未见过的运动规则。Prompt: 假设有一项运动叫做‘光球大战’,在这项运动中,两队通过控制一束光来得分。请解释这项运动的可能规则。

图片识别(Image Recognition)

Identify objects or animals it has never seen before.

任务: 识别模型未曾见过的动物——“鹦鹉螺”。Prompt: 鹦鹉螺是一种具有螺旋壳和鲜艳颜色的海洋生物,常见于热带海域。根据这些信息,判断以下图片中是否存在鹦鹉螺,并说明理由。

推荐系统(Recommendation Systems)

Suggest items (movies, books, etc.) to users based on descriptions or attributes of the items, even if those specific items have never been rated before.

任务: 推荐用户可能感兴趣的未评分的书籍。Prompt: 给定用户喜欢的是关于'未来科技和人工智能的科幻小说',请推荐一本该用户可能感兴趣但系统中未有评分记录的书籍。

文本分类(Text Classification)

Categorize texts into topics or sentiments it has not been explicitly trained on.

任务: 对于一个新的主题"区块链技术"的文章进行分类。Prompt: 考虑以下段落是关于‘区块链技术’的概念解释、应用案例或对未来的预测。请将其分类为'技术解释'、'应用案例'或'未来预测'。

跨语言理解转换(Cross-lingual Transfer)

A model trained on tasks in one language (e.g., English) can perform the same task in another language (e.g., French) that it was not trained on.

任务: 使用英语完成的模型解释一个中文概念。Prompt: "八卦"在中文中是一个复杂的概念,涉及到宇宙哲学、自然科学以及人的命运。请用英语解释"八卦"的含义及其在文化中的应用。

Few-shot Prompting

虽然大模型有不错的Zero-shot能力,但在更加复杂的任务上仍然不足。Few-shot Prompting可以用来支持大模型进行上下文学习,从而使模型具备更好的表现。Few-shot使用有限数量(10-100个)的标记数据作为上下文的信息,模型会从提供的示例中进行任务抽取,并用于新的、未见过的示例上,通常标记数据很少时可使用该技术。

《Language Models are Few-Shot Learners》主要介绍了增加模型参数来提升Few-shot等场景下的性能。 《Rethinking the Role of Demonstrations:What Makes In-Context Learning Work?》 介绍了Few-shot的一些使用技巧:

示例中,标签空间(所有可能的标签)和输入文本的分布(即不同类型文本的出现频率或样式)都是非常重要的因素,但不受示例中标签是否准确的影响。

the label space and the distribution of the input text specified by the demonstrations are both key to in-context learning (regardless of whether the labels are correct for individual inputs)

明确整体的格式至关重要,如标签未知,即使用随机单词作为标签也比没有标签效果要好。

specifying the overall format is also crucial, e.g., when the label space is unknown, using random English words as labels is significantly better than using no labels;

带有上下文学习目标的meta-training放大了模型在演示方面的效果,比如格式,而不是输入标签的映射。这也是常见的模型幻觉问题,有时候过度依赖于上下文,而导致不能深入理解和预测,增加幻觉的产生。

meta-training with an in-context learning objective magnifies these effects—the models almost exclusively exploit simpler aspects of the demonstrations like the format rather than the input-label mapping.

Few-shot可以处理以下任务:

语言翻译

任务: 将英文翻译成法文。Prompt:英文:I want to eat.法文:Je veux manger.英文:How are you?法文:Comment ça va?英文:It is a beautiful day.法文:

情感分析

任务: 分析客户评论的情绪倾向。Prompt:评论:This product works great!情感:Positive评论:I am disappointed with the service.情感:Negative评论:Their support team is very helpful.情感:This product works great! // PositiveI am disappointed with the service. // NegativeTheir support team is very helpful.

文本摘要

任务: 对新闻文章进行摘要。Prompt:文章:The company reported a 20% increase in profit this quarter, attributing the growth to an increase in sales and cost reduction measures.摘要:Company profit grew 20% this quarter due to higher sales and cost cutting.文章:Sacramento is the wild card here, and having a final game against Portland on Sunday could be the difference that keeps them on the 7-8 line and away from the win-or-go-home 9-10 line. 摘要:

问答系统

任务: 根据提供的信息回答问题。Prompt:文本:The Eiffel Tower is located in Paris, France. It was constructed in 1889.问题:Where is the Eiffel Tower located?答案:Paris, France文本:Alexander Hamilton was one of the founding fathers of the United States.问题:Who was Alexander Hamilton?答案:

生成编程代码

任务: 根据需求描述生成简单的编程代码。Prompt:描述:写一个函数,计算两个数字的和。代码:def add_numbers(a, b): return a + b描述:写一个函数,返回列表中的最大值。代码:

Chain-of-Thought(CoT) Prompting

思维链(CoT)提示通过中间推理步骤实现复杂的推理能力。可以与Few-shot结合起来,在复杂任务推理中能获得更好的结果。

Cot

论文《Chain-of-Thought Prompting Elicits Reasoning in Large Language Models》:介绍了CoT,Paper Image:

赛尔号布莱克技能表大全(布莱克的全部技能有哪些)插图

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

Prompt:The odd numbers in this group add up to an even number: 4, 8, 9, 15, 12, 2, 1.A: Adding all the odd numbers (9, 15, 1) gives 25. The answer is False.The odd numbers in this group add up to an even number: 15, 32, 5, 13, 82, 7, 1. A:Output:Adding all the odd numbers (15, 5, 13, 7, 1) gives 41. The answer is False.

Zero-Shot CoT

论文《Large Language Models are Zero-Shot Reasoners》:本质上是加了"Let's think step by step"这句话,来让模型进一步思考。Paper Image:

赛尔号布莱克技能表大全(布莱克的全部技能有哪些)插图1

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

Prompt:I went to the market and bought 10 apples. I gave 2 apples to the neighbor and 2 to the repairman. I then went and bought 5 more apples and ate 1. How many apples did I remain with?Let's think step by step.Output:First, you started with 10 apples.You gave away 2 apples to the neighbor and 2 to the repairman, so you had 6 apples left.Then you bought 5 more apples, so now you had 11 apples.Finally, you ate 1 apple, so you would remain with 10 apples.

Auto-CoT

论文《AUTOMATIC CHAIN OF THOUGHT PROMPTING IN LARGE LANGUAGE MODELS》:是对Zero-shot CoT的改进,认为Zero-shot CoT在每一步思维链中仍然会产生推理错误,而Manual CoT流程过于复杂并且手写成本巨大,而Auto-CoT是对不同的问题进行采样,并生成推理链来演示。主要有两步:

Stage1: question clustering,聚类问题,将给定的问题划分为几个簇。Stage2: demonstration sampling,示范抽样,从每个聚类簇中选择一个有代表性的问题,并使用简单的启发式算法生成推理链。

Auto-CoT consists of two main stages: (i) question clustering: partition questions of a given dataset into a few clusters; (ii) demonstration sampling: select a representative question from each cluster and generate its reasoning chain using Zero-Shot-CoT with simple heuristics.

Paper Image:

赛尔号布莱克技能表大全(布莱克的全部技能有哪些)插图2

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

实验结果也表明,在10个公开的基准推理任务上,Auto-CoT与Manual-CoT相比,性能持平或超过,说明LLMs能够通过自动构建示例来执行CoT推理。