最新要闻

广告

手机

iphone11大小尺寸是多少?苹果iPhone11和iPhone13的区别是什么?

iphone11大小尺寸是多少?苹果iPhone11和iPhone13的区别是什么?

警方通报辅警执法直播中被撞飞:犯罪嫌疑人已投案

警方通报辅警执法直播中被撞飞:犯罪嫌疑人已投案

家电

【全球聚看点】Prompt-Engineering-Guide 学习摘要1

来源:博客园

随着人工智能的不断发展,近期ChatGPT的推出成功出圈,吸引了一大波注意力。提示工程(直译)这一新兴行业就走入人们眼帘,当然也可能马上就被自动提示工程给淘汰掉。近期学习提示工程,学一下如何更好跟ai对话生成我们需要的内容。以下内容主要来自学习资料的摘要和翻译,以及个人理解。目前学习只停留在理论阶段,实践有限。

主要分成4部分。第一部分为基本介绍。第二部分为基础提示方法。第三部分为高级提示方法及相关应用。第四部分为对抗性提示。

基本介绍


(资料图片)

资料地址:Prompt-Engineering-Guide/prompts-intro.md at main · dair-ai/Prompt-Engineering-Guide (github.com)

两个参数。Temperature和top_p,作用接近,一般只修改一个。参数值低,更容易获得确定性答案。参数值高,更容易获得创造性答案。比较好理解一点就是,温度越高,思维越活跃,更容易感性的天马行空,温度越低,思维越理性,更容易给出确定性的回复。

提示的要素:

1.指令。你希望模型执行的特定任务或指令,例如:“列出list”,“分类Classify”,“总结Summarize”,“翻译Translate“,“排序Order”等。

2.上下文。可以涉及外部信息或其他上下文,从而更好的引导模型

3.输入数据。我们感兴趣想要找到答案的输入或者问题。

4.输出数据。明确类型或输出格式。

设计提示的通常技巧:

特异性:具体说明希望模型执行的指令和任务。描述和提示越详细,结果越好。例如在提示中提供示例,对于获取特定格式的输出很有效。

避免不精确性:信息传递的越直接,越有效。例如使用具体、简洁、切中要害的提示。

该做和不该做:避免在提示中出现不该做什么,而是该做什么。鼓励更多的特异性,聚焦在模型给出的良好回复。

基础提示方法

资料地址:Prompt-Engineering-Guide/prompts-basic-usage.md at main · dair-ai/Prompt-Engineering-Guide (github.com)

文本摘要:将文章和概念归纳为快速易读的摘要。

1 Prompt:2 Explain antibiotics3 A:4 5 Output:6 Antibiotics are a type of medication used to treat bacterial infections. They work by either killing the bacteria or preventing them from reproducing, allowing the body’s immune system to fight off the infection. Antibiotics are usually taken orally in the form of pills, capsules, or liquid solutions, or sometimes administered intravenously. They are not effective against viral infections, and using them inappropriately can lead to antibiotic resistance.
1 Prompt:2 Antibiotics are a type of medication used to treat bacterial infections. They work by either killing the bacteria or preventing them from reproducing, allowing the body’s immune system to fight off the infection. Antibiotics are usually taken orally in the form of pills, capsules, or liquid solutions, or sometimes administered intravenously. They are not effective against viral infections, and using them inappropriately can lead to antibiotic resistance.3 Explain the above in one sentence:4 5 Output:6 Antibiotics are medications used to treat bacterial infections by either killing the bacteria or stopping them from reproducing, but they are not effective against viruses and overuse can lead to antibiotic resistance.

信息提取。以下示例,给人更直观的感觉像是一个阅读理解,问题的具体形式却像是个填空题。这样的提示方式更容易获得确切的结果。

1 Prompt:2 Author-contribution statements and acknowledgements in research papers should state clearly and specifically whether, and to what extent, the authors used AI technologies such as ChatGPT in the preparation of their manuscript and analysis. They should also indicate which LLMs were used. This will alert editors and reviewers to scrutinize manuscripts more carefully for potential biases, inaccuracies and improper source crediting. Likewise, scientific journals should be transparent about their use of LLMs, for example when selecting submitted manuscripts.3 Mention the large language model based product mentioned in the paragraph above:4 5 Output:6 The large language model based product mentioned in the paragraph above is ChatGPT.

问答。一个好的提示可以通过组合指令、上下文、输入和输出四个要素来获取更好的回答。

1 Prompt:2 Answer the question based on the context below. Keep the answer short and concise. Respond "Unsure about answer" if not sure about the answer.3 Context:Teplizumab traces its roots to a New Jersey drug company called Ortho Pharmaceutical. There, scientists generated an early version of the antibody, dubbed OKT3. Originally sourced from mice, the molecule was able to bind to the surface of T cells and limit their cell-killing potential. In 1986, it was approved to help prevent organ rejection after kidney transplants, making it the first therapeutic antibody allowed for human use.4 Question:What was OKT3 originally sourced from?5 Answer:6 7 Output:8 Mice.

文本分类。如果指定回复格式或内容,可以在上下文举例(少量样本,零样本可能效果不好)。零样本见参考资料,注意零样本的大小写,虽然只是大小写的差异,但没有按照指定内容输出。

1 Prompt: 2 Classify the text into neutral, negative or positive.  3 Text: I think the vacation is okay. 4 Sentiment: neutral 5  6 Text: I think the food was okay.  7 Sentiment: 8  9 Output:10 neutral

会话。构建会话系统时,指定系统的意图和身份,观察系统如何运行是一个有趣的过程。

例如以下两个示例,我们在指定了系统不同的身份之后,明显发现示例2中的回答更加简单易懂。

1 Prompt:2 The following is a conversation with an AI research assistant. The assistant tone is technical and scientific.3 Human: Hello, who are you?4 AI: Greeting! I am an AI research assistant. How can I help you today?5 Human: Can you tell me about the creation of blackholes?6 AI:7 8 Output:9 Sure! Black holes are regions of spacetime where the gravitational force is so strong that nothing, not even light, can escape from it. They are created when a very massive star dies and its core collapses in on itself, forming a singularity of infinite density. The intense gravity of the singularity pulls in all the matter and radiation around it, creating the black hole.
Prompt:The following isa conversation with an AI research assistant. The assistant answers should be easy to understand even by primary school students.Human: Hello, who are you?AI: Greeting! I am an AI research assistant. How can I help you today?Human: Can you tell me about the creation of black holes?AI: Output:Sure! Black holes are created when a very massive star runs out of fuel and collapses in on itself. The gravity of the star is so strong that nothing, not even light, can escape its pull. This creates a point in space-time with an intense gravitational force called a black hole.

代码生成。我们在提示中给定了数据的结构,在描述查询内容之后,系统提供了对应的代码。

1 Prompt: 2 """ 3 Table departments, columns = [DepartmentId, DepartmentName] 4 Table students, columns = [DepartmentId, StudentId, StudentName] 5 Create a MySQL query for all students in the Computer Science Department6 """ 7  8 Output: 9 SELECT StudentId, StudentName 10 FROM students 11 WHERE DepartmentId IN (SELECT DepartmentId FROM departments WHERE DepartmentName = "Computer Science");

推理。LLM最困难的任务之一是需要某种形式的推理。可以尝试分步骤引导,也就是后续提到的思维链。Let’s think step by step,给AI一点鼓励,他的表现可能回更好。以下示例是相对良好的示例,不良示例参考学习资料。

1 Prompt:2 The odd numbers in this group add up to an even number: 15, 32, 5, 13, 82, 7, 1. 3 Solve by breaking the problem into steps. First, identify the odd numbers, add them, and indicate whether the result is odd or even. 4 5 Output:6 Odd numbers: 15, 5, 13, 7, 17 Sum: 41 8 41 is an odd number.

第三四部分的高级提示方法以及对抗性提示,随后继续。

学习资料:https://github.com/dair-ai/Prompt-Engineering-Guide

关键词: