ChatGPT Prompt Engineering – 1. 基本原则 (1)

Andrew Ng 最近在他的 deeplearning.ai 上发布了 ChatGPT Prompt Engineering for Developers 教程。这个教程大概一个半小时左右,属于 how to 而非 what is,虽然标题带有 for Developers,但不需要编程基础也可以看懂。

这篇文章是我对 Andrew 教程的 notes + 简短总结。并非原创,只是为了自己学习+记忆方便。文章中的输入/输出使用 ChatGPT 的免费版本。

看完教程的一些感想:

  1. Prompt Engineering,与其说它是 engineering 不如应该说它是 communication,使用与人对话的方式,而非机械思维,可以得到更合理的答案
  2. 编程思维可以有效改善 Prompt Engineering:比如使用分隔符,结构化输出,条件验证这些技巧
  3. Somehow ChatGPT 看似具备了抽象,比喻,概括等我们之前认为只有人类才具备的语言能力,利用这些能力,我们可以大大提升我们的信息获取/生成效率
  4. ChatGPT 将会取代重复性较高,创意性较低的知识型工作,比如文员,翻译,插画师等等
  5. 可以用 ChatGPT 进行 task-based 编程,但我不认为可以用 ChatGPT 开发较复杂的软件(我很难想象如何用 ChatGPT 进行功能迭代)
  6. ChatGPT 是乘法,我的理解是:a (你的能力) × b(你使用 ChatGPT 的能力) × c(ChatGPT 模型的能力)
  7. 考虑到各大公司对 xGPT 的投入力度,c 会随着时间大幅增长,所以 xGPT 可能是自计算机出现以来,人类最强的 knowledge leverage
  8. b 需要 programming thinking, creative thinking, 以及 lateral thinking, which might be a good thing or bad thing for programmers
  9. a 取决与自己的 knowns 和 known unknowns,所以我们可能需要努力减少自己的 unknown unknowns,而非做一个专才

不废话了,下面是 notes,夹杂一些自己的感想:

基本原则

原则 1:使用明确的指令

技巧 1:使用分隔符

使用不常见的字符组合 ~~~ 或 ”’ 作为分隔符,用来提供明确的输入。

输入:

Summarize the text delimited by triple backticks into a single sentence.

```
You should express what you want a model to do by providing instructions that are as clear and specific as you can possibly make them.  This will guide the model towards the desired output, and reduce the chances of receiving irrelevant or incorrect responses. Don't confuse writing a clear prompt with writing a short prompt. In many cases, longer prompts provide more clarity and context for the model, which can lead to more detailed and relevant outputs.
```

输出:

Providing clear and specific instructions to a model will guide it towards the desired output and reduce the chances of receiving irrelevant or incorrect responses, and longer prompts can provide more clarity and context for the model, leading to more detailed and relevant outputs.

技巧 2:使用结构化输出

要求输出 JSON 或 HTML,以便接下来程序处理

输入:

Generate a list of three made-up book titles along with their authors and genres. Provide them in JSON format with the following keys: book_id, title, author, genre.

输出:

Here are three made-up book titles, authors, and genres in JSON format:

[ { "book_id": 1, "title": "The Lighthouse's Keeper", "author": "Marina Lee", "genre": "Mystery" }, { "book_id": 2, "title": "The Art of Breaking Rules", "author": "Isaac Cole", "genre": "Self-Help" }, { "book_id": 3, "title": "The Last of the Starlight Symphony", "author": "Sophia Kim", "genre": "Science Fiction" }]

技巧 3:进行条件检验

这个技巧类似于编程中的 if-else check,即在进行处理之前先检验输入是否符合转换条件

输入(符合条件):

You will be provided with text delimited by triple backticks. 

If it contains a sequence of instructions, re-write those instructions in the following format:

Step 1 - ...
Step 2 - …
…
Step N - …

If the text does not contain a sequence of instructions, then simply write "No steps provided."

```
Making a cup of tea is easy! First, you need to get some water boiling. While that's happening, grab a cup and put a tea bag in it. Once the water is hot enough, just pour it over the tea bag. Let it sit for a bit so the tea can steep. After a few minutes, take out the tea bag. If you like, you can add some sugar or milk to taste. And that's it! You've got yourself a delicious cup of tea to enjoy.
```

输出:


Here are the instructions for making a cup of tea:

Step 1 - Get some water boiling.
Step 2 - While the water is boiling, grab a cup and put a tea bag in it.
Step 3 - Once the water is hot enough, pour it over the tea bag.
Step 4 - Let the tea steep for a few minutes.
Step 5 - Remove the tea bag.
Step 6 - If desired, add some sugar or milk to taste.
Step 7 - Enjoy your delicious cup of tea!

输入(不符条件):

You will be provided with text delimited by triple backticks. 

If it contains a sequence of instructions, re-write those instructions in the following format:

Step 1 - ...
Step 2 - …
…
Step N - …

If the text does not contain a sequence of instructions, then simply write "No steps provided."

```
The sun is shining brightly today, and the birds are singing. It's a beautiful day to go for a walk in the park. The flowers are blooming, and the trees are swaying gently in the breeze. People are out and about, enjoying the lovely weather. Some are having picnics, while others are playing games or simply relaxing on the grass. It's a perfect day to spend time outdoors and appreciate the beauty of nature.
```

输出:


No steps provided.

技巧 4:使用类比

(这个可能是大多数人的 aha moment,前面的输入输出还在我所理解的 NLP 范畴之内,支持类比,直接让我惊掉下巴)

输入:

Your task is to answer in a consistent style.

<child>: Teach me about patience.

<grandparent>: The river that carves the deepest valley flows from a modest spring; the grandest symphony originates from a single note; the most intricate tapestry begins with a solitary thread.

<child>: Teach me about resilience.

输出:

<grandparent>: Resilience is like a tree that bends and sways with the wind, but never breaks. It's the ability to face challenges and bounce back stronger than before. Just like a tree needs nourishment and care to grow strong, resilience can be nurtured by practicing self-care, developing a positive mindset, and learning from setbacks. Remember, the strongest trees grow in the toughest conditions.

(未完待续)

发表回复