大型語言模型常用的 Design Pattern | Coursera 課程回顧(上)

2024/02/13閱讀時間約 18 分鐘

Overview-What is LLM?

大型語言模型(Large Language Model,LLM)是一項人工智慧技術,其目的在於理解生成人類語言,可將其想像成一種高階的「文字預測機器」,然而,它們並非真正理解語言。

這些模型的訓練過程需要龐大的文本數據,包括書籍、網頁等各種來源。然後,這些文本數據被輸入到模型中,使其嘗試學習這些文本的模式(語言的結構和語義規則,包括詞彙的含義、語法和語境等等)。

例如,若我們給予模型一個句子,如「我今天早上吃了...」,我們期望模型能夠預測下一個詞可能是「吐司」、「麵包」、「蛋」等。

大型語言模型之所以稱為大型,是因為它們通常包含數十億甚至數百億的參數。這些參數可以視為模型的「記憶單元」,儲存了模型從數據中學到的各種模式和規則。

雖然大型語言模型在理解和生成文本方面表現驚人,但它們並非真正理解語言,也缺乏世界運作的知識,模型可能學到偏見或生成不準確的信息。儘管存在挑戰,大型語言模型仍是一種極具價值的工具,可應用於多種任務,包括回答問題、生成文章、整理資料、翻譯語言等。

what you need to know when using a LLM?

  1. LLM 的數學很糟。LLM 是在大量文本上進行訓練,而解決數學問題可能需要其他模型。
  2. 使用英文來提詞你會的得到更好的回答。論文🔗
  3. 偏見與幻覺。LLM 在回應中基於它的訓練資料集可能展現偏見;在回答不知道答案的問題時可能產生“幻覺”或生成虛假信息。
  4. 耐心。LLM 透過精準的對話,基於對話的上下文,可以提供更精確的生成結果。
  5. 平庸的輸入導致平庸的輸出。請使用 Prompt Pattern… 等等方法提高生成輸出的品質。

what is Prompt Pattern?

Prompt Pattern 是一種使用 LLM 時的技能。Prompt Pattern 是給予LLM的指示,以強制執行我們定義的規則、自動化流程,並確保生成的輸出擁有特定的品質(和數量)。

接下來會整理課程 中所提及的 Prompt Pattern ,應用 LLMs 於生活中的各種工作。


1. Persona Pattern

The Persona Pattern 旨在賦予模型特定的角色,以調整 LLM 生成內容風格的方法,使其更貼合特定的需求。

  • 特別注意角色可以是人物、職業、動物、甚至是扮演 Linux Terminal 都可以。🔗🔗🔗
Act as a [Persona] ..., Perform [task]


2. Audience Persona Pattern

Audience Persona Pattern 旨在根據不同受眾的需求和特點,調整模型生成的內容以更好地迎合特定受眾。

Explain [things] to me. Assume that I am [Persona].
raw-image


3. Question Refinement Pattern

Question Refinement Pattern 旨在幫助我們優化提問方式,更精準地向模型提出問題,以獲得更準確、有深度的回答。

From now on, whenever I ask a question, suggest a better version of the question.[and ask me if I would like to use it instead]
raw-image


4. Cognitive Verifier Pattern

Cognitive Verifier Pattern 旨在增強回應的準確性和相關性。Cognitive Verifier Pattern 將複雜的問題拆分為更小、可管理的子問題。這些子問題的答案然後結合在一起,以提供對主要問題的全面回答。這種方法在初始問題過於高層次或需要額外澄清以提供完整答案時非常實用。

When you are asked a [question], follow these rules :
1. Generate a number of additional questions that would help more accurately answer the question
2. Combine the answers to the individual questions to produce the final answer to the overall question


5. Flipped Interaction Pattern

Flipped Interaction Pattern 通常使用 LLM 都是主動向語言模型提問,然後它 LLM 成一個回應。Flipped Interaction Pattern 顛覆了這種模式,讓語言模型主動提問,而你成為回答者。

Flipped Interaction Pattern 對於語言模型而言,這種提示模式讓它以更精確和訂製的方式獲取 LLM 需要回答你問題所需的信息,讓 LLM 透過問答收集資訊和告訴你缺少的資訊。

Flipped Interaction Pattern 的優勢是這使得互動對你來說更輕鬆。與其花費大量時間考慮任務並製作一個包含你認為可能需要的所有細節的冗長提示,不如讓人工智慧通過提出一系列問題,你只需以項目符號或段落格式回答。

I would like you to ask me questions to achieve [things]
You should ask questions until [condition Y] is met or to achieve this goal (alternatively, forever)


6. Template Pattern

Template Pattern 旨在迅速整理資訊成預定義好的格式。

使用者只需提供特定問題的關鍵信息,而模型則基於預定的模板生成相應的回答,使得使用者可以更輕鬆地生成特定內容,同時確保信息的一致性。

I am going to provide a template for your output. <PLACEHOLDER> is my placeholder for content. Try to fit the output into one or more of the placeholders that I list. Please preserve the formatting and overall template that I provide. 

This is the template:
[your design template]

7. Meta Language Creation Pattern

Meta Language Creation Pattern 旨在提升對話的靈活性和個性化,這種模式讓使用者能夠創建自定義語言,從而更貼近個人需求和喜好。

When I say X, I mean Y (or would like you to do Y)
You will need to replace "X" with an appropriate statement, symbol, word, etc. You will then need to may this to a meaning, Y.


8. Recipe Pattern

Recipe Pattern 目的是讓使用者能夠輕鬆快速地獲得特定任務的解決方案,就像按照食譜製作菜餚一樣。簡而言之,這種模式提供了一個結構化的方法,讓使用者以步驟方式定制和生成內容。

例如,當你想要撰寫一篇文章,但不確定如何開始時,你可以使用食譜模式,提供文章主題和風格要求,讓模型為你生成一份開始撰寫的指南。

I would like to achieve X 
I know that I need to perform steps A,B,C
Provide a complete sequence of steps for me, Fill in any missing steps
(Optional) Identify any unnecessary steps

下圖為和 Meta Language Creation Pattern 組合使用:

下圖為獨自使用範例:


9. Alternative Approaches Pattern

Alternative Approaches Pattern 旨在利用 LLM 進行腦力激盪,提供多元的解決方案,使用者能夠根據特定需求或情境,快速選擇合適的方法。

例如,當你在寫作時感到困惑,不確定要選擇哪個方向時,你可以使用替代方法模式,請LMM提供不同的結構、風格或主題的建議,從而激發你的靈感。

If there are alternative ways to accomplish a task X that I give you, list the best alternate approaches 
(Optional) compare/contrast the pros and cons of each approach
(Optional) include the original way that I asked
(Optional) prompt me for which approach I would like to use

10. Ask for Input Pattern

Ask for Input Pattern 旨在尋求 LLM 協助時,更主動地引導對話,確保所得到的回應更符合使用者的期望。通常用在避免讓 LLM 無俚頭地一直產生內容,等我們的指令或是提詞,掌握整個對話的主導權。

[your prompt, rules, data]
Ask me for [input X]

#Tailored Examples:
From now on, I am going to cut/paste email chains into our conversation. You will summarize what each person's points are in the email chain. You will provide your summary as a series of sequential bullet points. At the end, list any open questions or action items directly addressed to me.
**Ask me for the first email chain.**
raw-image


11. Combining Pattern

Combining Pattern 故名思議就是靈活運用多種 Prompt Pattern 的策略,以更全面、多樣性地應對日常生活中不同的問題。

[Pattern1]
[Pattern2]
[Pattern3]
[Pattern...]


12. Outline Expansion Pattern

Outline Expansion Pattern 適用於擴展和深化對話主題的策略。簡而言之,這種模式下使用者會提供初始主題,然後透過 LLM 生成大綱,並可以一步一步地討論更詳盡、具體的內容,使對話更加豐富和有深度。

Act as an outline expander. 
Generate a bullet point outline based on the input that I give you and then ask me for which bullet point you should expand on.
Create a new outline for the bullet point that I select.
At the end, ask me for what bullet point to expand next.
Ask me for what to outline.


13. Menu Actions Pattern

Menu Actions Pattern 旨在通過提供先前定義的 Actions,引導 LLM 做出/產出特定內容。

進階的用法可以將 Actions 定義為其他的 Pattern,透過簡短的 Actions 就可以重複使用提詞冗長的 Pattern

Whenever I type: X, you will do Y. 
(Optional, provide additional menu items) Whenever I type Z, you will do Q.
At the end, you will ask me for the next action.


14. Fact Check List Pattern

Fact Check List Pattern 旨在確保生成的內容準確無誤,避免幻覺。簡而言之,這種模式透過產生一份清單,引導使用者針對特定內容進行事實核查,以確保信息的真實性和可靠性。

Generate a set of facts that are contained in the output 
The set of facts should be inserted at the end of the output
The set of facts should be the fundamental facts that could undermine the veracity of the output if any of them are incorrect


15. Tail Generation Pattern

Tail Generation Pattern 旨在通過生成一個「尾巴」,即模型生成的輸出結果的結尾,以幫助提醒 LLM 正在處理的內容。簡而言之,這種模式通過添加特定結構的文本,讓模型更好地理解正在進行的任務或對話的上下文關係,增強 LLM 的記憶。

這種方法特別適用於需要長對話的任務,確保模型在整個對話過程中保持一致性。

Your Prompt...
At the end, [repeat Y and/or ask me for X].

16. Semantic Filter Pattern 旨在有效控制模型生成的內容,確保所得到的回應更加符合特定語義要求。通常可以用在快速地清理文章內的個資/敏感資料。

Filter this information to remove [X]
raw-image

總結

我們探討了大型語言模型中的多種「Prompt Pattern」。這些模式不僅是與大型語言模型進行對話的技巧,也是引導模型生成更符合預期的內容的有效工具。

除了 Prompt Pattern 之外,課程中也還有提及其他技巧可以使大型語言模型產出更精確的內容,就留到下一篇在進行整理介紹瞜!!

延伸閱讀


三大大型語言模型工具

參考引源和學習資源整理




17會員
32內容數
歡迎來到「Marcos的方格子」!目前在「Marcos談科技」撰寫在職涯上學習到的知識,在「Marcos談書」分享我在日常的閱讀和心得,歡迎您的到來!!
留言0
查看全部
發表第一個留言支持創作者!