Prompt learning 教學[技巧篇]:透過增加示例、引導詞、特殊符號指令等方式讓chatgpt輸出更好的答案

汀丶發表於2023-05-13

Prompt learning 教學[技巧篇]:透過增加示例、引導詞、特殊符號指令等方式讓chatgpt輸出更好的答案

技巧1:To Do and Not To Do

在問答場景裡,為了讓 AI 回答更加準確,一般會在問題里加條件。比如讓 AI 推薦一部電影給你 Recommend a movie to me 。但這個 prompt 太空泛了,AI 無法直接回答,接著它會問你想要什麼型別的電影,但這樣你就需要跟 AI 聊很多輪,效率比較低。

所以,為了提高效率,一般會在 prompt 裡看到類似這樣的話(意思是不要詢問我對什麼感興趣,或者問我的個人資訊):

DO NOT ASK FOR INTERESTS. DO NOT ASK FOR PERSONAL INFORMATION.

如果你在 ChatGPT 裡這樣提問,或者使用 ChatGPT 最新的 API ,它就不會問你問題,而是直接推薦一部電影給你,它的 Output 是這樣的:

Certainly! If you're in the mood for an action-packed movie, you might enjoy "John Wick" (2014), directed by Chad Stahelski and starring Keanu Reeves. The movie follows a retired hitman named John Wick who seeks vengeance against the people who wronged him. It's a fast-paced and stylish film with lots of thrilling action sequences and an engaging story. If you're looking for something that will keep you on the edge of your seat, "John Wick" is definitely worth a watch!

但如果你使用的是如 Davinci-003 這樣的模型,它的 Output 很可能是這樣的,它還會問你的興趣愛好:

Sure, I can recommend a movie based on your interests. What kind of movie would you like to watch? Do you prefer action, comedy, romance, or something else?

所以 OpenAI 的 API 最佳實踐文件裡,提到了一個這樣的最佳實踐:

Instead of just saying what not to do, say what to do instead. 與其告知模型不能幹什麼,不妨告訴模型能幹什麼。

我自己的實踐是,雖然現在最新的模型已經理解什麼是 Not Todo ,但如果你想要的是明確的答案,加入更多限定詞,告知模型能幹什麼,回答的效率會更高,且預期會更明確。還是電影推薦這個案例,你可以加入一個限定詞:

Recommend a movie from the top global trending movies to me.

當然並不是 Not Todo 就不能用,如果:

  • 你已經告知模型很明確的點,然後你想縮小範圍,那增加一些 Not Todo 會提高不少效率。
  • 你是在做一些探索,比如你不知道如何做精準限定,你只知道不要什麼。那可以先加入 Not Todo ,讓 AI 先發散給你答案,當探索完成後,再去最佳化 prompt。

以下是一些場景案例,我整理了兩個 Less Effective(不太有效的) 和 Better(更好的) prompt,你可以自己嘗試下這些案例:

場景 Less Effective Better 原因
推薦雅思必背英文單詞 Please suggest me some essential words for IELTS Please suggest me 10 essential words for IELTS 後者 prompt 會更加明確,前者會給大概 20 個單詞。這個仍然有提升的空間,比如增加更多的限定詞語,像字母 A 開頭的詞語。
推薦香港值得遊玩的地方 Please recommend me some places to visit in Hong Kong. Do not recommend museums. Please recommend me some places to visit in Hong Kong including amusement parks. 後者的推薦會更準確高效一些,但如果你想進行一些探索,那前者也能用。

技巧2:增加示例

直接告知 AI 什麼能做,什麼不能做外。在某些場景下,我們能比較簡單地向 AI 描述出什麼能做,什麼不能做。但有些場景,有些需求很難透過文字指令傳遞給 AI,即使描述出來了,AI 也不能很好地理解。

比如給寵物起英文名,裡面會夾雜著一些所謂的名字風格。此時你就可以在 prompt裡增加一些例子,我們看看這個例子:

Suggest three names for a horse that is a superhero.

Output 是這樣的,第一個感覺還行,第二個 Captain 有 hero 的感覺,但 Canter 就像是說這匹馬跑得很慢,而且三個都比較一般,不夠酷。

Thunder Hooves, Captain Canter, Mighty Gallop

此時你就可以在 prompt 裡增加一些案例:

Suggest three names for an animal that is a superhero.

Animal: Cat
Names: Captain Sharpclaw, Agent Fluffball, The Incredible Feline
Animal: Dog
Names: Ruff the Protector, Wonder Canine, Sir Barks-a-Lot
Animal: Horse
Names:

增加例子後,輸出的結果就更酷一些,或者說是我想要的那種風格的名字。

Gallop Guardian, Equine Avenger, The Mighty Stallion

以下是一些場景案例,我整理了兩個 Less Effective(不太有效的) 和 Better(更好的) prompt,你可以自己嘗試下這些案例:

場景 Less Effective Better 原因
起英文名 Suggest three English names for a boy. Suggest three English names for a boy.
Here are some examples: Jimmy、Jason、James
可以在下方執行這個案例,在不給示例的情況下 AI 會給你什麼答案。
將電影名稱轉為 emoji Convert Star Wars into emoji. Convert movie titles into emoji.
Back to the Future: ????
Batman: ??
Transformers: ??
Star Wars:
可以在下方執行這個案例,在不給示例的情況下 AI 會給你什麼答案。

技巧3:使用引導詞,引導模型輸出特定內容

在程式碼生成場景裡,有一個小技巧,上面提到的案例,其 prompt 還可以繼續最佳化,在 prompt 最後,增加一個程式碼的引導,告知 AI 我已經將條件描述完了,你可以寫程式碼了。

Better:

Create a MySQL query for all students in the Computer Science Department:
Table departments, columns = [DepartmentId, DepartmentName]
Table students, columns = [DepartmentId, StudentId, StudentName]
SELECT

在 prompt 的最後增加 SELECT 可以很好地提示 AI 可以寫 SQL 程式碼了。

同樣的道理,如果你想讓 AI 寫 Python 程式碼,那 import 會是比較好的提示。但需要注意,這個只是告知 AI 可以寫程式碼了,並不能告知 AI 寫何種程式碼,你仍然需要在 prompt 裡增加提示,告知 AI 要生成何種語言的程式碼。

在吳恩達的 ChatGPT Prompt Engineering 課程中,也提到這個技巧,只是在課程中,引導詞並不是放在最後,而是在 prompt 裡直接說明,讓 AI 生成一個 JSON 格式的內容。課程中的例子是這樣的(注意這個是 python 程式碼):

prompt = f"""
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.
"""

我簡單解釋下,其關鍵是在 prompt 裡跟 AI 說明,需要 AI 按照 JSON 格式輸出內容。

技巧4:增加 Role(角色)或人物

前面提到的改寫例子,我在 prompt 里加了 Role 讓其更易於閱讀,這個最佳化方法是 OK 的。也很常用,比如你想將你寫的 Email 改得更商務,則只需要加 business 相關的詞即可。

我再介紹一個更有效的技巧,就是在 prompt 裡增加一些 role(角色)相關的內容,讓 AI 生成的內容更符合你的需求。

比如還是上面那個 rewrite 的例子,我在例子前加入這樣的一段話,我讓 AI 假設自己是一個小學老師,並且很擅長將複雜的內容轉變成 7、8歲小朋友也能聽懂的話,然後再改寫這段話:

You are a primary school teacher who can explain complex content to a level that a 7 or 8 year old child can understand. Please rewrite the following sentences to make them easier to understand:

Output 就變成了下面這樣。不管是用詞,還是語法,看起來都更容易懂了。

OpenAI is a place where people work on making computers really smart. It's like a lab where they do research to make computers do amazing things! They want the computers to be really friendly and helpful to people. They use one of the most powerful computers in the world to do this research. A bunch of really rich and smart people gave money to start this lab. One of them is Elon Musk, but he left in 2018. Another really big company, Microsoft, gave them a lot of money too.

另外除了增加角色外,還能讓 AI 模擬某個人,比如讓 AI 以 David Foster Wallace 的風格改寫上述那段話:

Imagine you are the famous writer David Foster Wallace, please rewrite this sentences.

Output 是這樣的:

As David Foster Wallace, I might rewrite these sentences to sound more like this:

OpenAI is a lab that studies something called artificial intelligence, which is like when computers can do things that normally only humans can do. They have a big computer that's one of the most powerful in the world, and they're trying to make sure the AI they create is friendly and helpful. The lab was started in 2015 in a city called San Francisco, and a bunch of important people gave them a lot of money to do their research. One of those people was Elon Musk, who stopped working there but still gives them money, and Microsoft also gave them a lot of money recently.

關於這個技巧的應用,以及如何更好地使用 AI 提升寫作能力,建議各位閱讀 Nat Eliason 的 Using ChatGPT as a Writing Coach,他使用 ChatGPT 輔助其寫作,就用到了上述的技巧。

技巧5:使用特殊符號指令和需要處理的文字分開

不管是資訊總結,還是資訊提取,你一定會輸入大段文字,甚至多段文字,此時有個小技巧。

可以用“”“將指令和文字分開。根據我的測試,如果你的文字有多段,增加”“”會提升 AI 反饋的準確性(這個技巧來自於 OpenAI 的 API 最佳實踐文件

:::info
感謝 CraneHuang6 的提醒,這裡還能用 ### 符號區隔,不過我一般會用“”“ ,因為我有的時候會用 # 作為格式示例,太多 # 的話 prompt 會看起來比較暈
:::

像我們之前寫的 prompt 就屬於 Less effective prompt。為什麼呢?據我的測試,主要還是 AI 不知道什麼是指令,什麼是待處理的內容,用符號分隔開來會更利於 AI 區分。

Please summarize the following sentences to make them easier to understand.
OpenAI is an American artificial intelligence (AI) research laboratory consisting of the non-profit OpenAI Incorporated (OpenAI Inc.) and its for-profit subsidiary corporation OpenAI Limited Partnership (OpenAI LP). OpenAI conducts AI research with the declared intention of promoting and developing a friendly AI. OpenAI systems run on the fifth most powerful supercomputer in the world.[5][6][7] The organization was founded in San Francisco in 2015 by Sam Altman, Reid Hoffman, Jessica Livingston, Elon Musk, Ilya Sutskever, Peter Thiel and others,[8][1][9] who collectively pledged US$1 billion. Musk resigned from the board in 2018 but remained a donor. Microsoft provided OpenAI LP with a $1 billion investment in 2019 and a second multi-year investment in January 2023, reported to be $10 billion.[10]

Better prompt:

Please summarize the following sentences to make them easier to understand.

Text: """
OpenAI is an American artificial intelligence (AI) research laboratory consisting of the non-profit OpenAI Incorporated (OpenAI Inc.) and its for-profit subsidiary corporation OpenAI Limited Partnership (OpenAI LP). OpenAI conducts AI research with the declared intention of promoting and developing a friendly AI. OpenAI systems run on the fifth most powerful supercomputer in the world.[5][6][7] The organization was founded in San Francisco in 2015 by Sam Altman, Reid Hoffman, Jessica Livingston, Elon Musk, Ilya Sutskever, Peter Thiel and others,[8][1][9] who collectively pledged US$1 billion. Musk resigned from the board in 2018 but remained a donor. Microsoft provided OpenAI LP with a $1 billion investment in 2019 and a second multi-year investment in January 2023, reported to be $10 billion.[10]
"""

另外,在吳恩達的 ChatGPT Prompt Engineering 課程中,還提到,你可以使用其他特殊符號來分割文字和 prompt,比如<><tag></tag> 等,課程中的案例是這樣的(注意這個是 python 程式碼,需要關注的是 prompt 裡的 text):

text = f"""
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.
"""

prompt = f"""
Summarize the text delimited by triple backticks \
into a single sentence.
`{text}`
"""

如果你是在開發一款允許使用者輸入內容,並對內容進行總結的 AI 產品,那你就可以使用到這個技巧。

技巧6:透過格式詞闡述需要輸出的格式

這個技巧是技巧 2 的變種,比較常用於生成文字場景。其實在場景 7 中,你也可以用到這個技巧。

假設你想讓 AI 總結一篇非常非常長的文章,並且按照特定格式給你總結,那你可以在文章前面明確輸出的格式(為了不佔用太多顯示空間,我省略了正文內容,你可以在 OpenAI 的 Playground 看到完整案例)。它的意思其實是讓 ChatGPT 按 Topic 總結,每個 Topic 裡按照無序列表(就是裡面那個 -)將每個 Topic 的主要觀點羅列出來。

Summarize the main points of the following speech
Use the following format:
Topic 1: <topic_name_1>
- <point_1>
..
Topic 2: <topic_name_2>
- <point_1>
..
Topic 10: ..

Text: """
Thank you so much, Fred, for that lovely introduction. And thanks to the Atlantic Council for hosting me today.

The course of the global economy over the past two years has been shaped by COVID-19 and our efforts to fight the pandemic. It’s now evident, though, that the war between Russia and Ukraine has redrawn the contours of the world economic outlook. Vladimir Putin’s unprovoked attack on Ukraine and its people is taking a devastating human toll, with lives tragically lost, families internally displaced or becoming refugees, and communities and cities destroyed.
...

"""

Output 是這樣的:

Topic 1: The war in Ukraine
- The war is taking a human toll with lives lost, families displaced, and communities destroyed
- The Biden administration is committed to holding Russia accountable
- The war has violated international law and is a challenge to the international order

Topic 2: The global economy
- The war is having negative impacts on the global economy, including higher commodity prices and inflation
- The IMF and World Bank will be focused on helping developing countries weather the impacts of the war
- The ultimate outcome for the global economy depends on the path of the war

關於這個場景和技巧,我想再解釋一下為什麼潛力很大。

根據我使用各種 Summary 或者資訊提取的產品,我發現 AI 並不知道什麼是重點,所以在總結的過程中,會丟失很多內容。如何引導 AI 進行總結,就變得非常重要,且具有一定的可玩性。


使用此技巧可以使輸出更結構化。比如針對一篇文章進行問答,你不僅想要得到一個答案,也希望 ChatGPT 的答案符合特定的格式,方便你下一步進行自動化。

比如問 "這裡的債券 duration 是多少?". 正常 GPT 模型的答案可能是 "債券 duration 是 4 年" 或 "duration 4 年"。
ChatGPT 的回答不穩定,且不方便繼續處理。

解法:
我們可以透過這個技巧,讓模型理解我們預期的格式。並在此基礎上,為了方便自動化,讓模型輸出特定的結構化答案 (比如 JSON/Markdown 等)。
也可以方便整合更多的額外要求,比如增加一個"confidence level", 並透過 prompt 的形式指定這些數值的格式。

比如:

{context}
Question: What is bond duration mentioned here.
Answer template (Valid JSON format):
{{
"duration": $duration_numeric_value_in_year,
"confidence_level": $answer_confidence_level_high_modrate_or_low,
}}
Answer:

在吳恩達的 ChatGPT Prompt Engineering 課程中,有提到一個這個技巧的高階用法,在讓 AI 按照特定格式輸出內容的同時,還讓 AI 根據內容是否滿足特定條件,來判斷應該輸出什麼結果,下面課程中的案例的 prompt(注意這個是 python 程式碼,有一些跳脫字元,可以不用管):

You will be provided with text delimited by triple quotes.
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.\"

\"\"\"{text}\"\"\"

簡單解釋下,這個 prompt 分成兩步:

讓 AI 將輸入的 text 轉為步驟(就是 prompt 裡的 Step 1、2)

然後還增加了一個判斷,如果輸入的 text 裡沒有 step 的內容,那麼就輸出 No Step

假如輸入的 text 是一個泡茶的步驟介紹:

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.

那麼 AI 輸出的內容是這樣的(因為內容中包含了步驟式的內容):

Step 1 - Get some water boiling.
Step 2 - 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 it sit for a bit so the tea can steep.
Step 5 - After a few minutes, take out the tea bag.
Step 6 - Add some sugar or milk to taste.
Step 7 - Enjoy your delicious cup of tea!

但如果我們輸入的是這樣的 text:

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.

從內容上看,這段話,沒有任何步驟式的內容,所以 AI 的輸出是這樣的:

No steps provided.

技巧7:Zero-Shot Chain of Thought

基於上述的第三點缺點,研究人員就找到了一個叫 Chain of Thought 的技巧。

這個技巧使用起來非常簡單,只需要在問題的結尾裡放一句 Let‘s think step by step (讓我們一步步地思考),模型輸出的答案會更加準確。

這個技巧來自於 Kojima 等人 2022 年的論文 Large Language Models are Zero-Shot Reasoners。在論文裡提到,當我們向模型提一個邏輯推理問題時,模型返回了一個錯誤的答案,但如果我們在問題最後加入 Let‘s think step by step 這句話之後,模型就生成了正確的答案:

論文裡有講到原因,感興趣的朋友可以去看看,我簡單解釋下為什麼(? 如果你有更好的解釋,不妨反饋給我):

  1. 首先各位要清楚像 ChatGPT 這類產品,它是一個統計語言模型,本質上是基於過去看到過的所有資料,用統計學意義上的預測結果進行下一步的輸出(這也就是為什麼你在使用 ChatGPT 的時候,它的答案是一個字一個字地吐出來,而不是直接給你的原因,因為答案是一個字一個字算出來的)。
  2. 當它拿到的資料裡有邏輯,它就會透過統計學的方法將這些邏輯找出來,並將這些邏輯呈現給你,讓你感覺到它的回答很有邏輯。
  3. 在計算的過程中,模型會進行很多假設運算(不過暫時不知道它是怎麼算的)。比如解決某個問題是從 A 到 B 再到 C,中間有很多假設。
  4. 它第一次算出來的答案錯誤的原因,只是因為它在中間跳過了一些步驟(B)。而讓模型一步步地思考,則有助於其按照完整的邏輯鏈(A > B > C)去運算,而不會跳過某些假設,最後算出正確的答案。

按照論文裡的解釋,零樣本思維鏈涉及兩個補全結果,左側氣泡表示基於提示輸出的第一次的結果,右側氣泡表示其收到了第一次結果後,將最開始的提示一起拿去運算,最後得出了正確的答案:

這個技巧,用於解複雜問題有用外,還適合生成一些連貫主題的內容,比如寫長篇文章、電影劇本等。

但需要注意其缺點,連貫不代表它就一定不會算錯,如果其中某一步驟算錯了,錯誤會因為邏輯鏈,逐步將錯誤積累,導致生成的文字可能出現與預期不符的內容。

另外,根據 Wei 等人在 2022 年的論文表明,還有它僅在大於等於 100B 引數的模型中使用才會有效。如果你使用的是小樣本模型,這個方法不會生效。


根據 Yongchao Zhou 等人的最新論文,更好的 prompt 是:

Let's work this out in a step by step way to be sure we have the right answer.

在吳恩達的 ChatGPT Prompt Engineering 課程中,有提到一個這個技巧的另一種用法,不僅僅只是讓 AI 按步驟行事,還會告知 AI 每一步要做什麼。比如這個案例(注意這個是 python 程式碼):

prompt_2 = f"""
Your task is to perform the following actions:
1 - Summarize the following text delimited by
  <> with 1 sentence.
2 - Translate the summary into French.
3 - List each name in the French summary.
4 - Output a json object that contains the
  following keys: french_summary, num_names.

Use the following format:
Text: <text to summarize>
Summary: <summary>
Translation: <summary translation>
Names: <list of names in Italian summary>
Output JSON: <json with summary and num_names>

Text: <{text}>
"""

簡單解釋下這個程式碼:

  1. 開頭是讓 AI 按照 1 ~ 4 步執行
  2. 然後再讓 AI 根據特定格式輸出內容

最後 AI 的輸出是這樣的:

Summary: Jack and Jill go on a quest to fetch water, but misfortune strikes and they tumble down the hill, returning home slightly battered but with their adventurous spirits undimmed.
Translation: Jack et Jill partent en quête d'eau, mais la malchance frappe et ils dégringolent la colline, rentrant chez eux légèrement meurtris mais avec leurs esprits aventureux intacts.
Names: Jack, Jill
Output JSON: {"french_summary": "Jack et Jill partent en quête d'eau, mais la malchance frappe et ils dégringolent la colline, rentrant chez eux légèrement meurtris mais avec leurs esprits aventureux intacts.", "num_names": 2}

上述的案例只是將任務拆解,能讓 AI 生成的結果更加符合要求,這個方法同樣能提升 AI 的回答準確性,比如這個案例:

Determine if the student's solution is correct or not.

Question:
I'm building a solar power installation and I need help working out the financials.

Land costs $100 / square foot

I can buy solar panels for $250 / square foot

I negotiated a contract for maintenance that will cost \
me a flat $100k per year, and an additional $10 / square foot
What is the total cost for the first year of operations
as a function of the number of square feet.

Student's Solution:
Let x be the size of the installation in square feet.
Costs:

Land cost: 100x

Solar panel cost: 250x

Maintenance cost: 100,000 + 100x
Total cost: 100x + 250x + 100,000 + 100x = 450x + 100,000

AI 的回答是「The student's solution is correct」。但其實學生的答案是錯誤的,應該 360x + 100,000,我們將 prompt 調整成這樣:

prompt = f"""
Your task is to determine if the student's solution \
is correct or not.
To solve the problem do the following:
- First, work out your own solution to the problem.
- Then compare your solution to the student's solution \
and evaluate if the student's solution is correct or not.
Don't decide if the student's solution is correct until
you have done the problem yourself.
Use the following format:
Question:
###
question here
###
Student's solution:
###
student's solution here
###
Actual solution:
###
steps to work out the solution and your solution here
###
Is the student's solution the same as actual solution \
just calculated:
###
yes or no
###
Student grade:
###
correct or incorrect
###
Question:
###
I'm building a solar power installation and I need help \
working out the financials.
- Land costs $100 / square foot
- I can buy solar panels for $250 / square foot
- I negotiated a contract for maintenance that will cost \
  me a flat $100k per year, and an additional $10 / square \
  foot
  What is the total cost for the first year of operations \
  as a function of the number of square feet.
###
Student's solution:
###
Let x be the size of the installation in square feet.
Costs:
1. Land cost: 100x
2. Solar panel cost: 250x
3. Maintenance cost: 100,000 + 100x
   Total cost: 100x + 250x + 100,000 + 100x = 450x + 100,000
###
Actual solution:
"""

本質上,也是將任務分拆成多步,這次 AI 輸出的結果是這樣的(結果就是正確的了):

Let x be the size of the installation in square feet.

Costs:

1. Land cost: 100x
2. Solar panel cost: 250x
3. Maintenance cost: 100,000 + 10x

Total cost: 100x + 250x + 100,000 + 10x = 360x + 100,000

Is the student's solution the same as actual solution just calculated:
No

Student grade:
Incorrect

技巧8:Few-Shot Chain of Thought

要解決這個缺陷,就要使用到新的技巧,Few-Shot Chain of Thought。

根據 Wei 他們團隊在 2022 年的研究表明:

透過向大語言模型展示一些少量的樣例,並在樣例中解釋推理過程,大語言模型在回答提示時也會顯示推理過程。這種推理的解釋往往會引匯出更準確的結果。

下面是論文裡的案例,使用方法很簡單,在技巧 2 的基礎上,再將邏輯過程告知給模型即可。從下面這個案例裡,你可以看到加入解釋後,輸出的結果就正確了。

那本章開頭提的例子就應該是這樣的(注:本例子同樣來自 Wei 團隊論文):

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: 17,  10, 19, 4, 8, 12, 24.
A: Adding all the odd numbers (17, 19) gives 36. The answer is True.

The odd numbers in this group add up to an even number: 16,  11, 14, 4, 8, 13, 24.
A: Adding all the odd numbers (11, 13) gives 24. The answer is True.

The odd numbers in this group add up to an even number: 17,  9, 10, 12, 13, 4, 2.
A: Adding all the odd numbers (17, 9, 13) gives 39. The answer is False.

The odd numbers in this group add up to an even number: 15, 32, 5, 13, 82, 7, 1.
A:

聊完技巧,我們再結合前面的 Zero-Shot Chain of Thought,來聊聊 Chain of Thought 的關鍵知識。根據 Sewon Min 等人在 2022 年的研究 表明,思維鏈有以下特點:

  1. "the label space and the distribution of the input text specified by the demonstrations are both key (regardless of whether the labels are correct for individual inputs)" 標籤空間和輸入文字的分佈都是關鍵因素(無論這些標籤是否正確)。
  2. the format you use also plays a key role in performance, even if you just use random labels, this is much better than no labels at all. 即使只是使用隨機標籤,使用適當的格式也能提高效能。

理解起來有點難,我一個 prompt 案例給大家解釋。我給 ChatGPT 一些不一定準確的例子:

I loved the new Batman movie!  // Negative
This is bad // Positive
This is good // Negative
What a good show! //

Output 是這樣的:

Positive

在上述的案例裡,每一行,我都寫了一句話和一個情感詞,並用 // 分開,但我給這些句子都標記了錯誤的答案,比如第一句其實應該是 Positive 才對。但:

  1. 即使我給內容打的標籤是錯誤的(比如第一句話,其實應該是 Positive),對於模型來說,它仍然會知道需要輸出什麼東西。換句話說,模型知道 // 劃線後要輸出一個衡量該句子表達何種感情的詞(Positive or Negative)。這就是前面論文裡 #1 提到的,即使我給的標籤是錯誤的,或者換句話說,是否基於事實,並不重要。標籤和輸入的文字,以及格式才是關鍵因素。
  2. 只要給了示例,即使隨機的標籤,對於模型生成結果來說,都是有幫助的。這就是前面論文裡 #2 提到的內容。

最後,需要記住,思維鏈僅在使用大於等於 100B 引數的模型時,才會生效。

BTW,如果你想要了解更多相關資訊,可以看看史丹佛大學的講義:Natural Language Processing with Deep Learning

技巧9:其他小trips彙總

一些小的技巧,我會統一放在這裡。

在示例里加入特定符號,讓模型知道如何處理特殊情況

這個解釋起來有點複雜,以下是 OpenAI 的官方 prompt,在一些奇怪的問題上比如 What is Devz9 的回答,你可以用 ? 代替答案,讓模型知道當遇到超出回答範圍時,需要如何處理(注意:此方法在 playground 上有效,但在 ChatGPT 上無效)。

Q: Who is Batman?
A: Batman is a fictional comic book character.

Q: What is torsalplexity?
A: ?

Q: What is Devz9?
A: ?

Q: Who is George Lucas?
A: George Lucas is American film director and producer famous for creating Star Wars.

Q: What is the capital of California?
A: Sacramento.

Q: What is Kozar-09?
A: 

它的 Output 是這樣的:

?

參考連結:https://github.com/thinkingjimmy/Learning-Prompt

相關文章