一、寫在前面
最近,吳恩達(dá)與CloseAI合作出了一個(gè)教程《面向開發(fā)者的ChatGPT提示工程》,第一時(shí)間就觀摩了,有些體會(huì),現(xiàn)在把個(gè)人覺得有意思的搬運(yùn)過來。Open
我的機(jī)器學(xué)習(xí)入門就是看的吳恩達(dá)的教程!大佬長得像馮鞏,哈哈哈。
原版視頻地址:
https://www.deeplearning.ai/short-courses/chatgpt-prompt-engineering-for-developers/
B站已經(jīng)有中文版:
https://space.bilibili.com/15467823/channel/seriesdetail?sid=3247315&ctype=0
下面是第一節(jié)課的筆記。多說一句,我覺得第一節(jié)課的內(nèi)容干貨滿滿(講的是方法論,值得細(xì)細(xì)評味),后面的課都是基于這些原則展開:
二、提示工程的兩個(gè)關(guān)鍵原則
(1)Write clear and specific instructions. 編寫清晰而具體的指令
(a)你應(yīng)該通過提供盡可能清晰和具體的指令來表達(dá)你希望模型做什么,這將引導(dǎo)模型走向預(yù)期的輸出,并減少你得到不相關(guān)或不正確反應(yīng)的機(jī)會(huì)。
(b)不要把寫一個(gè)清晰的提示和寫一個(gè)簡短的指令混淆起來,因?yàn)樵谠S多情況下,較長的指令實(shí)際上為模型提供了更清晰描述和上下文,可以帶來更詳細(xì)和相關(guān)的輸出。
總結(jié)一下:指令越清晰越好,越具體越好,不要吝嗇你的句子。
(c)幫助你寫出清晰而具體的指示的第一個(gè)策略:使用分隔符來明確指出輸入的不同部分。舉個(gè)例子:
咒語:將 {文本} 中的主要內(nèi)容總結(jié)成一句話,50個(gè)字左右。
{所謂的不平衡數(shù)據(jù)集指的是數(shù)據(jù)集各個(gè)類別的樣本量極不均衡。以二分類問題為例,假設(shè)正類的樣本數(shù)量遠(yuǎn)大于負(fù)類的樣本數(shù)量,通常情況下通常情況下把多數(shù)類樣本的比例接近100:1這種情況下的數(shù)據(jù)稱為不平衡數(shù)據(jù)。不平衡數(shù)據(jù)的學(xué)習(xí)即需要在分布不均勻的數(shù)據(jù)集中學(xué)習(xí)到有用的信息。}
?總結(jié)一下:使用定界符(如大括號)可以使模型清晰地了解需要總結(jié)的確切文本,定界符可以是任何明確的標(biāo)點(diǎn)符號,將特定文本片段與提示的其他部分分開。
(d)幫助你寫出清晰而具體的指示的第二個(gè)策略:要求一個(gè)結(jié)構(gòu)化的輸出。比如說,以Markdown、HTML或JSON格式輸出,或者像我之前以表格的形式展示。舉個(gè)例子:
咒語:生成一個(gè)包含三個(gè)編造的書名、作者和流派的列表。分別以表格的形式展示出它們的書籍ID、書名、作者和流派。
(e)幫助你寫出清晰而具體的指示的第三個(gè)策略:要求模型檢查條件是否得到滿足。有點(diǎn)拗口,她是這么解釋的,如果任務(wù)中的假設(shè)不一定被滿足,那么我們可以告訴模型先檢查這些假設(shè)。如果這些假設(shè)不被滿足,指出這一點(diǎn),并在完成任務(wù)的過程中停止。你也可以考慮潛在的邊緣情況,告訴模型應(yīng)該如何處理它們以避免意外的錯(cuò)誤或結(jié)果。舉個(gè)例子:
咒語:如果 {文本} 的主要內(nèi)容包含步驟信息,那么按照下面格式對文本內(nèi)容進(jìn)行總結(jié):
材料:
步驟:
第一步:...
第二步:-
第N步:-
如果 {文本} 的主要內(nèi)容不包含步驟信息,那么久簡單輸出“無法改寫”。
{啤酒鴨是一道非常受歡迎的烤鴨菜肴。制作啤酒鴨需要準(zhǔn)備鴨子、啤酒、食鹽、老抽、白糖、姜、大蔥和香料袋(八角、草果、桂皮、丁香、花椒等)等材料。首先,將鴨子宰殺并清理干凈,去掉內(nèi)臟和頭部,然后將鴨子整洗凈備用。接下來,將香料袋中的香料放入鍋中煸炒出香味,取出備用。然后,煮開一鍋水,加入適量啤酒、食鹽、老抽、白糖、姜、大蔥和香料袋,煮至香味溢出。將煮好的啤酒汁放涼,將鴨子浸泡在啤酒汁中腌制4小時(shí)以上(越久越入味)。為了讓鴨肉入味,可以在啤酒汁中加入適量鹽和醬油,也可以在鴨子表面涂抹適量醬油和料酒。將腌制好的鴨子放在烤箱中,以180度烤40分鐘,取出后涂上蜂蜜,再放回烤箱繼續(xù)烤20分鐘左右,直到鴨皮金黃酥脆。在烤制的過程中,可以根據(jù)自己口味調(diào)整烤制時(shí)間和溫度,以達(dá)到最佳口感。最后,取出烤好的啤酒鴨,切成合適的塊狀即可食用。煮汁時(shí)可加入香料袋,使啤酒汁更香,涂上蜂蜜可增添甜味。享用啤酒鴨時(shí),可以搭配啤酒或其他飲料,更加美味可口。}
?我把文本換一下:
(f)幫助你寫出清晰而具體的指示的第四個(gè)策略:在指令中舉一個(gè)具體的例子,讓模型依葫蘆畫瓢。這個(gè)就不舉例子了,大家都懂怎么操作。
總結(jié):首先我們需要編寫清晰而具體的指令。提供了4個(gè)策略,使用分隔符來明確指出輸入的不同部分;要求一個(gè)結(jié)構(gòu)化的輸出;要求模型檢查條件是否得到滿足;在指令中舉一個(gè)具體的例子,讓模型依葫蘆畫瓢。
(2)Give the model time to think. 給模型思考的時(shí)間
大佬解釋:如果一個(gè)模型因急于得出結(jié)論而出現(xiàn)推理錯(cuò)誤,應(yīng)該嘗試重新設(shè)計(jì)詢問,要求模型有一連串或一系列相關(guān)的推理,然后再由模型提供最終答案。如果你給一個(gè)模型一個(gè)太過復(fù)雜的任務(wù),那么它就無法在短時(shí)間內(nèi)或用很少的詞來完成,最終可能會(huì)編造一個(gè)不正確的答案。
說人話就是,要給模型思考的時(shí)間,好比我們算一道數(shù)學(xué)題都要打草稿呢。
(a)第一個(gè)策略:指定完成一項(xiàng)任務(wù)所需的步驟。直接舉例她的第一個(gè)例子:
咒語:Perform the following actions:
1 - Summarize the following text delimited by triple backticks with 1 sentence.
2 - Translate the summary into Chinses.
3 - List each name in the Chinese summary.
4 - Output a sheet object that contains the following keys: chinese_summary, num_names.
Separate your answers with line breaks.
Text:
‘’’?In a charming village, siblings Jack and Jill set out on a quest to fetch water from a hilltop well. As they climbed, singing joyfully, misfortune struck-Jack tripped on a stone and tumbled down the hill, with Jill following suit. Through slightly battered, the pair returned home to comforting embraces. Despite the mishap, their adventurous spirits remained undimmed, and they continued exploring with delight. ‘’’
?然后,她又換了一個(gè)咒語(主要是輸出格式有變化):
Perform the following actions:
1 - Summarize the following text delimited by <> with 1 sentence.
2 - Translate the summary into Chinese.
3 - List each name in the Chinese summary.
4 - Output a sheet object that contains the following keys: chinese_summary, num_names.
Use the following format:
Text: <text to summarize>
Summary: <summary translation>
Translation: <summary translation>
Name: <list of names in Chinese summary>
Output JOSN: <josn with summary and num_names>
Text:
< In a charming village, siblings Jack and Jill set out on a quest to fetch water from a hilltop well. As they climbed, singing joyfully, misfortune struck-Jack tripped on a stone and tumbled down the hill, with Jill following suit. Through slightly battered, the pair returned home to comforting embraces. Despite the mishap, their adventurous spirits remained undimmed, and they continued exploring with delight. >
?總結(jié)一下:首先讀取文本 ——> 用英文總結(jié)文本內(nèi)容 ——> 翻譯總結(jié)句子 ——> 提取名字 ——> 輸出JOSN格式。把任務(wù)層層分解,一步一步解決,最后匯總。
(b)第二個(gè)策略:指示模型不要急于得出結(jié)論,先嘗試找出解決方案。模型給出結(jié)論以后,告訴TA正確與否。所謂的人在回路?看看她的例子:
咒語: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
?然而,模型給出的結(jié)論是學(xué)生是正確的。確實(shí),學(xué)生的解題思路沒問題,只是粗心看錯(cuò)了一個(gè)數(shù)字。咋一看,確實(shí)以為是正確的。
?所以,需要修改策略:讓模型自己就這個(gè)問題想出方案,然后再和學(xué)生的方案作對比,這樣就能準(zhǔn)確地判斷學(xué)生的方案是否正確。
咒語: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. Dont’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:
- Land cost: 100x
- Solar panel cost: 250x
- Maintenance cost: 100,000 + 100x
Total cost: 100x + 250x + 100,000 + 100x = 450x + 100,000
?有沒有一種感覺,TA的思維模式,有點(diǎn)像人類,甚至犯的錯(cuò)誤都很像。
總結(jié):模型也是急性子,拍腦袋給出的答案正確率不高。解決辦法:給TA思考的時(shí)間,還有引導(dǎo)TA先自己想辦法,比對后再下結(jié)論。總之就是,三思而后行!
三、模型的局限
我們都見識過了,叫一本正經(jīng)地胡說八道:
大佬說:盡管語言模型在訓(xùn)練過程中已經(jīng)接觸了大量的知識,在其訓(xùn)練過程中,它并沒有完美地記住它所看到的信息。因此,它對自己的知識邊界并不十分了解,這意味著它可能會(huì)嘗試回答一些晦澀難懂的問題,并且可以編造一些聽起來很有道理但實(shí)際上并不真實(shí)的事情。我們把這些編造的想法稱為幻覺(Hallucination)。
大佬給的建議:有一個(gè)額外的策略來減少幻覺,如果你想讓模型基于文本生成答案,你需要先要求模型從文本中找到任何相關(guān)的引用,然后要求它使用這些引用來回答問題。
嗯,她沒給案例!?。?/strong>
文章來源:http://www.zghlxwxcb.cn/news/detail-433092.html
四、寫在最后文章來源地址http://www.zghlxwxcb.cn/news/detail-433092.html
- 信息量十足。直接聽官方的課程,少走彎路。
- 后面6節(jié)課,有緣再見。因?yàn)槲铱戳艘槐?,沒啥驚艷的,可能是我水平不夠。待我有所感悟,在加更一期。
到了這里,關(guān)于玩轉(zhuǎn)ChatGPT:吳恩達(dá)/OpenAI合作教程《面向開發(fā)者的ChatGPT提示工程》的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!