Prompt Engineering 學習筆記(考試溫習版)
0. 30 秒總複習(考前最後掃描)
| 你會用到的關鍵詞 | 一句話記法 |
|---|---|
| Prompt | 傳給語言模型、用來達成任務的指令+上下文 |
| Prompt Engineering | 開發並最佳化 prompt 的實務,以有效率地使用 LM |
| Elements of a Prompt | Instructions/Context/Input data/Output indicator 四件 |
| Temperature | 控制「確定性」;低=精確、高=多樣 |
| top_p | 另一顆確定性旋鈕;與 temperature 一起調 |
| Zero-Shot | 不給範例,靠預訓練知識直接做 |
| Few-Shot | 先給少量 input→output 範例再問(in-context learning) |
| Clear Instructions | 講明 Task/Format/Length/Tone/Constraints/Context |
| System Prompting | 設定常駐的操作規則層(語氣、界線、安全限制) |
| Role Prompting | 指派身分(teacher/PM/architect),影響語氣與決策標準 |
| Contextual Prompting | 補背景資訊(受眾、環境、限制),讓答案切題 |
| Markdown Prompting | 用標題/條列/表格/程式碼區塊規定輸出結構 |
| CoT | 要求逐步推理(think step by step) |
| TCoT | 把推理步驟放進表格(step/action/evidence/result) |
| SoT | 先產3–10 點骨架,再逐點展開 |
| Step-Back | 先退一步想通則/原則,再回到原題 |
| Least-to-Most | 拆解子問題,由易到難解完再合併 |
| ToT | 平行探索多條思路,評估後走最強分支 |
| iToT | ToT +每輪回饋迭代修正分支 |
| SG-ICL | 讓模型自己生範例,再用那些範例做 few-shot |
| CAI | 用明文原則/憲法約束回答(安全、公平、有據) |
| Perspective-Taking | 要求從多個利害關係人視角回答 |
| Analogical | 用類比把新概念接到熟悉經驗 |
| Multi-Modal | 文字+圖/文件/音訊/影片一起餵 |
| Persona Consistency | 跨多次輸出維持同一人格與語氣 |
| Predictive | 要求預測後果/風險(含機會、挑戰、變化) |
| Generate Knowledge | 先生成知識當上下文,再答題,取最高信心的答案 |
| PAL | 讓模型產程式,把解法外包給 Python 執行 |
| ReAct | 推理軌跡+行動交錯,可呼叫外部工具 |
| DAG | Data-Augmented Generation:檢索外部資料再生成 |
| Prompt Injection | 注入不可信指令劫持模型輸出 |
| Prompt Leaking | 逼模型吐出它自己的 prompt |
| Jailbreaking | 繞過安全與審核機制的注入攻擊 |
| RLHF | 用人類回饋訓練模型貼近人類偏好 |
1. Prerequisites & Objectives
這一節是課程的「先修與目標」頁。看起來像行政資訊,但它定義了這堂課的範圍: 你要會 Python、懂一點語言模型與深度學習/ML 概念,才吃得下後面的技術。 考試很愛考「這堂課的三個目標」與「先修條件」。
1.1 先修條件(Prerequisites)
| 先修 | 說明 |
|---|---|
| Python | 後面所有示範(PAL、ReAct、串 API)都以 Python 為載體 |
| Knowledge of language models | 至少要知道 LLM 在做什麼(對應 Lesson 3「Introduction to LLM」) |
| Basic understanding of deep learning / ML concepts | 懂基本 ML 詞彙(模型、訓練、推論)就夠,不需要會實作反向傳播 |
1.2 三個課程目標(Objectives)
- Present an introduction to prompt engineering——先建立 prompt engineering 的入門觀念。
- Present an overview of the latest prompting techniques——總覽最新的提示技術。
- Provide demonstrations and exercises to practice different prompting techniques——提供示範與練習,動手練不同技術。
考點:目標第三點是「示範與練習」——這正是課程裡 20 幾頁
Classroom Exercise存在的理由。 練習頁是成對的:同一題目各給「沒有用該技術」與「用了該技術」的版本,考題常問兩者差在哪。
2. What are prompts?
課程給出兩個定義:prompt 與 prompt engineering。這頁的字句要記牢, 因為後面每一種技術都只是「怎麼把 prompt 寫得更好」的變化。
2.1 兩個定義
| 名詞 | 定義 | 中文 |
|---|---|---|
| Prompt | instructions and context passed to a language model to achieve a desired task | 為了達成想要的任務,傳給語言模型的指令與上下文 |
| Prompt engineering | the practice of developing and optimizing prompts to efficiently use language models (LMs) for a variety of applications | 開發並最佳化 prompt 的實務,以便在各種應用中有效率地使用 LM |
2.2 補充說明
課程另外補充:prompt engineering 是「創造一組 prompts(或問題)」的過程, 用來把使用者引導到想要的結果;它是設計師用來打造易用、直覺使用者體驗的有效工具, 常用於互動設計與軟體開發,因為它讓使用者容易理解如何與系統或產品互動。
考點:兩個定義不要混。Prompt 是名詞(你送出的東西);prompt engineering 是動詞(你做的優化工作)。 另外「efficiently use」是關鍵——prompt engineering 的目的是用更少的成本/嘗試拿到更好的結果。
3. Why Prompt Engineering?
課程回答「為什麼要學」。三點理由,並引用了一份 Anthropic 的招聘啟事當佐證。
3.1 三個理由
| # | 原文 | 中文 |
|---|---|---|
| 1 | Important for research, discoveries, and advancement | 對研究、發現與技術推進很重要 |
| 2 | Helps to test and evaluate the limitations of LLMs | 幫助測試與評估 LLM 的極限 |
| 3 | Enables all kinds of innovative applications on top of LLMs | 讓各種創新應用得以建立在 LLM 之上 |
3.2 為什麼第 2 點最常被考
「測試與評估 LLM 的極限」是 prompt engineering 最容易被低估的用途: 它不是只有「讓模型答對」,更是主動找模型會答錯的地方——這正是後面 Part 4 (Model Safety、Prompt Injection、Jailbreaking)的伏筆。
考點:三點要能全列。第 2 點「test and evaluate the limitations」是關鍵字(不是 advantages)。
4. First Basic Prompt
課程用最小例子示範「輸入 → 輸出」的結構。這頁要記的是兩個欄位名稱與模型與參數。
text-davinci-003、temperature 0.7、top-p 1。|Qwen-Image 2.1 生成插圖4.1 結構:Instruction 與 Response
| 欄位 | 內容 |
|---|---|
| Instruction(你的輸入) | The sky is blue |
| Response(模型輸出) | The sky is a beautiful blue color during the day. The blue of the sky is created by the Earth's atmosphere scattering the sun's light. The blue is a result of the air molecules in the atmosphere reflecting the shorter wavelength of blue light back to our eyes. |
4.2 課程標註的模型與設定
| 項目 | 值 |
|---|---|
| Model | text-davinci-003 |
| temperature | 0.7 |
| top-p | 1 |
注意:
text-davinci-003是 OpenAI 早期的 GPT-3 系列 completion 模型(已淘汰), 但課程用它示範。考試若問「第一個範例用的模型與參數」,答案就是這三個數字。
4.3 這個例子示範了什麼
- 即使指令只有三個字(
The sky is blue),模型也會自行補完成一整段說明——這就是 completion(續寫)的威力。 - 輸出是流暢但沒有格式控制的自然段。要控制格式,就得靠後面 Chapter 11 的 Clear Instructions。
- temperature 0.7 是中性偏隨機;top-p 1 代表不截斷候選詞(考慮全部機率分佈)。
考點:
text-davinci-003/temperature0.7/top-p1。另外要能說出 Instruction 與 Response 的角色。
5. Elements of a Prompt
課程給出 prompt 的四個組成要素。這是整份筆記最常被直接考的清單之一。
5.1 四大要素
| # | 要素 | 英文 | 作用 |
|---|---|---|---|
| 1 | 指令 | Instructions | 你要模型做什麼(動詞:Classify/Summarize/Translate…) |
| 2 | 上下文 | Context | 背景資訊,讓答案切題 |
| 3 | 輸入資料 | Input data | 要被處理的實際內容 |
| 4 | 輸出指示 | Output indicator | 指定輸出格式/標籤集合 |
5.2 例子逐項拆解
課程把四個要素塞進一句很短的分類 prompt:
Classify the text into neutral, negative or positive ← Instructions(+Output indicator)
Text: I think the food was okay. ← Input data
Sentiment: ← Output indicator(要模型接著填)
| 要素 | 在這句裡的對應 |
|---|---|
| Instructions | Classify the text |
| Context | (此例從缺;見下方說明) |
| Input data | I think the food was okay. |
| Output indicator | into neutral, negative or positive + 結尾的 Sentiment: |
考點:Context 這一項在例子裡其實沒有出現。題目若問「四要素中哪一個在此例缺席」, 答案就是 Context。另外
Sentiment:這種「留一個尾巴讓模型接」的寫法,正是 output indicator 的典型手法。
6. Settings to keep in mind: temperature 與 top_p
課程提醒:同樣的 prompt,換設定會得到完全不同的結果。 其中最重要的兩顆旋鈕就是 temperature 與 top_p。
6.1 重點
- 對語言模型下 prompt 時,有幾個設定要放在心上。
- 不同設定會讓同一個 prompt 產生很不一樣的結果。
- 其中一個重要設定是控制模型在生成 completion 時有多「確定」(deterministic)。
- Temperature 與 top_p 是兩個最重要的參數。
- 想要精確答案 → 把這兩個調低;想要多樣回應 → 調高。
6.2 兩顆旋鈕怎麼記
| 參數 | 作用 | 低 | 高 |
|---|---|---|---|
| temperature | 縮放機率分佈;決定「隨機程度」 | 幾乎每次都選最高機率詞 → 穩定、可重現 | 分佈被拉平 → 多樣、有創意 |
| top_p(nucleus sampling) | 只從累積機率達 p 的最小詞集合中取樣 |
候選集合小 → 保守 | 候選集合大(=1 用全部) → 自由 |
6.3 實務建議
| 你的任務 | temperature | top_p |
|---|---|---|
| 分類、抽取、程式碼、數學 | 低(≈ 0–0.3) | 低 |
| 摘要、改寫 | 中(≈ 0.5–0.7) | 0.8–1 |
| 腦力激盪、故事、命名 | 高(≈ 0.8–1.2) | 1 |
考點:「精確 → 調低;多樣 → 調高」這句一定要背。 另外記得 temperature 與 top_p 通常不要同時大幅調整——課程把它們並列為「兩顆確定性旋鈕」, 但實務上調一顆、另一顆保持中性比較好抓因果。
7. Designing Prompts for Different Tasks(六大任務)
課程列出接下來要示範的六種常見任務,每個任務各一頁示範。 這六頁是最典型的「prompt 寫法範本」,考題常直接問「這句 prompt 屬於哪一類任務」。
7.1 六大任務總表
| # | 任務 | 英文 | 一句話 |
|---|---|---|---|
| 1 | 文本摘要 | Text Summarization | 把長文壓成一句/幾點 |
| 2 | 問答 | Question Answering | 依上下文回答問題 |
| 3 | 文本分類 | Text Classification | 把文字歸到既定標籤 |
| 4 | 角色扮演 | Role Playing | 讓模型以某身分對話 |
| 5 | 程式生成 | Code Generation | 由描述產生程式碼 |
| 6 | 推理 | Reasoning | 多步計算與判斷 |
7.2 Text Summarization
課程給一段抗生素的說明,指令只有一句 Explain the above in one sentence:,模型回:
Antibiotics are medications used to treat bacterial infections by either killing the bacteria or stopping them from reproducing, but they are not effective against viruses and overuse can lead to antibiotic resistance.
觀察:Context(抗生素原文)+ Instruction(Explain the above in one sentence:)→ 一句摘要。
課程在圖上把兩塊分別標成 Context 與 Instruction,這正是 Chapter 5 四要素的實際應用。
7.3 Question Answering
課程示範「依上下文回答、不確定就說不確定」:
Answer the question based on the context below. Keep the answer short and concise.
Respond "Unsure about answer" if not sure about the answer.
Context: Teplizumab traces its roots to a New Jersey drug company called Ortho
Pharmaceutical. There, scientists generated an early version of the antibody,
dubbed OKT3. Originally sourced from mice, the molecule was able to bind to the
surface of T cells and limit their cell-killing potential. In 1986, it was
approved to help prevent organ rejection after kidney transplants, making it the
first therapeutic antibody allowed for human use.
Question: What was OKT3 originally sourced from?
Answer: Mice.
兩個關鍵技巧:① Keep the answer short and concise(限制長度);
② 給定「不知道」的退路(Respond "Unsure about answer")——這是抑制幻覺最簡單有效的做法。
7.4 Text Classification
Classify the text into neutral, negative or positive.
Text: I think the food was okay.
Sentiment: Neutral
觀察:okay 這種「不好不壞」的字,正解是 Neutral 而不是 positive——課程用它示範標籤邊界的重要性。
7.5 Role Playing
The following is a conversation with an AI research assistant.
The assistant tone is technical and scientific.
AI: Greeting!
Human: Hello, who are you?
AI: I am an AI research assistant. How can I help you today?
Human: Can you tell me about the creation of black holes?
AI: Sure! Black holes are regions of spacetime where the gravitational force is
so strong that nothing, not even light, can escape from it. ...
觀察:開頭兩句就是 System/Role 設定(身分+語氣),並且課程自己先把開場幾輪對話寫出來
(AI: Greeting! …),這種「給範例對話」的手法同時也是 few-shot(Chapter 10)。
7.6 Code Generation
課程用三引號把資料庫 schema 當 context 塞進 prompt:
"""
Table departments, columns = [DepartmentId, DepartmentName]
Table students, columns = [DepartmentId, StudentId, StudentName]
Create a MySQL query for all students in the Computer Science Department
"""
模型輸出:
SELECT StudentId, StudentName
FROM students
WHERE DepartmentId IN (SELECT DepartmentId FROM
departments WHERE DepartmentName = 'Computer Science');
觀察:把 schema(結構)先講清楚,模型才寫得出正確的 IN + 子查詢。這是 code generation 的通用套路。
7.7 Reasoning
課程給一串數字 13, 7, 1, 15, 5, 32, 82,指令是:
Solve by breaking the problem into steps. First, identify whether the numbers
are odd or even. Then, add them, and indicate whether the result is odd or even.
模型的推理過程:
Odd numbers: 13, 7, 1, 15, 5 ← 逐步:先挑出奇數
Sum: 41
41 is an odd number. ← 結論
觀察:這頁其實已經是 Chain-of-Thought 的雛形(breaking the problem into steps)——
Part 1 先埋梗,Part 1 後半的 CoT(Chapter 16)再正式命名。
考點:六類任務要能配對。三句最容易被考的原句: ① QA 的
Respond "Unsure about answer" if not sure; ② Classification 的okay → Neutral; ③ Reasoning 的Solve by breaking the problem into steps(CoT 前身)。
8. Prompt Engineering 技術地圖(七大類)
課程給出「技術清單」,分成七大類,先展開第一類。 之後其餘各類也各有一頁展開。本筆記把五張總覽頁合併成這一章, 讓你先看到全貌,再逐章(Ch. 9–Ch. 32)展開每一種技術。
8.1 七大類技術
| # | 類別 | 英文 | 本筆記對應章節 |
|---|---|---|---|
| 1 | 基礎技術 | Foundational Techniques | Ch. 9–11 |
| 2 | 上下文與角色 | Context & Role-Based Techniques | Ch. 12–15 |
| 3 | 推理與規劃 | Reasoning & Planning Techniques | Ch. 16–19 |
| 4 | 進階編排與控制 | Advanced Orchestration & Control | Ch. 20–23、30–32 |
| 5 | 風格、語氣與人格 | Style, Tone & Persona | Ch. 28 |
| 6 | 迭代改進與精煉 | Iterative Improvement & Refinement | Ch. 22 |
| 7 | 專業與前沿 | Specialized & Cutting-Edge | Ch. 24–29 |
8.2 各類包含的技術
① Foundational Techniques
| 技術 | 一句話 |
|---|---|
| Zero-Shot Prompting | Ask the model to perform a task without examples. |
| Few-Shot Prompting (In-Context Learning) | Provide examples to guide the model's response style. |
| Clear Instructions & Task Framing | Use explicit, concise instructions with constraints(例:"Summarize in 3 bullet points")。 |
② Context & Role-Based Techniques
| 技術 | 一句話 |
|---|---|
| System Prompting | Define rules or boundaries for the AI(例:"You are a helpful tutor")。 |
| Role Prompting | Assign a persona(例:"Act as a project manager")。 |
| Contextual Prompting | Add background information for relevance. |
| Markdown Prompting | Use formatting to structure outputs clearly. |
③ Reasoning & Planning Techniques
| 技術 | 一句話 |
|---|---|
| Chain-of-Thought (CoT) | Ask the model to show step-by-step reasoning. |
| Tabular Chain-of-Thought (TCoT) | Structure reasoning in tables for clarity. |
| Skeleton-of-Thought (SoT) | Provide a high-level outline before details. |
| Step-Back Prompting | Ask the model to reflect before answering. |
④ Advanced Orchestration & Control
| 技術 | 一句話 |
|---|---|
| Least-to-Most Prompting | Break complex tasks into simpler steps. |
| Tree-of-Thoughts (ToT) | Explore multiple reasoning branches before deciding. |
| Interactive Tree-of-Thoughts (iToT) | Iteratively refine reasoning with feedback. |
| Self-Generated In-Context Learning | Model generates its own examples to improve accuracy. |
| Generate Knowledge Prompting | (同頁列出,見 Ch. 30) |
| Program-aided Language Model (PAL) | (同頁列出,見 Ch. 31) |
| ReAct | (同頁列出,見 Ch. 32) |
⑤ Specialized & Cutting-Edge
| 技術 | 一句話 |
|---|---|
| Constitutional AI (CAI) | Apply ethical or rule-based constraints. |
| Perspective-Taking Prompting | Ask the model to adopt different viewpoints. |
| Analogical Prompting | Use analogies to guide reasoning. |
| Multi-Modal Prompting | Combine text with images or other inputs. |
| Persona Consistency Prompting | Maintain a consistent character across outputs. |
| Predictive Prompting | Ask the model to anticipate outcomes. |
考點:七大類的名稱與順序是常考的表格題。最容易漏的是第 5、6 兩類 (Style, Tone & Persona 與 Iterative Improvement & Refinement)——因為這兩類沒有 單獨的展開頁,只在總表出現。
9. Zero-Shot Prompting
前面給定義,這裡給課堂練習。這是「基礎技術」裡最簡單的一種: 不給任何範例,直接叫模型做。
9.1 Definition
Asking an AI model to perform a task without giving examples. Relies on the model's pre-trained knowledge. Useful for quick, straightforward tasks.
| 要點 | 原文 |
|---|---|
| 定義 | 要求模型執行任務,不提供範例 |
| 依賴 | 模型預訓練的知識 |
| 適用 | 快速、直接的任務 |
9.2 Key Points
| 要點 | 原文 | 中文 |
|---|---|---|
| 1 | No context or examples provided. | 不提供上下文或範例 |
| 2 | Works best for general knowledge or simple tasks. | 最適合一般常識或簡單任務 |
| 3 | May produce generic or inconsistent results compared to few-shot prompting. | 相較 few-shot,輸出可能較籠統或不一致 |
9.3 Classroom Exercise
Prompt Example (Zero-Shot): "The sky is ______."
Expected Output: "Blue"
為什麼這題算 zero-shot:題目只給空格,沒有任何「input → output」示範;
模型完全靠預訓練常識補上 Blue。
考點:zero-shot 的優點是快、省 token;缺點是輸出可能籠統或不穩定(generic or inconsistent)。 這正是 few-shot 存在的理由——下一章就是它的解方。
10. Few-Shot Prompting
前面給定義,這裡給課堂練習。few-shot 就是「先示範幾組再叫模型做」。
10.1 Definition
Provide examples of input → output pairs before asking the model to perform the task. Helps the AI understand the format, style, or criteria you want.
| 要點 | 中文 |
|---|---|
| 做法 | 在要求模型做任務之前,先給幾組 input → output 範例 |
| 作用 | 幫模型理解你要的格式(format)、風格(style)、判準(criteria) |
10.2 Why It Matters
| 原文 | 中文 |
|---|---|
| Zero-Shot may give vague or inconsistent answers. | Zero-shot 可能給出含糊或不一致的答案 |
| Few-Shot shows the AI how to respond, reducing ambiguity. | Few-shot 示範該怎麼回,降低歧義 |
10.3 別名:In-Context Learning
課程在總表把 few-shot 標成 Few-Shot Prompting (In-Context Learning)—— 這個別名要記:範例是寫在「上下文(context)」裡的,模型不會更新權重, 只是在這次推論中「就地學會」你要的格式。這也是為什麼叫 in-context。
10.4 Classroom Exercise
Prompt Example (Few-Shot):
Example: the ocean is liquid.
the sky is ______
Expected Output: gas
觀察:這題和 Chapter 9 的 zero-shot 練習是同一句(The sky is ___),
但加了 the ocean is liquid. 這一個範例後,模型被引導到「狀態(liquid / gas)」這個語意框架,
所以答案是 gas 而不是 zero-shot 的 Blue。
考點:這組對照是必考點——同一個題目、有無範例會得到不同答案。 另外要記 few-shot 的別名 In-Context Learning,以及它不改權重。
11. Clear Instructions and Task Framing
前面給定義,這裡給「弱 prompt vs 強 prompt」對照表(本課最實用的一頁),接著是練習。 這一章講的是:把話講清楚本身就是一種技術。
11.1 Definition
Give the AI a precise goal, required format, constraints, and any necessary context before asking it to act.
| 面向 | 原文 | 中文 |
|---|---|---|
| Definition | Give the AI a precise goal, required format, constraints, and any necessary context before asking it to act. | 動手前先給模型:精確目標、要求格式、限制條件、必要上下文 |
| Why it matters | Reduces ambiguity, improves consistency, and makes outputs easier to evaluate and reuse. | 減少歧義、提升一致性、讓輸出更容易評估與重用 |
| When to use it | Any task where format, tone, length, or scope matters(summaries, classification, code, rubrics, reports). | 只要格式/語氣/長度/範圍重要就用(摘要、分類、程式、評分規準、報告) |
11.2 Key elements to include
課程明列六個要素:
| # | 要素 | 中文 |
|---|---|---|
| 1 | Task | 任務(要做什麼) |
| 2 | Format | 格式(輸出長什麼樣) |
| 3 | Length | 長度 |
| 4 | Tone | 語氣 |
| 5 | Constraints | 限制條件 |
| 6 | Context | 上下文 |
11.3 Examples: Weak vs Strong Prompt
這張表要整張背下來——它同時示範了「六要素怎麼落地」。
| 任務 | Weak Prompt(弱) | Strong Prompt(強) |
|---|---|---|
| Summary | Summarize this article. | Summarize the article in 3 bullet points, each ≤15 words, focusing on main findings. |
| Classification | Is this review good? | Label the review as Positive or Negative only; output one word. |
| Email draft | Write an email. | Write a 4-sentence email to a manager requesting a deadline extension; include reason and new proposed date. |
| Code task | Make a script. | Write Python that reads sales.csv, computes monthly averages, and prints JSON with region keys. |
強 prompt 的固定套路:動詞 + 產物 + 數量/長度限制 + 格式 + 必須包含的內容。
11.4 Classroom Exercise
Goal: Convert product descriptions into a 1-line marketing tagline.
Zero-Framing (ambiguous):
"Write a tagline for this product: A lightweight travel backpack with
anti-theft features."
Clear Instruction (framed):
"Write one marketing tagline (≤10 words) for this product.
Emphasize security and lightweight; use an energetic tone.
Output only the tagline."
| 差異點 | Zero-Framing | Clear Instruction |
|---|---|---|
| 數量 | 沒說幾個 | one |
| 長度 | 沒限制 | ≤10 words |
| 要強調什麼 | 沒說 | security、lightweight |
| 語氣 | 沒說 | energetic |
| 輸出範圍 | 沒說 | Output only the tagline(禁止廢話) |
考點:六要素(Task/Format/Length/Tone/Constraints/Context)要能默寫; 四組弱/強對照要能配對。最常考「強 prompt 比弱 prompt 多了什麼限制」。
12. System Prompting
前面給定義,接著是練習。system prompting 是所有後續對話都吃得到的常駐規則層, 也是實務上最常被用來做「產品化」的一種 prompt。
12.1 What it is
System prompting sets the core operating rules for the AI, such as tone, response style, constraints, safety limits, and task behavior. It acts like a permanent instruction layer that influences all later answers in the conversation.
| 關鍵字 | 說明 |
|---|---|
| core operating rules | 核心操作規則 |
| tone / response style | 語氣與回應風格 |
| constraints / safety limits | 限制條件/安全界線 |
| permanent instruction layer | 常駐指令層(影響之後所有回答) |
12.2 Why it matters
It improves consistency, reduces off-topic answers, and helps the model follow standards such as "be concise", "ask before assuming", or "output in bullets." It is especially useful in production workflows, teaching assistants, and support bots where repeatable behavior matters.
12.3 When to use it
Use system prompting when you want the AI to behave reliably across many tasks, not just one question. It works well for organizational rules, classroom rules, style guides, and output controls.
12.4 Classroom Exercise
| 版本 | 內容 |
|---|---|
| Input | Explain cloud computing. |
| Without System Prompting | 直接把上面那句丟給模型 → 輸出長度、語氣、深度全看運氣 |
| With System Prompting | You are a helpful IT tutor. Explain cloud computing in simple terms, use bullet points, avoid jargon, and give one real-world example. |
With 版本多做了四件事:① 給身分(helpful IT tutor);② 指定難度(in simple terms);
③ 指定格式(use bullet points);④ 下禁止條款(avoid jargon)+ 要求舉例(one real-world example)。
考點:system prompt 的三個關鍵詞——core operating rules、permanent instruction layer、 all later answers。它與 role prompting(Ch. 13)常一起考,差別在: system 管「規則與界線」(跨整個對話),role 管「身分與視角」(影響語氣與決策標準)。
13. Role Prompting
前面給定義,接著是練習。role prompting 只改一件事:你是誰。 但「你是誰」會改變語氣、詞彙、決策標準三件事。
13.1 What it is
Role prompting tells the AI to act from a defined identity such as a teacher, project manager, software architect, or analyst. A clearly stated role helps the model adopt the right tone, vocabulary, and decision criteria for the task.
| 會改變的三件事 | 中文 |
|---|---|
| tone | 語氣 |
| vocabulary | 詞彙 |
| decision criteria | 決策標準 |
13.2 Why it matters
Different roles produce different styles of output even for the same question. For example, a teacher explains concepts step by step, while a project manager focuses on scope, risk, and delivery.
這個「老師 vs PM」的對比是重點例子:同一個問題,換角色就換關注點。
13.3 When to use it
Use role prompting when perspective matters, especially for simulations, workplace writing, technical reviews, planning, or educational explanations. It is stronger when the role is specific rather than vague.
13.4 Classroom Exercise
| 版本 | 內容 |
|---|---|
| Input | Write a plan for a mobile app feature. |
| Without Role Prompting | 直接問 → 產出泛泛的功能說明 |
| With Role Prompting | Act as a product manager. Write a feature plan for a mobile app update, including goal, user story, dependencies, timeline, and rollout risks. |
With 版本做了兩件事:① 給具體角色(product manager,不是含糊的 expert);
② 給產出清單(goal/user story/dependencies/timeline/rollout risks)——後者是 PM 這個角色的決策標準。
考點:role prompting 影響的三件事(tone/vocabulary/decision criteria)+ 關鍵句 "stronger when the role is specific rather than vague"(角色越具體越好,不要寫 "an expert")。
14. Contextual Prompting
前面給定義,接著是練習。contextual prompting 不改角色、不改規則, 只補一件事:處境——受眾是誰、環境如何、有什麼限制。
14.1 What it is
Contextual prompting adds useful background such as audience, goals, environment, constraints, location, or prior knowledge. This helps the model understand not just the task, but the situation around the task.
| 可補的背景 | 中文 |
|---|---|
| audience | 受眾 |
| goals | 目標 |
| environment | 環境 |
| constraints | 限制 |
| location | 地點 |
| prior knowledge | 先備知識 |
14.2 Why it matters
A prompt without context often produces a generic answer. Adding context makes the response more relevant because the model can adapt to the real user, purpose, and setting.
14.3 Key idea
Use contextual prompting whenever the same question could require different answers in different settings.
這句話是判斷「要不要用 contextual prompting」的試金石:同一個問題在不同處境下答案會不同,就該補上下文。
14.4 Classroom Exercise
| 版本 | 內容 |
|---|---|
| Input | Suggest how to use AI in education. |
| Without Contextual Prompting | 直接問 → 得到一堆通用的「AI 可用於個人化學習」之類的空話 |
| With Contextual Prompting | My students are first-year learners with basic Python only. Suggest 3 classroom uses of AI that work in a school lab with limited computing power. |
With 版本補了四項背景:① 受眾(first-year learners);② 先備知識(basic Python only);
③ 數量(3 classroom uses);④ 環境限制(school lab with limited computing power)。
給一句「無上下文」的指令,再給「有上下文」的版本,要你比較兩者輸出差異。本筆記已把重點併入 14.4。考點:contextual 要補的六類背景(audience/goals/environment/constraints/location/prior knowledge) 是常考清單;另外要記 "the same question could require different answers in different settings" 這句判斷準則。 別與 role prompting 搞混:role 改「你是誰」,contextual 改「你在什麼處境」。
15. Markdown Prompting
前面給定義,接著是練習。這一章的技術成分最低,但投報率最高: 只要在 prompt 裡畫出「輸出骨架」,模型就會照著填。
15.1 What it is
Markdown prompting tells the model how to organize the response using headings, bullet points, numbered steps, tables, or code blocks. This improves both prompt clarity and output readability.
| 可用的結構元素 | 中文 |
|---|---|
| headings | 標題 |
| bullet points | 條列 |
| numbered steps | 編號步驟 |
| tables | 表格 |
| code blocks | 程式碼區塊 |
15.2 Why it matters
Even when the content is correct, poorly structured output is harder to read and reuse. Markdown gives the model a visible structure, which often leads to cleaner and more presentation-ready results.
15.3 Key idea
Use Markdown prompting when you want notes, reports, tutorials, summaries, or slide-ready content.
15.4 Classroom Exercise
| 版本 | 內容 |
|---|---|
| Input | Summarize machine learning |
| Without Markdown Prompting | 直接問 → 一坨連續文字,長度與切點都不受控 |
| With Markdown Prompting | Summarize machine learning in Markdown using these sections: **Overview, Key Types, Real-World Examples, and Limitations**. Use bullet points under each heading. |
With 版本做了兩件事:① 指定四個小節標題(Overview/Key Types/Real-World Examples/Limitations); ② 指定每個小節用 bullet points。等於先把輸出骨架畫好,模型只負責填肉。
給定不同的 section 清單與格式要求,比較「有/沒有 Markdown 指示」的輸出差異。本筆記已把重點併入 15.4。考點:Markdown prompting 的價值在於可讀性與可重用性(readable and reusable), 以及它同時改善prompt 清晰度與輸出可讀性這兩件事。另外要記四個示範小節名稱。
16. Chain-of-Thought (CoT) Prompting
前面給定義,接著是練習。這是推理類技術的起點,也是後面 TCoT/SoT/ToT 的基礎。
16.1 What it is
Chain-of-Thought prompting asks the model to reason through a task step by step before giving the final answer. Common trigger phrases include:
| 觸發語 | 中文 |
|---|---|
| "think step by step" | 一步一步想 |
| "work through this carefully" | 仔細推演 |
| "reason through this before answering" | 回答前先推理一遍 |
這三句是必背的觸發語——它們是「叫出 CoT」的開關。
16.2 Why it matters
This technique is useful for problems that involve logic, math, multi-step analysis, or careful decision-making. It often improves clarity because the model breaks a complex task into smaller reasoning steps.
16.3 When to use it
Use CoT when the task cannot be solved well with a one-line answer, especially for calculations, planning, troubleshooting, and structured reasoning.
16.4 Classroom Exercise
| 版本 | 內容 |
|---|---|
| Input | My student cannot run a Python notebook. What should I do? |
| Without CoT | 直接問 → 直接給一個「換一個 kernel 試試」之類的單點建議 |
| With CoT | My student cannot run a Python notebook in class. **Think step by step** and identify the **most likely causes in order**, then suggest a **troubleshooting sequence from simplest check to most advanced fix**. |
With 版本多了三個約束:① 觸發語(Think step by step);
② 要求排序(in order / from simplest check to most advanced fix);③ 明確的產出物(一份排好序的排查流程)。
考點:三句觸發語要能默寫(
think step by step/work through this carefully/reason through this before answering);適用場景(logic、math、multi-step analysis、 careful decision-making)與「由簡到繁排查」示範。
17. Tabular Chain-of-Thought (TCoT)
前面給定義,接著是練習。TCoT 是 CoT 的結構化版本: 推理步驟不寫成段落,而是排進表格。
17.1 What it is
Tabular Chain-of-Thought is a structured version of step-by-step reasoning in which the model presents each reasoning stage in a table. Instead of a paragraph of logic, the model organizes steps into columns such as step number, action, evidence, and result.
| 建議的欄位 | 中文 |
|---|---|
| step number | 步驟編號 |
| action | 動作 |
| evidence | 依據 |
| result | 結果 |
17.2 Why it matters
A table makes reasoning easier to scan, compare, and audit, especially when there are several conditions, options, or evaluation criteria. This is useful when teaching analytical thinking or reviewing multi-step decisions.
三個動詞要記:scan(掃視)、compare(比較)、audit(稽核)。
17.3 When to use it
Use TCoT for comparisons, decision matrices, troubleshooting flows, or any task where you want each reasoning step to be visible in a neat structure.
17.4 Classroom Exercise
| 版本 | 內容 |
|---|---|
| Input | Recommend the best laptop for a teacher. |
| Without TCoT | 直接問 → 得到一段推薦文,看不出取捨 |
| With TCoT | Recommend the best laptop for a teacher. Show your reasoning **in a table** with columns: **Option, Price, Battery Life, Portability, Pros, Cons, and Final Judgment**. |
With 版本把七個欄位全部指定——這七欄就是課程示範的 decision matrix 骨架。
⚠️ 「With」欄位裡混入了一段上一頁(CoT 練習)的殘留文字 (
My student cannot run a Python notebook in class...)——那是排版失誤。 本筆記只保留該頁真正要示範的內容(七欄表格)。考點:TCoT 的四個示範欄位(step number/action/evidence/result)與它的三個優點 (scan/compare/audit)是常考點;另外要能說出「TCoT = CoT + 表格化」。
18. Skeleton-of-Thought (SoT)
前面給定義,接著是練習。SoT 的核心是兩段式: 先產骨架(skeleton),再逐點展開(expand)。
18.1 What it is
Skeleton-of-Thought prompting asks the model to produce a brief outline or skeleton first, then expand each point afterward. A typical skeleton contains 3 to 10 short points that can later be developed in more detail.
| 關鍵數字 | 3 到 10 點 |
|---|---|
18.2 Why it matters
This method separates planning from elaboration, which can improve clarity and sometimes reduce response latency. It is especially useful when the answer is long and benefits from a clear top-level structure before details are added.
注意課程提到 reduce response latency(降低回應延遲)——這是 SoT 被提出的原始動機之一: 並行展開各點可以比逐字生成整段更快。
18.3 When to use it
Use SoT for essays, reports, lectures, study notes, or presentations where organization matters as much as content.
18.4 Classroom Exercise
| 版本 | 內容 |
|---|---|
| Input | Explain the impact of AI on education. |
| Without SoT | 直接問 → 一次吐出長文,結構不可控 |
| With SoT | First provide a **short skeleton outline** of the impact of AI on education using **5 bullet points**. Then **expand each point in 2 to 3 sentences**. |
With 版本把兩段式的數量都寫死:骨架 5 點、每點展開 2–3 句。
考點:SoT 的兩段式(skeleton → expand)、骨架點數範圍(3–10)、 以及它與 CoT 的差別:CoT 是「一條鏈」逐步推導;SoT 是「一個骨架」先定結構再分別長肉。
19. Step-Back Prompting
前面給定義,接著是練習。Step-Back 的動作是「先退一步」: 不直接答題,先問「這題背後的通則是什麼」,再用通則回來解題。
19.1 What it is
Step-Back prompting asks the model to step back from the exact question and first think about the higher-level concepts, principles, or framework behind it. After that, the model applies those general insights to the original task.
兩段式:① 抽象出通則 → ② 用通則解原題。
19.2 Why it matters
This technique helps reduce narrow or rushed answers by encouraging abstraction before detail. It is useful for complex questions where understanding the big picture leads to a better specific answer.
19.3 When to use it
Use Step-Back prompting for strategy, policy, design, analysis, and other tasks where principles matter more than immediate surface-level answers.
19.4 Classroom Exercise
| 版本 | 內容 |
|---|---|
| Input | How should a school adopt AI tools responsibly? |
| Without Step-Back Prompting | 直接問 → 直接跳出一串「要小心個資、要告知家長」的零散建議 |
| With Step-Back Prompting | Before answering, **step back and identify the main principles** of responsible AI adoption in education. **Then use those principles to recommend** how a school should adopt AI tools. |
With 版本把兩段式寫得很明確:step back and identify the main principles → then use those principles to recommend。
這也解釋了為什麼 Step-Back 特別適合政策/策略類問題。
考點:Step-Back 的兩段式順序(先通則、後解題),以及適用領域 (strategy/policy/design/analysis)。它與 Least-to-Most(Ch. 20)的差別: Step-Back 往「上」抽象成原則;Least-to-Most 往「下」拆成子問題。
20. Least-to-Most Prompting
前面給定義,接著是練習。Least-to-Most 的動作是「拆」: 把難題拆成子問題,由簡到繁逐一解完,再合併成最終答案。
20.1 What it is
Least-to-Most prompting breaks a difficult problem into smaller and simpler subproblems, solves them one by one, and then combines the results into a final answer. It follows a progression from easier reasoning to more complex reasoning.
| 三步 | 中文 |
|---|---|
| 1 | 拆成更小、更簡單的子問題 |
| 2 | 逐一解決 |
| 3 | 把結果合併成最終答案 |
20.2 Why it matters
Some tasks are too large or too messy to solve in a single pass. Decomposing them into smaller steps helps the model maintain focus and reduces confusion in multi-part tasks.
20.3 When to use it
Use Least-to-Most when the task naturally contains smaller components, such as coding, planning, long word problems, or layered analytical questions.
20.4 Classroom Exercise
| 版本 | 內容 |
|---|---|
| Input | Write a Python program for a student record system. |
| Without Least-to-Most | 直接要整支程式 → 模型可能漏掉需求、資料結構與函式界線模糊 |
| With Least-to-Most | Break this task into smaller parts: **identify required features, define the data structure, outline the functions, and then write the Python program** step by step from simplest part to full solution. |
With 版本把「拆分順序」寫死:需求 → 資料結構 → 函式輪廓 → 才寫程式。這正是實務上寫程式的正確順序。
20.5 與 CoT 的差別(本筆記補充)
| 比較 | CoT | Least-to-Most |
|---|---|---|
| 動作 | 對同一題逐步推理 | 把題目拆成多題再逐一解 |
| 結構 | 一條鏈 | 一組子問題+合併 |
| 適合 | 算術、邏輯、排查 | 大型任務(寫程式、規劃、長題幹) |
考點:Least-to-Most 的三步(拆解→逐一解→合併)與「由易到難」的方向; 適用場景(coding/planning/long word problems/layered analytical questions)是常考清單。
21. Tree-of-Thoughts (ToT)
前面給定義,接著是練習。ToT 把「一條鏈」升級成「一棵樹」: 同時長出多條思路,評估後只留最強的分支繼續走。
21.1 What it is
Tree-of-Thoughts extends step-by-step reasoning by letting the model explore multiple candidate paths or ideas in parallel, evaluate them, and then continue with the strongest branch. It is useful when one straight path is not enough and some search or backtracking is needed.
| 三個動作 | 中文 |
|---|---|
| explore in parallel | 平行探索多條候選路徑 |
| evaluate | 評估各路徑 |
| continue with the strongest | 只留最強分支繼續 |
關鍵字還有 search(搜尋)與 backtracking(回溯)——這是 ToT 與 CoT 最大的差別。
21.2 Why it matters
Many complex problems have more than one possible path. ToT helps the model compare alternatives instead of committing too early to a weak direction.
21.3 When to use it
Use ToT for strategy, planning, puzzles, creative ideation, optimization, or tasks where several solution branches should be explored before choosing one.
21.4 Classroom Exercise
| 版本 | 內容 |
|---|---|
| Input | Plan an AI club event for students. |
| Without ToT | 直接問 → 只給一個活動方案,無從比較 |
| With ToT | **Explore 3 possible event plans** for an AI club under limited budget and time. **Evaluate each plan by cost, learning value, and practicality**, then **choose the best option**. |
With 版本指定了三件事:① 分支數(3 possible event plans);② 評估準則(cost/learning value/practicality);
③ 最後要選一個(choose the best option)。這正是 ToT 的標準骨架:展開 → 評估 → 收斂。
考點:ToT 的三動作(parallel explore/evaluate/strongest branch)+ 兩個關鍵字 (search、backtracking)。與 CoT 的差別是分支與回溯,不是單純「步驟更多」。
22. Interactive Tree-of-Thoughts (iToT)
前面給定義,接著是練習。iToT = ToT + 每一輪都拿回饋修正。
22.1 What it is
Interactive Tree-of-Thoughts builds on Tree-of-Thoughts by refining branches iteratively with feedback after each round. Instead of generating all branches once, the model updates its reasoning based on evaluation, corrections, or new user guidance.
| 與 ToT 的差別 | ToT | iToT |
|---|---|---|
| 產生分支 | 一次產生全部分支 | 每輪逐步產生並修正 |
| 回饋 | 無 | 每輪都有(評估/修正/新的使用者指示) |
| 分支狀態 | 固定 | 弱的被修訂或替換 |
22.2 Why it matters
Some tasks improve through iteration rather than one-time branching. Interactive refinement allows the reasoning tree to become better over time as weak branches are revised or replaced.
22.3 When to use it
Use iToT when the task involves revision, feedback loops, or collaborative decision-making, such as planning, design, and brainstorming.
22.4 Classroom Exercise
| 版本 | 內容 |
|---|---|
| Input | Create a lesson plan for introducing AI ethics. |
| Without iToT | 一次生成 3 個教案就結束,不會回頭改 |
| With iToT | 先產生 3 個可能的教案方向 → 對每個方向評估並修正 → 把修正後的結果整合成最終教案 |
(generate → refine → present the improved final plan)用文字補齊。考點:iToT 的關鍵字是 iteratively、feedback after each round、revised or replaced。 一句話記:ToT 是「廣度搜尋」,iToT 是「廣度搜尋 + 迭代精煉」。
23. Self-Generated In-Context Learning (SG-ICL)
前面給定義,接著是練習。SG-ICL 解決的是 few-shot 的痛點: 範例要人手寫。那就讓模型自己生。
23.1 What it is
Self-Generated In-Context Learning asks the model to generate its own task-relevant examples first, and then use those examples as few-shot context for the final task. This reduces dependence on manually written exemplars.
| 兩步 | 中文 |
|---|---|
| 1 | 模型自己生成與任務相關的範例 |
| 2 | 把這些範例當作 few-shot 上下文去做最終任務 |
23.2 Why it matters
Good examples often improve prompt quality, but creating them manually takes time. SG-ICL uses the model itself to create examples closely related to the target task, which can improve input-example alignment.
23.3 When to use it
Use SG-ICL when few-shot prompting would help but you do not already have strong examples prepared. It is especially useful for classification, style imitation, and domain-specific tasks.
23.4 Classroom Exercise
| 版本 | 內容 |
|---|---|
| Input | Classify this customer comment as positive or negative. |
| Without SG-ICL | 直接分類 → 邊界案例容易判錯(沒有參照) |
| With SG-ICL | **First generate two short example comments, one positive and one negative.** Then use those examples as references to classify the target customer comment. |
With 版本只多做一步:先叫模型生一正一負兩個示範留言,再用它們當參照去分類目標留言。
考點:SG-ICL 的兩個關鍵字——self-generated examples、reduces dependence on manually written exemplars;以及它最適合的場景(classification/style imitation/domain-specific tasks)。
24. Constitutional AI (CAI)
前面給定義,接著是練習。CAI 是「把原則寫成清單,叫模型照著自我約束」的做法。
24.1 What it is
Constitutional AI uses an explicit set of principles, rules, or ethical constraints to guide how the model should respond. These rules act like a constitution that shapes answers toward safety, evidence, fairness, or other desired standards.
| 關鍵字 | 中文 |
|---|---|
| explicit set of principles / rules / ethical constraints | 明文的原則/規則/倫理限制 |
| constitution | 憲法(一組上位規範) |
| safety, evidence, fairness | 安全、有據、公平 |
24.2 Why it matters
Without clear governing principles, a model may answer in ways that are technically fluent but misaligned with policy or ethics. Constitutional-style constraints help the model critique or shape its own response according to predefined rules.
「technically fluent but misaligned」(講得漂亮但不合規)是這一頁的關鍵描述。
24.3 When to use it
Use CAI when you need aligned, policy-aware, or safety-aware responses, such as in education, customer support, public services, or regulated domains.
24.4 Classroom Exercise
| 版本 | 內容 |
|---|---|
| Input | Give advice on how schools should use AI |
| Without CAI | 直接問 → 可能給出忽略隱私或過度承諾的建議 |
| With CAI | Give advice on how schools should use AI. **Follow these principles**: ① prioritize student safety, ② respect privacy, ③ avoid unsupported claims, ④ acknowledge limitations, ⑤ recommend responsible use. |
With 版本列了五條原則——這五條就是課程示範的「憲法」。
考點:五條示範原則(student safety/privacy/avoid unsupported claims/acknowledge limitations/responsible use)是常考清單。CAI 的關鍵字:explicit principles、 self-critique(模型依規則檢視自己的回答)。
25. Perspective-Taking Prompting
前面給定義,接著是練習。這一種技術只做一件事: 強迫模型離開單一預設立場,把多個利害關係人的觀點都攤開。
25.1 What it is
Perspective-taking prompting asks the model to consider a problem from more than one viewpoint, such as student, teacher, parent, manager, or policymaker. This broadens the response beyond a single default perspective.
25.2 Why it matters
Many real-world questions affect different stakeholders in different ways. Considering multiple perspectives often produces a more balanced and nuanced answer.
兩個形容詞要記:balanced(平衡)、nuanced(細緻)。
25.3 When to use it
Use this technique for debate, policy, design, decision-making, and any task where stakeholder analysis is important.
25.4 Classroom Exercise
| 版本 | 內容 |
|---|---|
| Input | Is using AI tools for homework a good idea? |
| Without Perspective-Taking | 直接問 → 只得到一種立場(通常是「視情況而定」的空泛回答) |
| With Perspective-Taking | Evaluate using AI tools for homework **from the perspectives of a student, teacher, parent, and school administrator**. Identify **benefits, concerns, and trade-offs** for each viewpoint. |
With 版本指定了四個視角(student/teacher/parent/school administrator), 並要求每個視角都寫出 benefits/concerns/trade-offs 三欄。
考點:CAI 與 perspective-taking 都與「倫理」有關,但施力點不同: CAI 是「照規則約束自己」(單一立場、有紀律);perspective-taking 是「站到別人的位置」(多立場、求平衡)。
26. Analogical Prompting
前面給定義,接著是練習。Analogical prompting 用類比當橋樑, 把「不熟的新概念」接到「熟悉的舊經驗」。
26.1 What it is
Analogical prompting uses analogies to help the model reason or explain by relating a new idea to a familiar one. The analogy acts as a bridge between abstract concepts and known experience.
| 關鍵字 | 中文 |
|---|---|
| relating a new idea to a familiar one | 把新概念連到熟悉的事物 |
| a bridge | 類比是橋樑 |
26.2 Why it matters
Analogies are useful when the topic is difficult, technical, or unfamiliar. They can improve understanding by giving the model a clearer frame for explanation.
26.3 When to use it
Use analogical prompting for teaching, conceptual explanation, simplification, and sense-making across unfamiliar topics.
26.4 Classroom Exercise
| 版本 | 內容 |
|---|---|
| Input | Explain how a neural network works. |
| Without Analogical Prompting | 直接問 → 得到一堆術語(權重、梯度、激活函數),初學者吃不下去 |
| With Analogical Prompting | Explain how a neural network works **by using an analogy to how students learn from practice and feedback in class**. **Then connect the analogy back to the technical idea.** |
With 版本有兩個關鍵動作:① 指定類比來源(how students learn from practice and feedback);
② 要求把類比接回技術概念(connect the analogy back to the technical idea)——
少了第②步,類比就只是故事,沒有教學效果。
考點:analogical prompting 的兩個關鍵字——a bridge、connecting back to the technical idea; 適用場景(teaching/conceptual explanation/simplification/sense-making)。
27. Multi-Modal Prompting
前面給定義,接著是練習。多模態提示就是把文字以外的輸入也餵進去: 圖、文件、音訊、影片。
27.1 What it is
Multi-modal prompting combines text instructions with other input types such as images, documents, audio, or video. The model is asked to interpret and connect information across these different modalities.
| 模態 | 中文 |
|---|---|
| images | 影像 |
| documents | 文件 |
| audio | 音訊 |
| video | 影片 |
27.2 Why it matters
Some tasks cannot be solved well from text alone because important evidence exists in visual or audio form. Multimodal prompting allows the model to reason across richer input sources.
27.3 When to use it
Use multimodal prompting for image analysis, slide review, document understanding, UI feedback, diagram explanation, and tasks involving screenshots or photos.
27.4 Classroom Exercise
| 版本 | 內容 |
|---|---|
| Input | Summarize this business report of Underlying consumer price inflation stayed modest in the first quarter of 2025 Hong Kong. |
| Without Multi-Modal Prompting | 只給文字摘要需求 → 模型看不到圖表,無法談視覺趨勢 |
| With Multi-Modal Prompting | **Look at the attached chart and the accompanying report text.** Summarize the **main trend**, explain **what the visual shows**, and identify **one possible risk suggested by the chart** in the first quarter of 2025 Hong Kong. |
With 版本的三個要求都必須「看圖」才答得出:main trend、what the visual shows、risk suggested by the chart。
考點:multi-modal 的四種輸入(images/documents/audio/video)+ 適用場景 (image analysis/slide review/document understanding/UI feedback/diagram explanation/ screenshots or photos)是常考清單。
28. Persona Consistency Prompting
前面給定義,接著是練習。這一種技術屬於 Style, Tone & Persona 那一類, 目的是跨多次輸出維持同一個「人」。
28.1 What it is
Persona consistency prompting tells the model to maintain the same character, voice, style, or behavioral identity across outputs. This is useful when you want responses to sound like the same assistant, narrator, tutor, or fictional character over time.
28.2 Why it matters
Without consistency instructions, the model's tone and personality may drift across turns or documents. Persona consistency helps maintain continuity in style, vocabulary, and interaction behavior.
關鍵字:drift(漂移)——這是它要解決的問題。
28.3 When to use it
Use this technique in storytelling, tutoring bots, branded assistants, role-play exercises, and multi-part content creation.
28.4 Classroom Exercise
| 版本 | 內容 |
|---|---|
| Input | Write three short replies as a study coach. |
| Without Persona Consistency | 三次回覆可能語氣不一:一次很嚴肅、一次很熱血、一次很簡短 |
| With Persona Consistency | Write three short replies **as the same study coach**. **Keep the tone encouraging, calm, practical, and supportive in every reply**, and **do not change personality or speaking style**. |
With 版本指定了四個語氣形容詞(encouraging/calm/practical/supportive),
並加上禁止條款(do not change personality or speaking style)。
考點:persona consistency 要解決的是 drift;關鍵字是 the same character / voice / style / behavioral identity。它與 role prompting(Ch. 13)的差別: role 是「單次指派身分」;persona consistency 是「跨多次維持同一個身分不變」。
29. Predictive Prompting
前面給定義,接著是練習。預測式提示要模型往前看: 不只描述現況,還要推測接下來會發生什麼。
29.1 What it is
Predictive prompting asks the model to anticipate likely outcomes, consequences, or future developments based on the current situation.
29.2 Why it matters
Many decisions depend on what is likely to happen next, not just on what is true now. Predictive prompting helps the model extend analysis beyond the present so that planning and risk assessment become more useful.
29.3 When to use it
Use predictive prompting for forecasting, risk assessment, planning, and decision support where future implications matter.
29.4 Classroom Exercise
| 版本 | 內容 |
|---|---|
| Input | Explain the impact of AI use in classrooms. |
| Without Predictive Prompting | 直接問 → 只描述現在的影響 |
| With Predictive Prompting | Analyze the **current use** of AI in classrooms and **predict three likely outcomes over the next two years**, including **one opportunity, one challenge, and one likely change in teaching practice**. |
With 版本把預測的結構寫死:時間範圍(next two years)、數量(three)、 且必須涵蓋三種類別(opportunity/challenge/change in teaching practice)。
考點:predictive prompting 的三個適用領域(forecasting/risk assessment/decision support); 以及「1 機會 + 1 挑戰 + 1 教學變化」三段式結構。
30. Generate Knowledge Prompting
前面給定義,這裡用高爾夫球的例子完整示範兩階段流程。 這是「先產生知識、再用知識答題」的技術。
30.1 核心概念
| 原文 | 中文 |
|---|---|
| This technique involves using additional knowledge provided as part of the context to improve results on complex tasks such as commonsense reasoning | 把額外知識當成上下文的一部分,來改善常識推理這類複雜任務的表現 |
| The knowledge used in the context is generated by a model and used in the prompt to make a prediction | 這些知識是由模型生成的,再放進 prompt 裡做預測 |
| Highest-confidence prediction is used | 最後採用信心最高的那個預測 |
30.2 兩階段流程
階段一:Generate Knowledge
問題 → 讓模型生成「一段相關知識」→ 得到 Knowledge 1、Knowledge 2 …(可多條)
階段二:Knowledge-Augmented Answering
把「原問題 + 每條知識」各組一個 prompt → 得到多個「Explain and Answer」提案
→ 選「信心最高」的那一個當最終答案
30.3 課程示範
階段一:生成知識
| Input | 生成的 Knowledge |
|---|---|
| Greece is larger than mexico. | Greece is approximately 131,957 sq km, while Mexico is approximately 1,964,375 sq km, making Mexico 1,389% larger than Greece. |
| A rock is the same size as a pebble. | A pebble is a clast of rock with a particle size of 4 to 64 millimetres based on the Udden-Wentworth scale of sedimentology. Pebbles are generally considered larger than granules (2 to 4 millimetres diameter) and smaller than cobbles (64 to 256 millimetres diameter). |
| Part of golf is trying to get a higher point total than others. | (產生了兩條知識:Knowledge 1 與 Knowledge 2,見下) |
階段二:用知識答題
題目:Question: Part of golf is trying to get a higher point total than others. Yes or No?
| 用哪條知識 | 模型的 Explain and Answer | 判定 |
|---|---|---|
Knowledge 1(The objective of golf is...) |
Answer: No, the objective of golf is not to get a higher point total than others. Rather, the objective is to play a set of holes in the least number of strokes. The total number of strokes is used to determine the winner of the game, not the total number of points. | ✅ High-confidence prediction |
Knowledge 2(Golf is a precision club-and-ball sport...) |
Answer: Yes, part of golf is trying to get a higher point total than others. Each player tries to complete the course with the lowest score... | ❌ Low-confidence prediction |
這頁最精彩的地方:同一題、兩條知識,得到完全相反的答案。 系統最後採用「信心較高」的那一條(正解是 No——高爾夫球是桿數越少越好,不是分數越高越好)。
考點:① 兩階段名稱(generate knowledge → knowledge-augmented answering); ② 最後用 highest-confidence prediction;③ 這個高爾夫球例子的正解是 No ( Knowledge 1 才是對的,Knowledge 2 是低信心/錯誤的那條)。
31. Program-aided Language Model (PAL)
前面給定義,這裡給示意圖。PAL 的洞見很簡單: 模型不擅長算數,但很擅長寫程式。那就讓它寫程式,把算術外包出去。
31.1 核心概念
| 原文 | 中文 |
|---|---|
| Chain-of-thought prompting is a good example of how to steer models to perform better at complex reasoning tasks | CoT 是引導模型做好複雜推理的好例子 |
| However, sometimes CoT is not enough as it depends only on the generated text from the model | 但有時 CoT 不夠——因為它只依賴模型生成的文字 |
| Program-aided language models (PAL) uses an LLM to read problems and generate programs as the intermediate reasoning steps | PAL 讓 LLM 讀題並產生程式,把程式當成中間推理步驟 |
| It offloads the solution step to a runtime such as Python interpreter | 把求解步驟外包給執行環境(如 Python 直譯器) |
31.2 為什麼 CoT 不夠
CoT 的推理是「用文字算數學」——模型可能在某一步算錯,而且錯了自己不知道。 PAL 把「算」這一步交給 Python 直譯器,模型只負責把題目翻譯成程式。 算錯的機率因此大幅下降。
31.3 流程圖
考點:PAL 的三個關鍵詞——generate programs as intermediate reasoning steps、 offloads the solution step to a runtime、Python interpreter。 它與 CoT 的差別一句話:CoT 用文字推理,PAL 用程式推理(並真的執行)。
32. ReAct
前面給定義,這裡給示意圖。ReAct = Reason + Act: 讓模型一邊推理、一邊動手查,兩者交錯進行。
32.1 核心概念
| 原文 | 中文 |
|---|---|
| ReAct is a framework where LLMs are used to generate both reasoning traces and task-specific actions in an interleaved manner | ReAct 讓 LLM 交錯產生「推理軌跡」與「任務專屬行動」 |
| Generating reasoning traces allow the model to induce, track, and update action plans, and even handle exceptions | 推理軌跡讓模型能歸納、追蹤、更新行動計畫,甚至處理例外 |
| The action step allows to interface with and gather information from external sources such as knowledge bases or environments | 行動步驟讓模型能介接外部來源(知識庫、環境)並取得資訊 |
| ReAct allows LLMs to interact with external tools to retrieve additional information that leads to more reliable and factual responses | ReAct 讓 LLM 與外部工具互動、檢索額外資訊,產生更可靠、更符合事實的回答 |
32.2 與 CoT 的差別(本筆記整理)
| 比較 | CoT | ReAct |
|---|---|---|
| 只做推理 | ✅ | ✅(Reason) |
| 會對外動作 | ❌ | ✅(Act:查知識庫、呼叫 API) |
| 能取得新資訊 | ❌(只用模型內部知識) | ✅(retrieve additional information) |
| 輸出品質 | 可能流暢但過時/幻覺 | more reliable and factual |
32.3 迴圈結構
考點:ReAct 的三個關鍵詞——interleaved(交錯)、reasoning traces + actions、 external tools。它與 CoT 的差別是「會動手查」,與 PAL 的差別是 「PAL 只外包計算;ReAct 會對外檢索與行動」。
33. Tools & IDEs
課程是 Part 3 的開頭。它不講技術,只講生態: 有一大堆工具、函式庫、平台,各自有不同的能力。
33.1 三個重點
| 原文 | 中文 |
|---|---|
| There are many tools, libraries, and platforms with different capabilities and functionalities | 有非常多工具、函式庫與平台,能力與功能各異 |
| Capabilities include: Developing and experimenting with prompts | 能力一:開發與實驗 prompt |
| Evaluating prompts | 能力二:評估 prompt |
| Versioning and deploying prompts | 能力三:版本控制與部署 prompt |
33.2 三個能力對應的三類工具
| 階段 | 你要做的事 | 典型工具型態 |
|---|---|---|
| 開發/實驗 | 試不同 prompt、比較輸出 | Playground、Jupyter notebook、SDK |
| 評估 | 用測試集量化好壞 | Evaluation framework、benchmark、LLM-as-a-judge |
| 版本控制/部署 | 追蹤改了什麼、上線 | Prompt registry、CI/CD、A/B 測試 |
課程最後給了一個延伸清單的網址(github.com/dair-ai/Prompt-Engineering-Guide#tools--libraries)。
考點:三個能力要能全列——develop and experiment/evaluate/version and deploy。 這其實就是 prompt 從「隨手寫」變成「工程化」的三個階段。
34. Applications(外部工具與資料增強生成)
前面給應用總覽,這裡拆解「LLM + 外部工具」的三個必要元件, 課程說明 Data-Augmented Generation 的步驟。這一章是 Part 2 那些技術的落地場景。
34.1 應用總覽
| 原文 | 中文 |
|---|---|
| Advanced prompting techniques are now allowing all sorts of advanced applications with LLMs | 進階提示技術讓各種進階應用成為可能 |
| LLMs and external tools/APIs | 應用一:LLM 搭配外部工具/API |
| Data-augmented Generation | 應用二:資料增強生成 |
| — QA with sources | 附帶來源的問答 |
| — Summarization using sources | 使用來源的摘要 |
34.2 LLMs with External Tools
The generative capabilities of LLMs can be combined with an external tool to solve complex problems.
The components you need(三個必要元件):
| # | 元件 | 原文 | 中文 |
|---|---|---|---|
| 1 | Agent | An agent powered by LLM to determine which actions to take | 由 LLM 驅動、負責決定採取什麼行動的代理人 |
| 2 | Tool | A tool used by the agent to interact with the world(e.g., search API, Wolfram, Python REPL, database lookup) | 代理人用來與世界互動的工具(搜尋 API、Wolfram、Python REPL、資料庫查詢) |
| 3 | LLM | The LLM that will power the agent | 驅動代理人的那個 LLM |
⚠️ 注意課程把 LLM 列為獨立元件(元件 3),與「agent(元件 1)」分開—— 這在考試裡常被當成陷阱:agent 是「決策邏輯」,LLM 是「引擎」,兩者不是同一件事。
34.3 Data-Augmented Generation
For many real-world applications there is a need to augment the generation of a model by incorporating external data.
Steps involved(兩個步驟):
| # | 步驟 | 中文 |
|---|---|---|
| 1 | Fetching relevant data | 取回相關資料 |
| 2 | Augmenting prompts with the retrieved data as context | 把取回的資料當成上下文塞進 prompt |
External data can include(外部資料來源):
| 來源 | 中文 |
|---|---|
| Document stores | 文件庫 |
| APIs | 外部 API |
| Databases | 資料庫 |
| User provided data | 使用者提供的資料 |
| … | 其他 |
考點:① 「LLM + 外部工具」的三個元件(agent/tool/LLM)與各自定義; ② DAG 的兩個步驟(fetch → augment)與四類外部資料來源。 DAG 就是業界常說的 RAG(Retrieval-Augmented Generation)的同義思路: 先檢索、再生成,並可附上來源(QA/summarization with sources)。
35. Opportunities and Future Directions
課程是 Part 4 的目錄頁:列出這一 Part 要討論的四個主題。 這一章很短,但它決定了 Ch. 36–38 的順序。
35.1 這一 Part 要討論的四件事
| # | 主題 | 本筆記對應章節 |
|---|---|---|
| 1 | Model safety | Ch. 36 |
| 2 | Prompt Injection | Ch. 37 |
| 3 | RLHF | Ch. 38 |
| 4 | Future directions | 本章 |
35.2 Future Directions(課程僅列標題)
課程把「Future directions」列為最後一項,但沒有再做展開頁。 全部用來講安全與 RLHF。因此這一項在考試上通常只考「它是這四項之一」。
考點:Part 4 的四個主題與順序(Model safety → Prompt Injection → RLHF → Future directions)。注意課程把 RLHF 放在安全主題群組裡,而不是放在「訓練技術」裡—— 這是編排邏輯,要照它記。
36. Model Safety
說明:prompt engineering 不只是用來提升效能,也用來提升可靠性與安全性。
36.1 三個重點
| 原文 | 中文 |
|---|---|
| Prompt engineering can be used not only to improve performance but also the reliability of response from a safety perspective | Prompt engineering 不只提升效能,也提升安全面向的回應可靠性 |
| Prompt engineering can help identify risky behaviours of LLMs, which can help to reduce harmful behaviours and risks that may arise from language models | 它能幫我們找出 LLM 的風險行為,進而降低有害行為與風險 |
| There is also a part of the community performing prompt injection to understand the vulnerability of LLMs | 社群中有一群人主動做 prompt injection,以了解 LLM 的弱點 |
36.2 「攻防兩用」的觀點
第 3 點是本頁最關鍵的觀念轉折:prompt injection 在研究上不是純粹的壞事——
它是紅隊(red teaming)手段,用來找出模型弱點,再回頭修補。
這正好呼應 Chapter 3 的第二個理由(test and evaluate the limitations of LLMs)。
考點:本頁的三點要能全列。特別注意第 2 點的關鍵字是 identify risky behaviours 與 reduce harmful behaviours——prompt engineering 在此的角色是風險探測器。
37. Prompt Injection 三大攻擊
這幾節是同一主題的五頁:先總覽三種常見問題, 再各用一頁說明。 本筆記合併成這一章。
37.1 總覽
| 原文 | 中文 |
|---|---|
| It turns out that building with LLMs, like any other systems, comes with challenges that includes safety considerations. | 用 LLM 打造系統,跟其他系統一樣,會有安全考量的挑戰 |
| Prompt injections aim to find vulnerabilities in LLMs | Prompt injection 的目的在於找出 LLM 的弱點 |
Some common issues include(三種常見問題):
| # | 問題 | 本質 |
|---|---|---|
| 1 | Prompt Injection | 劫持輸出 |
| 2 | Prompt Leaking | 洩漏 prompt |
| 3 | Jailbreaking | 繞過安全機制 |
37.2 Prompt Injection
Prompt injection is used to hijack an LM's output by injecting an untrusted command that overrides instruction of a prompt.
| 關鍵字 | 中文 |
|---|---|
| hijack an LM's output | 劫持模型輸出 |
| untrusted command | 不可信的指令 |
| overrides instruction | 覆蓋原本的指令 |
成因說明(最重要的一句):
This could easily happen if you just concatenate your prompt with another user generated prompt.
也就是說:只要你把「自己的 prompt」和「使用者輸入」直接串接,就可能被注入。 這正是為什麼實務上要把 system prompt 與 user input 分開處理(用角色分層、加分隔符、做輸入檢查)。
37.3 Prompt Leaking
Prompt leaking aims to force the model to spit out information about its own prompt.
| 關鍵字 | 中文 |
|---|---|
| force the model to spit out | 逼模型吐出 |
| information about its own prompt | 關於它自己 prompt 的資訊 |
| leads to leaking of sensitive, private or confidential information | 導致敏感、私人或機密資訊外洩 |
為什麼嚴重:企業的 system prompt 常包含內部規則、商業邏輯、甚至 API key 佔位; 一旦洩漏,等於把系統設計圖交出去。
37.4 Jailbreaking
Jailbreaking is another form of prompt injection where the goal is to bypass safety and moderation features.
| 原文 | 中文 |
|---|---|
| LLMs provided via APIs might be coupled with safety features or content moderation which can be bypassed with harmful prompts/attacks | API 版 LLM 通常帶有安全功能或內容審核,但可被有害的 prompt/攻擊繞過 |
| This might sound like a difficult task but it's not, because the model is usually served static | 聽起來很難,但其實不難——因為模型通常是靜態部署的 |
| …and might have these vulnerabilities due to many factors such as the data it was trained on | 弱點可能來自訓練資料等諸多因素 |
「served static」是關鍵:模型上線後不會自己更新防禦,所以同一個攻擊手法可以重複使用。
37.5 Jailbreaking examples
三者的辨別方式如下(這是考試最可能出的比較題):
| 攻擊 | 目標 | 一句話辨別 |
|---|---|---|
| Prompt Injection | 劫持輸出 | 「你原本的指令被覆蓋了」 |
| Prompt Leaking | 洩漏 prompt | 「你的系統提示被吐出來了」 |
| Jailbreaking | 繞過安全 | 「你的安全規則被繞過了」 |
考點:① 三種問題的名稱與定義要能配對;② Prompt Injection 的成因句 (
concatenate your prompt with another user generated prompt); ③ Jailbreaking 是 another form of prompt injection(課程明確這樣歸類); ④ served static 是它難以根治的原因。
38. RLHF
課程是全份最後一頁,講 Reinforcement Learning from Human Feedback。
38.1 課程內容
| 原文 | 中文 |
|---|---|
| Reinforcement Learning from Human Feedback (RLHF) is now being used to train LLMs that fit human preference | RLHF 現在被用來訓練貼近人類偏好的 LLM |
| RLHF involves collecting high-quality prompt datasets | RLHF 需要收集高品質的 prompt 資料集 |
Popular examples(課程舉的兩個例子):
| 產品 | 公司 |
|---|---|
| Claude | Anthropic |
| ChatGPT | OpenAI |
課程引用的來源是 OpenAI 的 ChatGPT: Optimizing Language Models for Dialogue。
38.2 三個關鍵字(本筆記整理)
| 縮寫 | 全稱 | 中文 |
|---|---|---|
| RL | Reinforcement Learning | 強化學習(用獎勵訊號調整行為) |
| HF | Human Feedback | 人類回饋(人類排序/評分當獎勵) |
| 目的 | fit human preference | 讓輸出符合人類偏好 |
38.3 為什麼 RLHF 放在「安全」這一 Part
回看 Chapter 35:課程把 RLHF 列在 Model safety / Prompt Injection / RLHF / Future directions 這一組裡。原因是 RLHF 是「把人類偏好寫進模型」的主要手段—— 它與 CAI(Ch. 24)一樣,都是「對齊(alignment)」的工具: CAI 用明文原則在推論時約束,RLHF 用訓練把偏好內化。
考點:① RLHF 的全稱(Reinforcement Learning from Human Feedback)與目的 (fit human preference);② 需要收集高品質 prompt 資料集; ③ 兩個代表產品 Claude(Anthropic)/ChatGPT(OpenAI); ④ 它與 CAI 的差別(RLHF 訓練時內化偏好;CAI 推論時依規則自我約束)。
附錄 A:Prompt 元素與參數速查表
A.1 Prompt 的組成
| 名詞 | 英文 | 一句話說明 |
|---|---|---|
| 提示 | Prompt | 為了達成任務,傳給語言模型的指令與上下文 |
| 提示工程 | Prompt engineering | 開發並最佳化 prompt 的實務 |
| 指令 | Instructions | 你要模型做什麼 |
| 上下文 | Context | 背景資訊,讓答案切題 |
| 輸入資料 | Input data | 要被處理的內容 |
| 輸出指示 | Output indicator | 指定輸出格式/標籤集合 |
| 系統提示 | System prompt | 常駐的操作規則層(影響之後所有回答) |
| 角色 | Role | 指派的身分(teacher/PM/architect…) |
A.2 解碼參數
| 參數 | 作用 | 精確答案 | 多樣回應 |
|---|---|---|---|
temperature |
縮放機率分佈 | 調低(0–0.3) | 調高(0.8–1.2) |
top_p |
nucleus sampling 的累積機率門檻 | 調低 | 調高(1 = 全部候選) |
A.3 38 種技術一句話速查
| 章 | 技術 | 一句話 |
|---|---|---|
| 9 | Zero-Shot | 不給範例,直接做 |
| 10 | Few-Shot(In-Context Learning) | 先給 input→output 範例 |
| 11 | Clear Instructions | Task/Format/Length/Tone/Constraints/Context |
| 12 | System Prompting | 常駐規則層(core operating rules) |
| 13 | Role Prompting | 指派身分,改變 tone/vocabulary/decision criteria |
| 14 | Contextual Prompting | 補受眾、環境、限制等背景 |
| 15 | Markdown Prompting | 用標題/條列/表格規定結構 |
| 16 | CoT | think step by step |
| 17 | TCoT | 把推理排進表格 |
| 18 | SoT | 先 3–10 點骨架,再展開 |
| 19 | Step-Back | 先想通則,再解原題 |
| 20 | Least-to-Most | 拆子問題,由易到難 |
| 21 | ToT | 平行分支 → 評估 → 走最強 |
| 22 | iToT | ToT + 每輪回饋修正 |
| 23 | SG-ICL | 模型自己生範例 |
| 24 | CAI | 用明文原則約束回答 |
| 25 | Perspective-Taking | 多個利害關係人視角 |
| 26 | Analogical | 用類比當橋樑,再接回技術 |
| 27 | Multi-Modal | 文字+圖/文件/音訊/影片 |
| 28 | Persona Consistency | 跨輸出維持同一人格(防 drift) |
| 29 | Predictive | 預測後果與風險 |
| 30 | Generate Knowledge | 先生成知識,再答題,取最高信心 |
| 31 | PAL | 產程式,外包給 Python 執行 |
| 32 | ReAct | 推理+行動交錯,可呼叫外部工具 |
| 33 | Tools & IDEs | develop/evaluate/version & deploy |
| 34 | Applications | LLM + 外部工具、Data-Augmented Generation |
A.4 必背數字與字串
| 項目 | 值 |
|---|---|
| 第一個示範的模型 | text-davinci-003 |
| 第一個示範的參數 | temperature 0.7、top-p 1 |
| SoT 骨架點數 | 3 到 10 點 |
| 六大任務 | Summarization/QA/Classification/Role Playing/Code Generation/Reasoning |
| 七大技術類別 | Foundational/Context & Role-Based/Reasoning & Planning/Advanced Orchestration & Control/Style, Tone & Persona/Iterative Improvement & Refinement/Specialized & Cutting-Edge |
| 三大安全問題 | Prompt Injection/Prompt Leaking/Jailbreaking |
| RLHF 代表產品 | Claude(Anthropic)、ChatGPT(OpenAI) |
| CAI 示範原則數 | 5 條 |
| CoT 觸發語 | think step by step/work through this carefully/reason through this before answering |
A.5 常用指令
# 本筆記的 HTML 為單檔離線頁面,無需安裝任何套件即可閱讀
# 若要自行實驗 prompt,最簡單的方式是使用任何支援 chat/completion 的 SDK
pip install openai # 或其他供應商的 SDK
附錄 B:常見錯誤與陷阱
B.1 十大陷阱總表
| # | 陷阱 | 錯誤想法 | 正確想法 |
|---|---|---|---|
| 1 | 把 prompt 與 prompt engineering 混為一談 | 「prompt 就是 prompt engineering」 | prompt 是名詞(送出的內容);prompt engineering 是動詞(優化過程) |
| 2 | 以為四要素每題都會齊 | 「prompt 一定有 context」 | 的分類例子沒有 context |
| 3 | 參數方向記反 | 「要精確 → temperature 調高」 | 精確 → 調低;多樣 → 調高 |
| 4 | 以為 few-shot 會改權重 | 「few-shot 會微調模型」 | 是 in-context learning,不改權重 |
| 5 | 混淆 system 與 role | 「system prompting 就是給角色」 | system 管規則與界線;role 管身分與視角 |
| 6 | 混淆 CoT 與 ToT | 「ToT 就是步驟更多的 CoT」 | ToT 多了分支探索與回溯(search / backtracking) |
| 7 | 混淆 ToT 與 iToT | 「iToT 只是 ToT 的別名」 | iToT 多了每輪回饋迭代,弱分支會被修訂或替換 |
| 8 | 混淆 Step-Back 與 Least-to-Most | 「兩個都是拆解問題」 | Step-Back 往上抽象成原則;Least-to-Most 往下拆成子問題 |
| 9 | 以為 PAL 會自己算對 | 「PAL 讓模型算數學」 | PAL 是產程式、外包給 Python 執行,不是模型自己算 |
| 10 | 把三種攻擊混在一起 | 「jailbreaking 就是 prompt leaking」 | Injection 劫持輸出/Leaking 吐出 prompt/Jailbreaking 繞過安全 |
B.2 易混淆技術對照
| 常被混淆的一對 | 關鍵差別 |
|---|---|
| CoT ↔ Least-to-Most | CoT 對同一題逐步推理;Least-to-Most 拆成多個子問題 |
| CoT ↔ TCoT | TCoT 把推理排進表格(step/action/evidence/result) |
| CoT ↔ SoT | CoT 是一條鏈;SoT 是先骨架、後展開 |
| CoT ↔ PAL | PAL 把求解外包給 runtime(Python 直譯器) |
| CoT ↔ ReAct | ReAct 會對外檢索與行動(external tools) |
| Role ↔ Persona Consistency | Role 是單次指派;Persona 是跨多次維持不變 |
| CAI ↔ RLHF | CAI 在推論時依規則約束;RLHF 在訓練時內化偏好 |
| Prompt Injection ↔ Jailbreaking | Jailbreaking 是 injection 的一種,目標是繞過安全與審核 |
附錄 C:離線執行/安裝提示
C.1 這份筆記本身
- 本頁是單一 HTML 檔:CSS、語法高亮、插圖(base64)全部內嵌, 零外部資源,下載後雙擊即可離線閱讀,不需要網路。
- 原始 Markdown 也在同一資料夾,方便你自行修改或再轉檔。
C.2 想自己動手試 prompt
本筆記的內容都是「方法論」,不需要安裝任何套件就能讀完。若要實作:
| 目的 | 需要什麼 |
|---|---|
| 呼叫雲端模型 | 任一供應商的 SDK(例如 pip install openai)+ API key |
| 本機跑開源模型 | Ollama/llama.cpp/vLLM 等推論框架 + 足夠的 GPU 記憶體 |
| 多供應商統一介面 | LiteLLM(本課程 Lesson 8 的主題) |
| 建聊天介面 | Streamlit 或 Flask(本課程 Lesson 9 的主題) |
C.3 沒有網路時怎麼複習
| 做法 | 說明 |
|---|---|
| 把本頁存成 PDF | 瀏覽器列印 → 存成 PDF(版面已為列印最佳化) |
| 用附錄 D | 考前 10 分鐘只需要看附錄 D 的一頁精華 |
| 用附錄 A | 需要查「某個技術的一句話定義」時查附錄 A.3 |
| 用附錄 B | 複習時最有效的是 B.2 的「易混淆技術對照」 |
C.4 驗證本頁確實可離線使用
在瀏覽器開發者工具的 Network 面板重新載入本頁,應該看到 0 個外部請求
(只有這一份 HTML 本身)。插圖是 data:image/jpeg;base64,...,不會發出請求。
附錄 D:一頁精華(考前 10 分鐘)
========== 1. 三個定義 ==========
Prompt = instructions + context,為了達成任務而送給語言模型的東西
Prompt engineering= 開發並最佳化 prompt,以有效率地使用 LM
Elements of a Prompt = Instructions / Context / Input data / Output indicator
========== 2. 兩顆參數旋鈕 ==========
temperature:低=精確、可重現 高=多樣、有創意
top_p :低=候選集合小 高=候選集合大(1 = 全部)
========== 3. 七大類技術(依序)==========
① Foundational → Zero-Shot / Few-Shot / Clear Instructions
② Context & Role-Based → System / Role / Contextual / Markdown
③ Reasoning & Planning → CoT / TCoT / SoT / Step-Back
④ Advanced Orchestration → Least-to-Most / ToT / iToT / SG-ICL
(+ Generate Knowledge / PAL / ReAct)
⑤ Style, Tone & Persona → Persona Consistency
⑥ Iterative Improvement → iToT(迭代精煉)
⑦ Specialized & Cutting-Edge → CAI / Perspective-Taking / Analogical /
Multi-Modal / Persona / Predictive
========== 4. 推理類技術一句話分辨 ==========
CoT :同一題,一步步推
TCoT :同 CoT,但排成表格(step/action/evidence/result)
SoT :先給 3–10 點骨架,再逐點展開
Step-Back :先往「上」抽通則,再回來解原題
Least-to-Most:往「下」拆子問題,由易到難
ToT :平行長多條分支 → 評估 → 只走最強(有 search/backtracking)
iToT :ToT + 每輪回饋迭代修正
PAL :產程式,把計算外包給 Python 直譯器
ReAct :Thought → Action → Observation 迴圈,可呼叫外部工具
========== 5. 應用與安全 ==========
LLM + 外部工具三元件:Agent(決策)/Tool(互動世界)/LLM(引擎)
Data-Augmented Generation:① Fetching relevant data → ② Augmenting prompts
資料來源:Document stores / APIs / Databases / User data
三大攻擊:Prompt Injection(劫持輸出)/Prompt Leaking(吐出 prompt)/
Jailbreaking(繞過安全,是 injection 的一種;模型 served static 所以難防)
RLHF:Reinforcement Learning from Human Feedback → fit human preference
代表:Claude(Anthropic)/ChatGPT(OpenAI)
附錄 E:互動式線上測驗(60 題)
60 題單選、滿分 60 分、建議 75 分鐘。 測驗以互動網頁形式提供(點選即時計分、進度自動儲存);本筆記不重複收錄題目。
E.1 開始測驗
線上版功能:
- 點選答案即自動計分,並即時顯示得分
- 作答進度自動存在你的瀏覽器(localStorage)——關掉網頁、隔天再開都能繼續
- 可切換「只顯示未答」或「只顯示答錯」的題目,快速複習
- 按「顯示答案」才揭曉正解與解析,不會一開始就被暴雷
- 需要紙本時,直接在該頁按列印即可
E.2 時間分配建議
| 階段 | 時間 | 做什麼 |
|---|---|---|
| 第一輪 | 0–40 分鐘 | 快速作答有把握的題目,不確定先標記跳過 |
| 第二輪 | 40–65 分鐘 | 回頭處理標記的難題 |
| 第三輪 | 65–75 分鐘 | 檢查有沒有漏答 |
E.3 評分參考
| 分數 | 程度 | 建議 |
|---|---|---|
| 54–60 | 優異 | 直接看附錄 D 一頁精華即可上場 |
| 45–53 | 良好 | 複習錯題所屬章節 |
| 36–44 | 及格邊緣 | 重讀主要章節 + 附錄 A |
| 0–35 | 需加強 | 整份筆記重讀一遍,再重做本卷 |
答錯的題目請對照下方〈附錄 F:互動測驗答錯題目 → 複習章節對照〉回到對應章節複習。
附錄 F:互動測驗答錯題目 → 複習章節對照
| 答錯題號 | 建議複習章節 |
|---|---|
| 1–4 | §1–§2 Prerequisites & Objectives、What are prompts? |
| 5–8 | §3–§4 Why Prompt Engineering?、First Basic Prompt |
| 9–12 | §5–§6 Elements of a Prompt、temperature 與 top_p |
| 13–17 | §7 六大任務(Summarization/QA/Classification/Role Playing/Code/Reasoning) |
| 18–20 | §8 七大類技術地圖 |
| 21–24 | §9–§11 Zero-Shot/Few-Shot/Clear Instructions |
| 25–29 | §12–§15 System/Role/Contextual/Markdown Prompting |
| 30–34 | §16–§18 CoT/TCoT/SoT |
| 35–38 | §19–§20 Step-Back/Least-to-Most |
| 39–42 | §21–§23 ToT/iToT/SG-ICL |
| 43–46 | §24–§26 CAI/Perspective-Taking/Analogical |
| 47–49 | §27–§29 Multi-Modal/Persona Consistency/Predictive |
| 50–53 | §30–§32 Generate Knowledge/PAL/ReAct |
| 54–56 | §33–§34 Tools & IDEs/Applications(外部工具、DAG) |
| 57–58 | §35–§36 Future Directions/Model Safety |
| 59–60 | §37–§38 Prompt Injection 三大攻擊/RLHF |
本篇為個人學習筆記整理。