Prompt-Engineering-Guide 学习摘要1

Posted 单亚林

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Prompt-Engineering-Guide 学习摘要1相关的知识,希望对你有一定的参考价值。

Prompt工程(Prompt-Engineering)是一种用于主动支持和协助工程团队进行及时决策的软件工具。它提供了定量分析工具、多种决策支持方法以及交互式界面,以帮助团队成员更好地理解和评估各种常见的工程风险和决策问题,从而能够更好地做出明智的决策。除此之外,Prompt工程还可以对关键任务和时间表进行监控和预测,以帮助工程团队更好地管理和分配工作量,确保项目顺利完成。——ChatGPT对提示工程的理解

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

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

  基本介绍

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

 

   两个参数。Temperaturetop_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)

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

 

 Prompt:
 Explain antibiotics
 A:
 
 Output:
 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.

 

 Prompt:
 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.
 Explain the above in one sentence:
 
 Output:
 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.

 

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

 Prompt:
 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.
 Mention the large language model based product mentioned in the paragraph above:
 
 Output:
 The large language model based product mentioned in the paragraph above is ChatGPT.

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

 Prompt:
 Answer the question based on the context below. Keep the answer short and concise. Respond "Unsure about answer" if not sure about the answer.
 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.
 Question: What was OKT3 originally sourced from?
 Answer:
 
 Output:
 Mice.

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

 Prompt:
 Classify the text into neutral, negative or positive. 
 Text: I think the vacation is okay.
 Sentiment: neutral 
 
 Text: I think the food was okay. 
 Sentiment:
 
 Output:
 neutral

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

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

 Prompt:
 The following is a conversation with an AI research assistant. The assistant tone is technical and scientific.
 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 blackholes?
 AI:
 
 Output:
 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 is a 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.

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

 Prompt:
 """
 Table departments, columns = [DepartmentId, DepartmentName]
 Table students, columns = [DepartmentId, StudentId, StudentName]
 Create a MySQL query for all students in the Computer Science Department
 """
 
 Output:
 SELECT StudentId, StudentName 
 FROM students 
 WHERE DepartmentId IN (SELECT DepartmentId FROM departments WHERE DepartmentName = \'Computer Science\');

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

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

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

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

 

以上是关于Prompt-Engineering-Guide 学习摘要1的主要内容,如果未能解决你的问题,请参考以下文章