穿戴式跳d放在里面逛超市的_av无码网站在线_国产午夜亚洲欧美家园美丽_久久无码一二三四_精品久久香蕉国产线看观看亚洲

Top
首頁(yè)>即刻 > 正文

最大限度發(fā)揮LLM的潛力之提示符工程化策略指南 最資訊

發(fā)布時(shí)間:2023-05-18 16:57:33        來(lái)源:清一色財(cái)經(jīng)

仔細(xì)設(shè)計(jì)GPT-4等LLM(大型語(yǔ)言模型)中使用的提示符信息有助于極大地改善模型的輸出結(jié)果,本文將通過(guò)展示多種場(chǎng)景下的應(yīng)用實(shí)例來(lái)論證此結(jié)論。

譯者 | 朱先忠


(資料圖片)

審校 | 重樓

引言

近年來(lái),自然語(yǔ)言模型得到了快速改進(jìn);其中,GPT-3和GPT-4等大型語(yǔ)言模型占據(jù)了中心地位。這些模型之所以受歡迎,是因?yàn)樗鼈兡軌蛞粤钊穗y以置信的技能執(zhí)行各種各樣的任務(wù)。此外,隨著這些模型的參數(shù)數(shù)量(數(shù)十億?。┑牟粩嘣黾樱@些模型意外地獲得了新的功能。

在本文中,我們將探討LLM(大型語(yǔ)言模型)、它們可以執(zhí)行的任務(wù)、它們存在的問(wèn)題以及各種應(yīng)用場(chǎng)景下的提示符工程化應(yīng)對(duì)策略。

什么是LLM?

LLM是在大量文本數(shù)據(jù)上進(jìn)行訓(xùn)練的神經(jīng)網(wǎng)絡(luò)。訓(xùn)練過(guò)程允許模型學(xué)習(xí)文本中的模式,包括語(yǔ)法、句法和單詞聯(lián)想。這些模型能夠使用這些學(xué)習(xí)到的模式來(lái)生成類似人類的文本,使其成為自然語(yǔ)言處理(NLP)任務(wù)的理想選擇。

目前存在哪些可用的LLM?

當(dāng)前,已經(jīng)有幾種LLM正式投入商業(yè)應(yīng)用,其中GPT-4最受歡迎。其他模型包括LLaMA、PaLM、BERT和T5等。當(dāng)然,每一種模型都有其各自的優(yōu)點(diǎn)和缺點(diǎn)。其中有一些是開源的,另一些則是閉源的,只能通過(guò)API調(diào)用方式來(lái)使用。

LLM的不足

盡管LLM的性能令人印象深刻,但仍有一些局限性。一個(gè)顯著的缺點(diǎn)是它們無(wú)法超越提示符中提供的信息進(jìn)行推理。此外,LLM可能根據(jù)訓(xùn)練的數(shù)據(jù)生成帶有“偏見”的文本描述內(nèi)容??傊?,想準(zhǔn)確控制LLM的輸出結(jié)果也是一項(xiàng)很富有挑戰(zhàn)性的任務(wù)。因此,人們有必要采用提示符工程化策略來(lái)控制所需要的輸出內(nèi)容。

您可以執(zhí)行哪些任務(wù)?

我們可以通過(guò)格式化每一種應(yīng)用場(chǎng)景相應(yīng)的提示符內(nèi)容來(lái)指導(dǎo)LLM為我們執(zhí)行特定的任務(wù)。接下來(lái),我們將列舉一些典型應(yīng)用場(chǎng)景中的任務(wù)、提示符模板以及每個(gè)任務(wù)相應(yīng)的輸出結(jié)果。

文本摘要應(yīng)用場(chǎng)景

LLM可以幫助我們生成長(zhǎng)文本的摘要,使內(nèi)容更容易理解和消化。例如,我們可以要求使用以下提示符模板對(duì)文本進(jìn)行總結(jié):

模板

Summarize the text above: / Explain the text above in  sentences:

例如,我們可以要求用以下提示信息來(lái)總結(jié)上述文本:

提示符

In a mechanical watch the watch"s gears are turned by a spiral spring called a mainspring. In a manual watch energy is stored in the mainspring by turning a knob, the crown on the side of the watch. Then the energy from the mainspring powers the watch movement until it runs down, requiring the spring to be wound again.A self-winding watch movement has a mechanism which winds the mainspring using the natural motions of the wearer"s body. The watch contains an oscillating weight that turns on a pivot. The normal movements of the watch in the user"s pocket (for a pocketwatch) or on the user"s arm (for a wristwatch) cause the rotor to pivot on its staff, which is attached to a ratcheted winding mechanism. The motion of the watch is thereby translated into circular motion of the weight which, through a series of reverser and reducing gears, eventually winds the mainspring. There are many different designs for modern self-winding mechanisms. Some designs allow winding of the watch to take place while the weight swings in only one direction while other, more advanced, mechanisms have two ratchets and wind the mainspring during both clockwise and anti-clockwise weight motions.Explain the text above in 2 sentences:

最終,LLM將給出以下輸出結(jié)果:

輸出

A mechanical watch uses a mainspring to power the movement of the watch"s gears. In a manual watch, the mainspring is wound by turning a knob, while a self-winding watch uses the natural motion of the wearer"s body to wind the mainspring through an oscillating weight and ratcheted winding mechanism.

信息提取領(lǐng)域應(yīng)用

LLM可以從大量文本中識(shí)別和提取特定信息。這在新聞和商業(yè)智能等領(lǐng)域很有用。以下模板指示LLM模型提取信息:

模板

Mention X in the text above: / List X in the text above:

例如,我們可以要求從以下文本中提取地名:

提示符

The earliest credible evidence for a successful design is the watch made by the Swiss watchmaker Abraham-Louis Perrelet, who lived in Le Locle. In late 1776 or early 1777, he invented a self-winding mechanism for pocket watches using an oscillating weight inside the watch that moved up and down. The Geneva Society of Arts, reporting on this watch in 1777, stated that 15 minutes walking was necessary to fully wind the watch.List the names of places in the text above:

它給出以下輸出結(jié)果:

輸出

Le Locle, Geneva.

問(wèn)答場(chǎng)景應(yīng)用

LLM還可以根據(jù)提示符中提供的信息進(jìn)行問(wèn)題回答。以下模板可用于指導(dǎo)LLM回答問(wèn)題:

模板

Answer the question based on the context below. . Respond "Not sure" if not sure about the answer.Context: Q: A:

例如,使用以下提示:

提示符

Answer the question based on the context below. Answer in a single sentence. Respond "Not sure" if not sure about the answer.Context: An automatic watch, also known as a self-winding watch or simply an automatic, is a mechanical watch where the natural motion of the wearer provides energy to wind the mainspring, making manual winding unnecessary if worn enough. It is distinguished from a manual watch in that a manual watch must have its mainspring wound by hand at regular intervals.Q: Do automatic watches need to be manually wound?A:

而ChatGPT的回應(yīng)是:

輸出

No, automatic watches do not need to be manually wound if worn enough because the natural motion of the wearer provides energy to wind the mainspring.

文本分類領(lǐng)域

LLM可以將文本分類為預(yù)定義的類別,例如情緒分析或垃圾郵件檢測(cè)。您可以按以下方式格式化文本分類說(shuō)明:

模板

Classify the text into :Text: Classification:

例如,我們可以嘗試根據(jù)文本的情緒是積極的、中立的還是消極的來(lái)對(duì)其進(jìn)行分類:

提示符

Classify the text into positive, neutral or negative:Text: That shot selection was awfulClassification:

輸出

Negative

會(huì)話應(yīng)用場(chǎng)景

LLM可以生成類似人類的對(duì)話,使其在聊天機(jī)器人和客戶服務(wù)應(yīng)用程序中非常有用。我們可以指示LLM以特定的方式跟隨對(duì)話。

模板

The following is a conversation with . The  should answer .Person: : Person: :

LLM能夠填寫我們指示它的參與者類型的響應(yīng),我們可以通過(guò)再次傳遞整個(gè)對(duì)話和新的響應(yīng)來(lái)繼續(xù)對(duì)話。例如:

提示符1

The following is a conversation with a lawyer. The lawyer should answer simply and in layman terms.Person: Hello, I would like to know how to dispute a parking ticketLawyer:

輸出1

Sure, I can help. The first step is to check the ticket for any errors or mistakes. If you find any, you can use those as grounds to dispute the ticket. If there are no mistakes, you can still dispute the ticket by providing evidence to support your case, such as photos or witness statements. You can also request a hearing to present your case in person.

提示符2

The following is a conversation with a lawyer. The lawyer should answer simply and in layman terms.Person: Hello, I would like to know how to dispute a parking ticketLawyer: Sure, I can help. The first step is to check the ticket for any errors or mistakes. If you find any, you can use those as grounds to dispute the ticket. If there are no mistakes, you can still dispute the ticket by providing evidence to support your case, such as photos or witness statements. You can also request a hearing to present your case in person.Person: How do I request a hearing?Lawyer:

輸出2

To request a hearing, you"ll need to follow the instructions on the back of the ticket or on the website provided. Usually, you"ll need to submit a written request within a certain timeframe, along with any evidence or supporting documents you have. Once your request is received, you"ll be notified of the date, time, and location of your hearing.

代碼生成應(yīng)用場(chǎng)景

LLM可以生成計(jì)算機(jī)程序代碼,使開發(fā)人員更容易創(chuàng)建復(fù)雜的軟件程序。我們可以寫一個(gè)代碼注釋來(lái)描述我們希望代碼做什么,LLM將能夠盡最大努力為我們做這件事。我們希望代碼做的事情越復(fù)雜,我們就需要在提示注釋中表現(xiàn)得越具體和具備描述性。

模板可能會(huì)因我們想要生成的編程語(yǔ)言而異,但我建議大致遵循如下所示的模板:

模板

Method: Language: Description: Parameters: Context: Output: 

例如,如果我們想獲取一個(gè)帶有分頁(yè)的API,我們可以編寫以下注釋:

提示符

/* Method: fetchFirst5Pages * Language: Javascript * Description: Fetch the first 5 pages from this paginated API: http://example.com/pages/?n=x * Context: This API accepts the following URL parameters: * n: the number of the page to fetch * Output: the content of the first 5 pages */

輸出

Here"s an example implementation of the fetchFirst5Pages method in JavaScript, assuming the use of the fetch function:async function fetchFirst5Pages() { const baseUrl = "http://example.com/pages/?n="; const pages = []; for (let i = 1; i <= 5; i++) { const url = baseUrl + i; const response = await fetch(url); if (!response.ok) { throw new Error(`Error fetching page ${i}`); } const pageData = await response.json(); pages.push(pageData); } return pages;}This function uses a loop to fetch the first 5 pages from the API by appending the page number to the base URL. It checks if the response from the server is okay and throws an error if it"s not. Then, it parses the JSON data from the response and adds it to an array of pages. Finally, it returns the array of pages.

推理領(lǐng)域應(yīng)用

LLM可能會(huì)在一些基本任務(wù)上遇到困難,例如算術(shù)問(wèn)題。然而,如果我們要求LLM對(duì)其回應(yīng)進(jìn)行推理,我們可以幫助它找到正確的答案。下面是我推薦的模板:

模板

Q: A: Let"s work this out in a step by step way to be sure we have the right answer. First, .

在這個(gè)例子中,我們可以看到,如果我們不合理地提出一個(gè)簡(jiǎn)單的算術(shù)問(wèn)題,它就會(huì)失?。?/p>

提示符1

Answer the following question. Respond "Not sure" if not sure about the answer.Q: The sum of prime numbers in the following list are a multiple of 3: [2, 4, 6, 7, 9, 14]A: [Yes or No]

輸出1

No. The sum of prime numbers in the list [2, 4, 6, 7, 9, 14] is not a multiple of 3. Therefore, the answer is "No".

然而,如果我們指示LLM對(duì)其答案進(jìn)行推理,我們會(huì)得到一個(gè)非常不同的結(jié)果:

提示符2

Q: The sum of prime numbers in the following list are a multiple of 3: [2, 4, 6, 7, 9, 14]A: Let"s work this out in a step by step way to be sure we have the right answer. First, we find the prime numbers in the list and add them together. Then we check whether the resulting number can be divided by 3.

輸出2

Sure, let"s work this out step by step.The prime numbers in the list are 2 and 7. So we can add them together:2 + 7 = 9The resulting number is 9. Now we need to check whether it is a multiple of 3. We can do this by checking if the remainder of 9 divided by 3 is equal to 0:9 % 3 = 0Since the remainder is 0, we know that 9 is indeed a multiple of 3.Therefore, the answer is "Yes", the sum of prime numbers in the list [2, 4, 6, 7, 9, 14] is a multiple of 3.

策略生成領(lǐng)域

雖然這些模板可以幫助您根據(jù)自己的需求挖掘LLM的潛力,但有時(shí)它們?nèi)匀粫?huì)在某些復(fù)雜的任務(wù)中遇到困難。當(dāng)然,科學(xué)家們已經(jīng)開發(fā)了一些技術(shù)來(lái)幫助LLM獲得令人滿意的答案。到目前為止,我們只使用了零樣本提示,現(xiàn)在我們將對(duì)其進(jìn)行定義;不過(guò),我們可以使用更復(fù)雜的技術(shù)。

零樣本提示(Zero-Shot Prompting)

本文中的所有示例都使用了零樣本提示。零樣本提示意味著,向LLM傳遞一個(gè)提示,只包含我們希望它回答的問(wèn)題,而不包含任何其他情況下它應(yīng)該如何響應(yīng)的示例。例如,在前面的一個(gè)例子中,我們做到了:

提示符

Classify the text into positive, neutral or negative:Text: That shot selection was awfulClassification:

輸出

Negative

這可能不足以讓模型準(zhǔn)確地回答我們希望它如何回答。讓我們看看我們有什么替代方案。

少快照提示(Few-Shot Prompting)

與零樣本提示不同,在少快照提示的情況下,我們給LLM幾個(gè)示例,說(shuō)明它應(yīng)該如何響應(yīng),然后再提問(wèn)。例如,假設(shè)我們想實(shí)現(xiàn)像前面的例子一樣對(duì)文本的情感進(jìn)行分類。但我們希望它每次都能以一種非常具體的形式給我們答案。我們可以提前舉幾個(gè)例子:

提示符

Classify the text into positive, neutral or negative:Text: Today the weather is fantasticClassification: PosText: The furniture is small.Classification: NeuText: I don"t like your attitudeClassification: NegText: That shot selection was awfulClassification:

輸出

Neg

思維鏈提示(Chain of Thought Prompting)

對(duì)于更復(fù)雜的任務(wù),我們可以將少量的快照提示與讓模型對(duì)其答案進(jìn)行推理相結(jié)合。我們可以使用與之前相同的例子來(lái)了解推理和少量快照提示是如何影響結(jié)果的:

提示符

Q: The sum of prime numbers in the following list are a multiple of 3: [2, 4, 6, 7, 9, 14]A: The prime numbers in the list are 2 and 7. Their sum is 9. 9 % 3 = 0. The answer is yes.Q: The sum of prime numbers in the following list are a multiple of 3: [1, 2, 4, 7, 8, 10]A: The prime numbers in the list are 1, 2 and 7. Their sum is 10. 10 % 3 = 1. The answer is no.Q: The sum of prime numbers in the following list are a multiple of 3: [1, 2, 3, 4]A: The prime numbers in the list are 1, 2 and 3. Their sum is 6. 6 % 3 = 0. The answer is yes.Q: The sum of prime numbers in the following list are a multiple of 3: [5, 6, 7, 8]A:

輸出

The prime numbers in the list are 5 and 7. Their sum is 12. 12 % 3 = 0. The answer is yes.

總結(jié)

總之,當(dāng)前的大型語(yǔ)言模型已經(jīng)徹底改變了自然語(yǔ)言處理領(lǐng)域;然而,另一方面,要最大限度地發(fā)揮其潛力,提示符的工程化策略選擇至關(guān)重要。通過(guò)了解LLM可以執(zhí)行的任務(wù)、它們的缺點(diǎn)以及各種提示符的工程策略,開發(fā)人員可以利用LLM的力量來(lái)創(chuàng)建創(chuàng)新和有效的解決方案。

在不久的將來(lái),可能會(huì)開發(fā)出更多的策略和技術(shù),因此請(qǐng)關(guān)注該領(lǐng)域的進(jìn)一步發(fā)展,以最大限度地發(fā)揮LLM的潛力。此外,隨著LLM數(shù)十億個(gè)額外參數(shù)的不斷擴(kuò)大,很可能會(huì)有更多我們現(xiàn)在甚至無(wú)法想到的任務(wù)。想到使用這些新工具會(huì)有什么可能,以及它們?cè)谖磥?lái)會(huì)為我們提供哪些用例,不能不令人驚訝。

關(guān)鍵詞:

相關(guān)新聞