提示設計策略

本頁將介紹幾個一般提示設計策略,您可以在這類策略中使用這些工具 設計提示雖然提示設計方式沒有對錯,但還是 可用來影響模型回應的策略持續通過嚴謹的測試與評估 是最佳化模型成效的關鍵

大型語言模型 (LLM) 以大量文字資料訓練而成,能瞭解模型及 語言單位之間的關係只要提供文字 (提示) 給語言模型 例如先進的自動完成工具因此 設計提示,考慮有哪些不同因素會影響模型預測結果 下一步。

提供清楚明確的操作說明

為模型提供相關協助,是有效且有效率地自訂模型的方式。 行為請務必提供清楚明確的操作說明。指示可能包括 提供簡單的逐步說明清單 或可對應使用者體驗的複雜功能 心態。

定義要執行的工作

詳細說明您希望模型執行的工作。這項任務可以很簡單 顯示逐步說明,或對應使用者體驗和思維的複雜性。 下列提示可讓模型總結一段文字:

Summarize this text.
Text: A quantum computer exploits quantum mechanical phenomena to perform calculations exponentially
faster than any modern traditional computer. At very tiny scales, physical matter acts as both
particles and as waves, and quantum computing uses specialized hardware to leverage this behavior.
The operating principles of quantum devices is beyond the scope of classical physics. When deployed
at scale, quantum computers could be used in a wide variety of applications such as: in
cybersecurity to break existing encryption methods while helping researchers create new ones, in
meteorology to develop better weather forecasting etc. However, the current state of the art quantum
computers are still largely experimental and impractical.
  
Quantum computers utilize quantum mechanical phenomena to perform computations significantly faster
than traditional computers. By exploiting the particle-wave duality of matter at tiny scales,
quantum computers leverage specialized hardware to solve problems beyond classical physics.
Potential applications include breaking encryption, developing better weather forecasting, and more.
However, current quantum computers are still largely experimental and impractical.
  

指定任何限制

指定讀取提示或產生回應的限制。您可以告訴模型 該決定該採取哪些行動與上一個例子相比,總結內容比原始範例短 但或許您想縮短摘要篇幅在這種情況下,您可以透過 按照系統提示判斷摘要的持續時間:

Summarize this text in two sentences.
Text: A quantum computer exploits quantum mechanical phenomena to perform calculations exponentially
faster than any modern traditional computer. At very tiny scales, physical matter acts as both
particles and as waves, and quantum computing uses specialized hardware to leverage this behavior.
The operating principles of quantum devices is beyond the scope of classical physics. When deployed
at scale, quantum computers could be used in a wide variety of applications such as: in
cybersecurity to break existing encryption methods while helping researchers create new ones, in
meteorology to develop better weather forecasting etc. However, the current state of the art quantum
computers are still largely experimental and impractical.
    

Quantum computers use quantum mechanical phenomena to perform calculations much faster than
traditional computers. They have the potential to revolutionize various fields, but current quantum
computers are still experimental and impractical.
    

定義回應格式

您也可以提供指示,說明回應的格式。例如,您可以問問 讓回應的格式包括表格、項目符號清單、電梯簡報、關鍵字、句子或句子 例如自動產生影片、音訊 和文章段落的摘要下列提示會指示模型在 例如:

Summarize this text as bullets points of key information.
Text: A quantum computer exploits quantum mechanical phenomena to perform calculations exponentially
faster than any modern traditional computer. At very tiny scales, physical matter acts as both
particles and as waves, and quantum computing uses specialized hardware to leverage this behavior.
The operating principles of quantum devices is beyond the scope of classical physics. When deployed
at scale, quantum computers could be used in a wide variety of applications such as: in
cybersecurity to break existing encryption methods while helping researchers create new ones, in
meteorology to develop better weather forecasting etc. However, the current state of the art quantum
computers are still largely experimental and impractical.
  
- Quantum computers leverage quantum mechanical phenomena for exponentially faster calculations than
  traditional computers.
- Quantum devices utilize specialized hardware to exploit tiny-scale matter behavior as both
  particles and waves.
- Their operating principles transcend classical physics.
- Potential applications include cybersecurity, weather forecasting, and more.
- Current quantum computers are largely experimental and impractical.
  

摘要

  • 請向模型提供操作說明。
  • 指示要清楚明確。
  • 指定輸出的任何限製或格式要求。

加入少量樣本範例

您可以在提示中加入範例,讓模型取得最佳結果。 模型會嘗試從範例中找出模式和關係, 生成回應內含幾個範例的提示稱為「few-shot」提示。 未提供範例的提示則稱為「零樣本提示」。少量樣本提示 常用於調節模型回應的格式、分句、範圍設定或一般模式。 使用各種具體範例,協助模型縮小焦點並產生更準確的結果 也就是預測結果

建議你一律在提示中加入少量樣本。提供少量提示 不過,這些例子只會示範如何套用操作說明,因此效益可能較低。於 就可以移除提示中的指示,如果範例夠明顯,可以顯示 處理相關工作

零樣本與少量樣本提示

下列零樣本提示要求模型選擇最合適的解釋。

Please choose the best explanation to the question:

Question: How is snow formed?
Explanation1: Snow is formed when water vapor in the air freezes into ice crystals in the
atmosphere, which can combine and grow into snowflakes as they fall through the atmosphere and
accumulate on the ground.
Explanation2: Water vapor freezes into ice crystals forming snow.
Answer:
  
Explanation1
  

如果您的用途需要模型產生簡潔的回應,您可以在 提示讀者 優先選擇精簡的回覆

下列提示會提供兩個範例,說明偏好較短的說明。於 可看到這些範例引導模型選擇較簡短易懂的解釋 (說明 2) 與之前的長說明 (說明 1) 不同。

Please choose the best explanation to the question:

Question: Why is sky blue?
Explanation1: The sky appears blue because of Rayleigh scattering, which causes shorter blue
wavelengths of light to be scattered more easily than longer red wavelengths, making the sky look
blue.
Explanation2: Due to Rayleigh scattering effect.
Answer: Explanation2

Question: What is the cause of earthquakes?
Explanation1: Sudden release of energy in the Earth's crust.
Explanation2: Earthquakes happen when tectonic plates suddenly slip or break apart, causing a
release of energy that creates seismic waves that can shake the ground and cause damage.
Answer: Explanation1

Question: How is snow formed?
Explanation1: Snow is formed when water vapor in the air freezes into ice crystals in the
atmosphere, which can combine and grow into snowflakes as they fall through the atmosphere and
accumulate on the ground.
Explanation2: Water vapor freezes into ice crystals forming snow.
Answer:
  
Explanation2
  

找出最理想的樣本數量

您可以嘗試在提示中提供的樣本數量,找出最符合需求的提示。 也就是預測結果PaLM 和 Gemini 等模型通常可透過一些範例找出模式,不過 您可能得嘗試實驗數目的樣本數目,才能達到所需的結果。較簡單的模型 像是 BERT 等,因此需要更多範例。而且,如果您加入的樣本過多 可能會開始 過度配適

使用範例來說明模式而非反面模式

透過範例來展示模型待依循的模式,比使用範例來得有效。 向模型呈現反面模式

排除模式

Don't end haikus with a question:
Haiku are fun
A short and simple poem
Don't you enjoy them?
  

一般模式

Always end haikus with an assertion:
Haiku are fun
A short and simple poem
A joy to write
  

在所有範例中使用一致的格式

請確保少量樣本樣本的結構和格式相同,避免產生回應 不符所需格式在提示中加入少量樣本範例的主要目標之一是 要顯示回應格式因此,確保不同產品/服務採用一致的廣告格式至關重要 所有範例,尤其是 XML 標記、空格、換行符號和範例 分割器。

摘要

  • 在提示中加入提示回應範例,有助模型瞭解如何回應。
  • 為模型提供要追蹤的模式範例,而非模式範例 請避免。
  • 測試要加入的提示數量。視模型而定,樣本數太少 無法有效變更模型行為樣本過多會導致模型過度配適。
  • 在所有範例中使用一致的格式

新增情境資訊

您可以在提示中 而不是先假設模型已具備所有必要資訊。這項內容比對 資訊有助於模型瞭解您要求內容的限制和細節 信任關係

下例會要求模型提供路由器的疑難排解指引:

What should I do to fix my disconnected wifi? The light on my Google Wifi router is yellow and
blinking slowly.
  
1. **Check the Cables:**
- Make sure that all cables are securely connected to your Google Wifi router and modem.
- Try replacing the cables with new ones to ensure they are not faulty.


2. **Reboot the Router:**
- Unplug your Google Wifi router and modem from the power outlet.
- Wait for at least 30 seconds.
- Plug the modem and router back in and wait for them to start up.


3. **Factory Reset the Router:**
- Resetting the router will restore it to its default settings.
- Find the small reset button on the back of the router.
- Press and hold the reset button with a paper clip or similar object for 10 seconds.
- Release the button and wait for the router to restart.


4. **Check Your Internet Connection:**
- Use a wired connection to connect a device directly to your modem.
- If the internet works, the issue may be with your router.
- If the internet still doesn't work, contact your Internet Service Provider (ISP).


5. **Update Router's Firmware:**
- Check if there is a firmware update available for your Google Wifi router.
- Download and install the latest firmware update from the Google Wifi app.


6. **Interference and Obstacles:**
- Make sure the router is not near electronic devices that can cause interference, like microwaves or cordless phones.
- Remove any obstacles between the router and your devices, such as furniture or thick walls.


7. **Change Wi-Fi Channel:**
- In the Google Wifi app, go to Settings > Network & General > Advanced Networking.
- Try changing the Wi-Fi channel to a less congested one.


8. **Contact Google Support:**
- If you've tried the above steps and the issue persists, contact Google support for further assistance.
  

回覆內容似乎是一般性的疑難排解資訊,並非專屬於路由器。 LED 指示燈的狀態。

如要自訂特定路由器的回應,請將 疑難排解指南,做為提供回應時參考的背景資訊。

Answer the question using the text below. Respond with only the text provided.
Question: What should I do to fix my disconnected wifi? The light on my Google Wifi router is yellow and blinking slowly.

Text:
Color: Slowly pulsing yellow
What it means: There is a network error.
What to do:
Check that the Ethernet cable is connected to both your router and your modem and both devices are turned on. You might need to unplug and plug in each device again.

Color: Fast blinking yellow
What it means: You are holding down the reset button and are factory resetting this device.
What to do:
If you keep holding down the reset button, after about 12 seconds, the light will turn solid yellow. Once it is solid yellow, let go of the factory reset button.

Color: Solid yellow
What it means: Router is factory resetting.
What to do:
This can take up to 10 minutes. When it's done, the device will reset itself and start pulsing white, letting you know it's ready for setup.

Color: Solid red
What it means: Something is wrong.
What to do:
Critical failure. Factory reset the router. If the light stays red, contact Wifi customer support.
  
Check that the Ethernet cable is connected to both your router and your modem and both devices are turned on. You might need to unplug and plug in each device again.
  

摘要

  • 在提示中,加入您希望模型在產生 回應。
  • 為模型提供如何使用情境資訊的指示。

新增前置字串

前置字元是指你在提示內容中加入的字詞或詞組,有多種用途。 視您加入前置字元的位置而定:

  • 輸入前置字元:為具備語意意義的輸入信號新增前置字串 輸入至模型的各個部分例如前置字串「English:」以及「法文」:區分兩個 不同語言
  • 輸出前置字串:雖然輸出內容是由模型產生,但您也可以 為輸出結果輸入前置字串輸出前置字串會為模型 可當做回應例如輸出內容前置字串「JSON:」向模型發出 則應採用 JSON 格式
  • 前置字串範例:在少量樣本提示中,在範例中加入前置字串 模型產生輸出內容時使用的標籤,方便您剖析輸出內容 內容。

在下方範例中,「文字」:為輸入前置字元,「答案為:」是輸出內容 前置字串。

Classify the text as one of the following categories.
- large
- small
Text: Rhino
The answer is: large
Text: Mouse
The answer is: small
Text: Snail
The answer is: small
Text: Elephant
The answer is:
  
large
  

讓模型完成部分輸入

生成式語言模型的運作方式與進階自動完成工具類似,如果提供部分資訊 模型就能提供其餘內容 把內容視為回應因此,只要您附上任何範例或背景資訊,模型就能採用 這些例子或背景資訊。

以下範例提供指示和實體輸入內容的提示:

For the given order, return a JSON object that has the fields cheeseburger, hamburger, fries, or
drink, with the value being the quantity.

Order: A burger and a drink.
  
```
{
"cheeseburger": 0,
"hamburger": 1,
"fries": 0,
"drink": 1
}
```
  

雖然模型會依照提示,以自然語言寫出指示, 這可能就很有挑戰性,導致模型的解讀能力例如餐廳菜單 可能包含許多項目如要縮減 JSON 回應的大小,您可能會想要省略 未能下單。在這種情況下,您可以提供範例和回應前置字串,讓模型 請完成:

Valid fields are cheeseburger, hamburger, fries, and drink.
Order: Give me a cheeseburger and fries
Output:
```
{
  "cheeseburger": 1,
  "fries": 1
}
```
Order: I want two burgers, a drink, and fries.
Output:
  
```
{
"hamburger": 2,
"drink": 1,
"fries": 1
}
```
  

請注意,「起司漢堡」該元素不屬於訂單,因此已從輸出中排除。

提示模型設定回應格式

完成策略也有助於設定回覆格式。下列範例會提示 建立短文大綱:

Create an outline for an essay about hummingbirds.
  
I. Introduction
A. Hook: Begin with an intriguing fact or description of hummingbirds.
B. Provide some background information on hummingbirds.
1. Mention their small size and long, thin beaks.
2. Highlight their unique ability to hover and fly backward.

II. Body
A. Anatomy and Physiology
1. Elaborate on their tiny size, making comparisons to other animals.
2. Describe their wings and how they enable hovering and swift flight.
3. Discuss their metabolism and energy requirements, emphasizing their caloric needs.

B. Feeding Habits and Diet
1. Explain their primary food source, nectar, and how they extract it from flowers.
2. Describe their ability to feed from a wide variety of flowers.
3. Mention their consumption of insects and the nutritional value they provide.

C. Migration Patterns
1. Discuss the incredible long-distance migrations of some hummingbird species.
2. Explain the phenomenon of seasonal migration and the environmental factors driving it.
3. Describe the routes taken by different species during migration.

D. Conservation and Threats
1. Highlight the importance of hummingbirds in ecosystems as pollinators.
2. Discuss the challenges and threats they face, such as habitat loss, nectar scarcity, and climate change.
3. Mention conservation efforts and ways to support hummingbird populations.

III. Conclusion
A. Summarize the main points covered in the essay.
B. Reinforce the importance of hummingbirds and their ecological role.
C. Provide a final thought or call to action to protect these fascinating creatures.
  

提示沒有指定大綱格式,且模型已為您選擇格式。若要取得 模型傳回特定格式的外框,您可以新增文字來代表 讓模型根據您啟動的模式完成

Create an outline for an essay about hummingbirds.
I. Introduction
   *
  
I. Introduction
* Capture the reader's attention with an interesting anecdote or fact about hummingbirds.
* Provide a brief background on hummingbirds, including their unique characteristics.
* State the main points that will be covered in the essay.

II. The Unique Characteristics of Hummingbirds
* Discuss the hummingbird's exceptionally rapid wing-beat, allowing them to hover and fly backward.
* Highlight their tiny size, making them the smallest birds in the world.
* Describe their long, slender beaks and tongues, allowing them to reach deep into flowers to extract nectar.
* Explain their iridescent plumage, which creates brilliant and vibrant colors.

III. Hummingbird Migration and Distribution
* Discuss the extensive migration patterns of hummingbirds, covering vast distances across continents.
* Describe the different habitats where hummingbirds can be found, including tropical rainforests, deserts, and urban areas.
* Explain the seasonal changes that influence hummingbird migration and habitat selection.

IV. Hummingbird Diet and Feeding Habits
* Focus on the hummingbird's primary food source, which is nectar from flowers.
* Describe their ability to consume insects, spiders, and other small invertebrates for protein.
* Explain how hummingbirds use their long, slender tongues to extract nectar from flowers.
* Discuss the importance of flowering plants in providing sustenance for hummingbirds.

V. Reproduction and Nesting Behavior
* Describe the mating rituals and courtship behavior of hummingbirds.
* Explain the process of nest-building, including the materials used and the unique characteristics of hummingbird nests.
* Discuss the role of the female hummingbird in laying and incubating eggs.
* Describe the development of hummingbird chicks and the role of both parents in providing care.

VI. Threats to Hummingbirds and Conservation Efforts
* Highlight habitat loss, climate change, and deforestation as significant threats to hummingbird populations.
* Describe the role of habitat conservation initiatives in protecting hummingbird habitats.
* Explain the importance of creating hummingbird-friendly gardens and landscapes.
* Discuss the efforts of organizations and individuals working to conserve hummingbird populations.

VII. Conclusion
* Summarize the main points covered in the essay, emphasizing the unique characteristics, migration patterns, diet, reproduction, and conservation of hummingbirds.
* Provide a closing statement that leaves a lasting impression on the reader and reinforces the significance of these fascinating creatures.
  

摘要

  • 如果您向模型提供部分輸入內容,模型會根據可用的 指定範例或情境
  • 讓模型完成輸入內容,有時可能會比自然地描述任務來得簡單 語言。
  • 在提示中新增部分答案,可以引導模型遵循所需的模式,或 格式。

將提示拆成幾個簡單元件

對於需要複雜提示的用途 並拆解成更簡單的元件

細分操作說明

與其在單一提示中多次提供指令,不如為每個指示建立一則提示。你可以 根據使用者輸入內容選擇要處理的提示

鏈結提示

針對涉及多個依序步驟的複雜工作,請讓每個步驟都做為提示並鏈結 依序發出多個提示在這個依序的提示鏈中, 會成為下一個提示的輸入內容序列中最後一個提示的輸出內容 最終輸出內容

匯總回應

匯總是指在容器的不同部分執行不同的平行工作 並匯總結果來產生最終輸出內容舉例來說,您可以指示模型 對資料的第一部分執行一項作業 然後對其餘部分 然後匯總結果

摘要

  • 將複雜指示拆解成每個指示的提示,並決定 才會根據使用者輸入內容套用篩選器
  • 將多個依序步驟拆成不同的提示並鏈結在一起,方便輸出結果 會成為下列提示的輸入內容
  • 拆分平行工作並匯總回應以產生最終輸出內容。

測試不同參數值

您傳送至模型的每個呼叫都含有參數值,用來控制模型產生的 回應。模型可能會針對不同的參數值產生不同的結果。實驗 為工作取得最佳值。您可以使用的參數 不同的模型可能會有差異最常見的參數如下:

  • 輸出符記數量上限
  • 溫度
  • Top-K
  • Top-P

輸出符記數量上限

可在回應中產生的權杖數量上限。符記是 大約四個字元100 個符記可對應至大約 20 個字詞。

如要取得較短的回覆,請指定較低的值;如要延長回應時間,請調高此值 回應。

溫度

系統會依據隨機性參數,在產生回應期間進行取樣 套用 topPtopK 時。溫度控制 選取符記的隨機程度。較低的溫度適用 需要更具確定性、較不具開放性或創意的提示 就算隨機性參數較高,也可能產生較多元或有創意的內容 也就是預測結果0 的溫度具有確定性,也就是說, 一律選取可能性最高的回覆

以大部分用途來說,可以先將隨機性參數設為 0.2,如果 模型傳回的回應可能太普通、太短 備用回應,請嘗試調高隨機性參數

Top-K

「Top-K」會影響模型選取輸出符記的方式。前 K 個 1 表示下一個選取的符記是所有可能性最高的符記 符記中符記 (也稱為「貪婪解碼」) 以及「Top-K」 3 代表下一個符記會從 隨機性參數

在每個符記選取步驟中,「前 K 高」符記為 抽樣接著進一步根據「可能性總和為 P」參數進一步篩選符記 產生最終符記

如要取得較不隨機的回覆,請指定較低的值;如要取得其他要求,請調高此值 隨機性回應「前 K 個」的預設值為 40

Top-P

「Top-P」會影響模型選取輸出符記的方式。已選取權杖 從機率最高 (請見「Top-K」) 到最低,直到達到機率總和 等於「可能性總和為 P」舉例來說,假設符記 A、B 和 C 的可能性 0.3、0.2 和 0.1,而「可能性總和為 P」的值為 0.5,則模型 使用隨機性參數選取 A 或 B 做為下一個符記,並排除 C 候選人。

如要取得較不隨機的回覆,請指定較低的值;如要取得其他要求,請調高此值 隨機性回應「可能性總和為 P」的預設值為 0.95

提示疊代策略

提示設計是反覆式的過程 通常需要經過多次疊代 。本節提供可嘗試的 反覆改進提示

使用不同的措辭

在提示中使用不同字詞或措辭,通常會產生與模型不同的回覆 但這些 D 代表什麼意思?如果無法從 提示,請換個說法

Version 1:
How do I bake a pie?

Version 2:
Suggest a recipe for a pie.

Version 3:
What's a good pie recipe?
  

切換至類似工作

如果無法取得模型的執行指示,請試著 也能達成相同結果的類似任務

這個提示會指示模型使用預先定義的類別將書籍分類。

Which category does The Odyssey belong to:
thriller
sci-fi
mythology
biography
  
The answer: mythology

Explanations:

The Odyssey is an epic poem in ancient Greek literature. It is one of two major ancient Greek epic
poems attributed to Homer. The Odyssey is an epic poem that tells the story of Odysseus, a Greek
hero who fought in the Trojan War and then spent ten years trying to return home to Ithaca. The
Odyssey is a work of mythology.
  

回應正確,但模型未保持在選項範圍內。以及 讓模型只提供其中一組選項做為回覆,而非完整的句子。在本例中 您可將操作說明改寫為選擇題,然後請模型選擇 如果有需要 SQL 指令的分析工作負載 則 BigQuery 可能是最佳選擇

Multiple choice problem: Which of the following options describes the book The Odyssey?
Options:
- thriller
- sci-fi
- mythology
- biography
  
The answer is: mythology
  

變更提示內容的順序

提示中的內容順序有時可能會影響回覆。請嘗試變更 看看這對回應有何影響。

Version 1:
[examples]
[context]
[input]

Version 2:
[input]
[examples]
[context]

Version 3:
[examples]
[input]
[context]

備用回應

備用回應是指模型在系統根據提示或回應 就會觸發安全性篩選器備用回應的範例為:「我無法提供這方面的協助, 我只是語言模型。」

如果模型提供備用回應,請嘗試調高隨機性參數。

應避免的事項

  • 避免依賴模型來產生事實資訊。
  • 請謹慎處理數學和邏輯問題。

後續步驟