Prompt-Engineering-Guide 學習摘要1

  隨着人工智能的不斷髮展,近期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)

  文本摘要:將文章和概念歸納爲快速易讀的摘要。

 

1 Prompt:
2 Explain antibiotics
3 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 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.

  代碼生成。我們在提示中給定了數據的結構,在描述查詢內容之後,系統提供了對應的代碼。

 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 Department
 6 """
 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, 1
7 Sum: 41 
8 41 is an odd number.

  第三四部分的高級提示方法以及對抗性提示,隨後繼續。

  學習資料:https://github.com/dair-ai/Prompt-Engineering-Guide

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章