<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Prompting on Tarragon</title><link>https://tarrragon.github.io/blog/tags/prompting/</link><description>Recent content in Prompting on Tarragon</description><generator>Hugo -- gohugo.io</generator><language>zh-TW</language><copyright>Tarragon (CC BY 4.0)</copyright><lastBuildDate>Thu, 14 May 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://tarrragon.github.io/blog/tags/prompting/index.xml" rel="self" type="application/rss+xml"/><item><title>Few-shot prompting</title><link>https://tarrragon.github.io/blog/llm/knowledge-cards/few-shot-prompting/</link><pubDate>Thu, 14 May 2026 00:00:00 +0000</pubDate><guid>https://tarrragon.github.io/blog/llm/knowledge-cards/few-shot-prompting/</guid><description>&lt;p>Few-shot prompting 的核心概念是「&lt;strong>在 prompt 內塞幾個 input-output 範例、讓模型透過範例對齊任務&lt;/strong>」。Zero-shot 是不給範例直接給任務、few-shot 是給 1-N 個範例、模型從範例推任務分佈。屬於 in-context learning 的最常見形態、是「對齊任務」這件事的 prompt 層解法、跟 fine-tune 是兩個 endpoint。&lt;/p>
&lt;h2 id="概念位置">概念位置&lt;/h2>
&lt;p>Zero-shot vs few-shot 對照：&lt;/p>





&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-text" data-lang="text">&lt;span class="line">&lt;span class="ln"> 1&lt;/span>&lt;span class="cl">Zero-shot：
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="ln"> 2&lt;/span>&lt;span class="cl"> Classify the tone as positive/negative/neutral.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="ln"> 3&lt;/span>&lt;span class="cl"> Review: &amp;#34;Fine, but I expected more.&amp;#34;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="ln"> 4&lt;/span>&lt;span class="cl"> → 模型自己判斷「中性」邊界
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="ln"> 5&lt;/span>&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="ln"> 6&lt;/span>&lt;span class="cl">Few-shot：
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="ln"> 7&lt;/span>&lt;span class="cl"> Classify the tone as positive/negative/neutral.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="ln"> 8&lt;/span>&lt;span class="cl"> Examples:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="ln"> 9&lt;/span>&lt;span class="cl"> &amp;#34;Exceeded my expectations&amp;#34; → positive
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="ln">10&lt;/span>&lt;span class="cl"> &amp;#34;OK, but I wish more features&amp;#34; → negative
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="ln">11&lt;/span>&lt;span class="cl"> &amp;#34;Service was adequate&amp;#34; → neutral
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="ln">12&lt;/span>&lt;span class="cl"> Review: &amp;#34;Fine, but I expected more.&amp;#34;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="ln">13&lt;/span>&lt;span class="cl"> → 模型按範例對齊、更傾向 negative&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Few-shot 跟 fine-tune 對照：&lt;/p>
&lt;table>
 &lt;thead>
 &lt;tr>
 &lt;th>維度&lt;/th>
 &lt;th>Few-shot in prompt&lt;/th>
 &lt;th>Fine-tune&lt;/th>
 &lt;/tr>
 &lt;/thead>
 &lt;tbody>
 &lt;tr>
 &lt;td>Iteration&lt;/td>
 &lt;td>分鐘級、改 prompt 即可&lt;/td>
 &lt;td>天級、要 retrain&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td>範例容量&lt;/td>
 &lt;td>受 context window 限制（10–50）&lt;/td>
 &lt;td>可以幾千幾萬、整個 dataset 都行&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td>Cost&lt;/td>
 &lt;td>每次 inference 多付 token&lt;/td>
 &lt;td>一次性訓練 cost、之後 inference 不變&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td>模型遷移&lt;/td>
 &lt;td>跨模型即時換、prompt 直接搬&lt;/td>
 &lt;td>綁特定 base model、換模型要 retrain&lt;/td>
 &lt;/tr>
 &lt;/tbody>
&lt;/table>
&lt;h2 id="設計責任">設計責任&lt;/h2>
&lt;p>讀 prompt engineering 文章或寫 production prompt 看到「few-shot」「in-context examples」就是這個機制。實作判讀：&lt;/p>
&lt;ol>
&lt;li>&lt;strong>適用任務有「我的標準跟模型預設不同」&lt;/strong>：分類邊界、抽取格式、tone alignment、structured output 形狀。&lt;/li>
&lt;li>&lt;strong>失效在範例選不好&lt;/strong>：cherry-picked 不代表 distribution、cover 不到 edge case、範例彼此衝突。&lt;/li>
&lt;li>&lt;strong>跟 &lt;a href="https://tarrragon.github.io/blog/llm/knowledge-cards/chain-of-thought/" data-link-title="Chain-of-Thought（CoT）" data-link-desc="讓 LLM 先輸出推理步驟再給最終答案的 prompting / 訓練方式、reasoning model 的基礎機制">chain-of-thought&lt;/a> 可疊&lt;/strong>（few-shot CoT 是經典組合）、跟 fine-tune 是 endpoint 取捨。&lt;/li>
&lt;li>&lt;strong>何時轉 fine-tune&lt;/strong>：範例多到撐爆 &lt;a href="https://tarrragon.github.io/blog/llm/knowledge-cards/context-window/" data-link-title="Context Window" data-link-desc="模型一次能處理的最大 token 數量：prompt 加生成的總和上限">context window&lt;/a> 又每天都用、才考慮。預設先 few-shot iterate。&lt;/li>
&lt;li>&lt;strong>Retrieval-augmented prompting&lt;/strong>：把寫死的 few-shot 換成從範例庫即時 retrieve、屬於 &lt;a href="https://tarrragon.github.io/blog/llm/knowledge-cards/rag/" data-link-title="RAG" data-link-desc="Retrieval-Augmented Generation：動態外掛知識給 LLM、繞開模型參數記憶的靜態限制">RAG&lt;/a> 概念延伸。&lt;/li>
&lt;/ol>
&lt;p>完整 prompt 技術 landscape 見 &lt;a href="https://tarrragon.github.io/blog/llm/04-applications/prompt-techniques-landscape/" data-link-title="4.0 Prompt 技術光譜：手法分類、取捨、組合模式" data-link-desc="Zero-shot / few-shot、chain-of-thought、role / template、reflection 等 prompt 技術的分類與取捨、何時 stack 何時不要 stack、跟 fine-tune / RAG / chaining 的邊界">4.0 Prompt 技術光譜&lt;/a>。&lt;/p></description><content:encoded><![CDATA[<p>Few-shot prompting 的核心概念是「<strong>在 prompt 內塞幾個 input-output 範例、讓模型透過範例對齊任務</strong>」。Zero-shot 是不給範例直接給任務、few-shot 是給 1-N 個範例、模型從範例推任務分佈。屬於 in-context learning 的最常見形態、是「對齊任務」這件事的 prompt 層解法、跟 fine-tune 是兩個 endpoint。</p>
<h2 id="概念位置">概念位置</h2>
<p>Zero-shot vs few-shot 對照：</p>





<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="ln"> 1</span><span class="cl">Zero-shot：
</span></span><span class="line"><span class="ln"> 2</span><span class="cl">  Classify the tone as positive/negative/neutral.
</span></span><span class="line"><span class="ln"> 3</span><span class="cl">  Review: &#34;Fine, but I expected more.&#34;
</span></span><span class="line"><span class="ln"> 4</span><span class="cl">  → 模型自己判斷「中性」邊界
</span></span><span class="line"><span class="ln"> 5</span><span class="cl">
</span></span><span class="line"><span class="ln"> 6</span><span class="cl">Few-shot：
</span></span><span class="line"><span class="ln"> 7</span><span class="cl">  Classify the tone as positive/negative/neutral.
</span></span><span class="line"><span class="ln"> 8</span><span class="cl">  Examples:
</span></span><span class="line"><span class="ln"> 9</span><span class="cl">    &#34;Exceeded my expectations&#34; → positive
</span></span><span class="line"><span class="ln">10</span><span class="cl">    &#34;OK, but I wish more features&#34; → negative
</span></span><span class="line"><span class="ln">11</span><span class="cl">    &#34;Service was adequate&#34; → neutral
</span></span><span class="line"><span class="ln">12</span><span class="cl">  Review: &#34;Fine, but I expected more.&#34;
</span></span><span class="line"><span class="ln">13</span><span class="cl">  → 模型按範例對齊、更傾向 negative</span></span></code></pre></div><p>Few-shot 跟 fine-tune 對照：</p>
<table>
  <thead>
      <tr>
          <th>維度</th>
          <th>Few-shot in prompt</th>
          <th>Fine-tune</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>Iteration</td>
          <td>分鐘級、改 prompt 即可</td>
          <td>天級、要 retrain</td>
      </tr>
      <tr>
          <td>範例容量</td>
          <td>受 context window 限制（10–50）</td>
          <td>可以幾千幾萬、整個 dataset 都行</td>
      </tr>
      <tr>
          <td>Cost</td>
          <td>每次 inference 多付 token</td>
          <td>一次性訓練 cost、之後 inference 不變</td>
      </tr>
      <tr>
          <td>模型遷移</td>
          <td>跨模型即時換、prompt 直接搬</td>
          <td>綁特定 base model、換模型要 retrain</td>
      </tr>
  </tbody>
</table>
<h2 id="設計責任">設計責任</h2>
<p>讀 prompt engineering 文章或寫 production prompt 看到「few-shot」「in-context examples」就是這個機制。實作判讀：</p>
<ol>
<li><strong>適用任務有「我的標準跟模型預設不同」</strong>：分類邊界、抽取格式、tone alignment、structured output 形狀。</li>
<li><strong>失效在範例選不好</strong>：cherry-picked 不代表 distribution、cover 不到 edge case、範例彼此衝突。</li>
<li><strong>跟 <a href="/blog/llm/knowledge-cards/chain-of-thought/" data-link-title="Chain-of-Thought（CoT）" data-link-desc="讓 LLM 先輸出推理步驟再給最終答案的 prompting / 訓練方式、reasoning model 的基礎機制">chain-of-thought</a> 可疊</strong>（few-shot CoT 是經典組合）、跟 fine-tune 是 endpoint 取捨。</li>
<li><strong>何時轉 fine-tune</strong>：範例多到撐爆 <a href="/blog/llm/knowledge-cards/context-window/" data-link-title="Context Window" data-link-desc="模型一次能處理的最大 token 數量：prompt 加生成的總和上限">context window</a> 又每天都用、才考慮。預設先 few-shot iterate。</li>
<li><strong>Retrieval-augmented prompting</strong>：把寫死的 few-shot 換成從範例庫即時 retrieve、屬於 <a href="/blog/llm/knowledge-cards/rag/" data-link-title="RAG" data-link-desc="Retrieval-Augmented Generation：動態外掛知識給 LLM、繞開模型參數記憶的靜態限制">RAG</a> 概念延伸。</li>
</ol>
<p>完整 prompt 技術 landscape 見 <a href="/blog/llm/04-applications/prompt-techniques-landscape/" data-link-title="4.0 Prompt 技術光譜：手法分類、取捨、組合模式" data-link-desc="Zero-shot / few-shot、chain-of-thought、role / template、reflection 等 prompt 技術的分類與取捨、何時 stack 何時不要 stack、跟 fine-tune / RAG / chaining 的邊界">4.0 Prompt 技術光譜</a>。</p>
]]></content:encoded></item><item><title>In-Context Learning</title><link>https://tarrragon.github.io/blog/llm/knowledge-cards/in-context-learning/</link><pubDate>Thu, 14 May 2026 00:00:00 +0000</pubDate><guid>https://tarrragon.github.io/blog/llm/knowledge-cards/in-context-learning/</guid><description>&lt;p>In-context learning（ICL）的核心概念是「&lt;strong>模型在不更新權重的情況下，從 &lt;a href="https://tarrragon.github.io/blog/llm/knowledge-cards/context-window/" data-link-title="Context Window" data-link-desc="模型一次能處理的最大 token 數量：prompt 加生成的總和上限">context window&lt;/a> 內資訊臨時學會任務格式與判準&lt;/strong>」。它是 LLM 跟傳統模型最不同的能力之一：任務規則可以放在 context 裡，而不是一定要 fine-tune 進權重。&lt;/p>
&lt;h2 id="概念位置">概念位置&lt;/h2>
&lt;p>ICL 是推論時行為，不是訓練流程。&lt;a href="https://tarrragon.github.io/blog/llm/knowledge-cards/few-shot-prompting/" data-link-title="Few-shot prompting" data-link-desc="在 prompt 內塞 input-output 範例對齊任務、不動模型權重的 in-context learning 技術">Few-shot prompting&lt;/a> 是 ICL 最常見的操作方式；SFT、LoRA、QLoRA 則是修改權重的訓練或微調方式。&lt;/p>
&lt;h2 id="可觀察訊號與例子">可觀察訊號與例子&lt;/h2>
&lt;p>給模型三個分類範例後，第四個樣本就按同一標準分類，這是 ICL。把專案命名規則、輸出格式、review rubric 放進 prompt，模型在當次回合遵守，也屬於 ICL。&lt;/p>
&lt;h2 id="設計責任">設計責任&lt;/h2>
&lt;p>ICL 適合快速迭代與少量範例；當範例多到吃滿 &lt;a href="https://tarrragon.github.io/blog/llm/knowledge-cards/context-window/" data-link-title="Context Window" data-link-desc="模型一次能處理的最大 token 數量：prompt 加生成的總和上限">context window&lt;/a>、每天重複使用且標準穩定時，再考慮 fine-tune。需要穩定輸出格式時，ICL 應搭配 &lt;a href="https://tarrragon.github.io/blog/llm/knowledge-cards/structured-output/" data-link-title="Structured Output" data-link-desc="讓 LLM 輸出可被 parser 穩定消費的推論階段設計：JSON mode、schema-guided decoding、grammar 約束都屬於這一層">structured output&lt;/a> 或 validator。&lt;/p></description><content:encoded><![CDATA[<p>In-context learning（ICL）的核心概念是「<strong>模型在不更新權重的情況下，從 <a href="/blog/llm/knowledge-cards/context-window/" data-link-title="Context Window" data-link-desc="模型一次能處理的最大 token 數量：prompt 加生成的總和上限">context window</a> 內資訊臨時學會任務格式與判準</strong>」。它是 LLM 跟傳統模型最不同的能力之一：任務規則可以放在 context 裡，而不是一定要 fine-tune 進權重。</p>
<h2 id="概念位置">概念位置</h2>
<p>ICL 是推論時行為，不是訓練流程。<a href="/blog/llm/knowledge-cards/few-shot-prompting/" data-link-title="Few-shot prompting" data-link-desc="在 prompt 內塞 input-output 範例對齊任務、不動模型權重的 in-context learning 技術">Few-shot prompting</a> 是 ICL 最常見的操作方式；SFT、LoRA、QLoRA 則是修改權重的訓練或微調方式。</p>
<h2 id="可觀察訊號與例子">可觀察訊號與例子</h2>
<p>給模型三個分類範例後，第四個樣本就按同一標準分類，這是 ICL。把專案命名規則、輸出格式、review rubric 放進 prompt，模型在當次回合遵守，也屬於 ICL。</p>
<h2 id="設計責任">設計責任</h2>
<p>ICL 適合快速迭代與少量範例；當範例多到吃滿 <a href="/blog/llm/knowledge-cards/context-window/" data-link-title="Context Window" data-link-desc="模型一次能處理的最大 token 數量：prompt 加生成的總和上限">context window</a>、每天重複使用且標準穩定時，再考慮 fine-tune。需要穩定輸出格式時，ICL 應搭配 <a href="/blog/llm/knowledge-cards/structured-output/" data-link-title="Structured Output" data-link-desc="讓 LLM 輸出可被 parser 穩定消費的推論階段設計：JSON mode、schema-guided decoding、grammar 約束都屬於這一層">structured output</a> 或 validator。</p>
]]></content:encoded></item><item><title>Instruction Following</title><link>https://tarrragon.github.io/blog/llm/knowledge-cards/instruction-following/</link><pubDate>Thu, 14 May 2026 00:00:00 +0000</pubDate><guid>https://tarrragon.github.io/blog/llm/knowledge-cards/instruction-following/</guid><description>&lt;p>Instruction following 的核心概念是「&lt;strong>模型能否遵守使用者或系統給定的任務約束&lt;/strong>」。它關注模型是否照格式輸出、是否留在任務範圍、是否遵守長度與禁止事項，跟 &lt;a href="https://tarrragon.github.io/blog/llm/knowledge-cards/instruction-tuned/" data-link-title="Instruction-Tuned Model" data-link-desc="經過指令微調的模型：會跟著 prompt 走、回答使用者問題">instruction-tuned model&lt;/a> 這種訓練後模型類型相關，但不是同一件事。&lt;/p>
&lt;h2 id="概念位置">概念位置&lt;/h2>
&lt;p>&lt;a href="https://tarrragon.github.io/blog/llm/knowledge-cards/instruction-tuned/" data-link-title="Instruction-Tuned Model" data-link-desc="經過指令微調的模型：會跟著 prompt 走、回答使用者問題">Instruction-tuned model&lt;/a> 是訓練狀態，instruction following 是行為表現。模型可能經過 SFT，仍在細格式、邊界條件或多約束任務上失敗；也可能在簡單指令上表現穩定，但遇到衝突指令或長 prompt 漏掉限制。&lt;/p>
&lt;h2 id="可觀察訊號與例子">可觀察訊號與例子&lt;/h2>
&lt;p>測試訊號包含：是否輸出指定 JSON、是否只回答要求的欄位、是否避免多餘解釋、是否在資料不足時說不知道、是否遵守「不要呼叫工具」或「只讀不寫」。本地小模型常在簡單問答可用，但在多條格式限制同時存在時掉分。&lt;/p>
&lt;h2 id="設計責任">設計責任&lt;/h2>
&lt;p>評估 instruction following 時要做 coverage 測試：格式、長度、拒答、資料不足、衝突指令、跨語言指令都要看。失敗時優先用更清楚的 prompt、few-shot、structured output 或 validator 兜底；長期穩定需求才考慮 fine-tune。&lt;/p></description><content:encoded><![CDATA[<p>Instruction following 的核心概念是「<strong>模型能否遵守使用者或系統給定的任務約束</strong>」。它關注模型是否照格式輸出、是否留在任務範圍、是否遵守長度與禁止事項，跟 <a href="/blog/llm/knowledge-cards/instruction-tuned/" data-link-title="Instruction-Tuned Model" data-link-desc="經過指令微調的模型：會跟著 prompt 走、回答使用者問題">instruction-tuned model</a> 這種訓練後模型類型相關，但不是同一件事。</p>
<h2 id="概念位置">概念位置</h2>
<p><a href="/blog/llm/knowledge-cards/instruction-tuned/" data-link-title="Instruction-Tuned Model" data-link-desc="經過指令微調的模型：會跟著 prompt 走、回答使用者問題">Instruction-tuned model</a> 是訓練狀態，instruction following 是行為表現。模型可能經過 SFT，仍在細格式、邊界條件或多約束任務上失敗；也可能在簡單指令上表現穩定，但遇到衝突指令或長 prompt 漏掉限制。</p>
<h2 id="可觀察訊號與例子">可觀察訊號與例子</h2>
<p>測試訊號包含：是否輸出指定 JSON、是否只回答要求的欄位、是否避免多餘解釋、是否在資料不足時說不知道、是否遵守「不要呼叫工具」或「只讀不寫」。本地小模型常在簡單問答可用，但在多條格式限制同時存在時掉分。</p>
<h2 id="設計責任">設計責任</h2>
<p>評估 instruction following 時要做 coverage 測試：格式、長度、拒答、資料不足、衝突指令、跨語言指令都要看。失敗時優先用更清楚的 prompt、few-shot、structured output 或 validator 兜底；長期穩定需求才考慮 fine-tune。</p>
]]></content:encoded></item><item><title>Reflection / Self-critique</title><link>https://tarrragon.github.io/blog/llm/knowledge-cards/reflection/</link><pubDate>Thu, 14 May 2026 00:00:00 +0000</pubDate><guid>https://tarrragon.github.io/blog/llm/knowledge-cards/reflection/</guid><description>&lt;p>Reflection（self-critique）的核心概念是「&lt;strong>模型先生成一個草版、再對自己的草版 critique、再修改&lt;/strong>」。屬於推理引導類的 prompting 技術、也是 &lt;a href="https://tarrragon.github.io/blog/llm/04-applications/workflow-patterns/" data-link-title="4.7 Workflow 編排模式" data-link-desc="Pipeline / router / parallel / reflection：多 LLM call 組合的四種基本模式與退化條件">workflow pattern&lt;/a> 的基本模式之一。跟 &lt;a href="https://tarrragon.github.io/blog/llm/knowledge-cards/chain-of-thought/" data-link-title="Chain-of-Thought（CoT）" data-link-desc="讓 LLM 先輸出推理步驟再給最終答案的 prompting / 訓練方式、reasoning model 的基礎機制">chain-of-thought&lt;/a> 不同：CoT 是「過程要 explicit」、reflection 是「先寫一版再批評再改」、有明確的兩階段。&lt;/p>
&lt;h2 id="概念位置">概念位置&lt;/h2>
&lt;p>Reflection 三步：&lt;/p>





&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-text" data-lang="text">&lt;span class="line">&lt;span class="ln">1&lt;/span>&lt;span class="cl">[Generate] 模型生成 v1
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="ln">2&lt;/span>&lt;span class="cl"> ↓
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="ln">3&lt;/span>&lt;span class="cl">[Critique] 模型（或 critic LLM）對 v1 給回饋
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="ln">4&lt;/span>&lt;span class="cl"> ↓
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="ln">5&lt;/span>&lt;span class="cl">[Refine] 模型按回饋生成 v2
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="ln">6&lt;/span>&lt;span class="cl"> ↓
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="ln">7&lt;/span>&lt;span class="cl">(可選 loop)&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>跟其他模式對照：&lt;/p>
&lt;table>
 &lt;thead>
 &lt;tr>
 &lt;th>模式&lt;/th>
 &lt;th>結構&lt;/th>
 &lt;th>主要解的問題&lt;/th>
 &lt;/tr>
 &lt;/thead>
 &lt;tbody>
 &lt;tr>
 &lt;td>CoT&lt;/td>
 &lt;td>Think step by step、單次生成&lt;/td>
 &lt;td>隱式推理變 explicit&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td>Reflection&lt;/td>
 &lt;td>Generate → critique → refine&lt;/td>
 &lt;td>一次生成不夠好、需要二次審視&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td>Multi-step&lt;/td>
 &lt;td>Retrieve / decide / retrieve again&lt;/td>
 &lt;td>資訊不足、要動態補資料&lt;/td>
 &lt;/tr>
 &lt;/tbody>
&lt;/table>
&lt;h2 id="設計責任">設計責任&lt;/h2>
&lt;p>讀 prompt engineering / agent paper 看到「reflection」「self-critique」「self-refine」「critic」就是這個機制。實作判讀：&lt;/p>
&lt;ol>
&lt;li>&lt;strong>適用模型有能力辨識「自己寫的不夠好」&lt;/strong>、critique 跟 generator 不會共用同樣 blind spot。&lt;/li>
&lt;li>&lt;strong>失敗在 systematic error&lt;/strong>：critique 跟 generator 是同個模型、訓練分佈中的盲點不會因為「再想一次」消失。判讀訊號：critique 每次給很像的建議、或修完還是同一類錯——換 critic 用不同 base model、或加外部驗證（test、lint、schema）取代 LLM critique。&lt;/li>
&lt;li>&lt;strong>失敗在低能力模型&lt;/strong>：critic 能力不足、產不出有用建議、徒增 cost / latency。&lt;/li>
&lt;li>&lt;strong>失敗在無限循環&lt;/strong>：沒有客觀停止訊號、reflection 一直跑、cost 爆掉。緩解：step cap + 外部 metric（test pass、schema valid）。&lt;/li>
&lt;li>&lt;strong>失敗在過度修正&lt;/strong>：每次 reflection 都改一點、累積結果變糟（過度 fitting critic 意見）。緩解：保留 baseline、reflection 結果要跟 baseline 比、不一定採用。&lt;/li>
&lt;/ol>
&lt;p>&lt;a href="https://tarrragon.github.io/blog/llm/knowledge-cards/agent-loop/" data-link-title="Agent Loop" data-link-desc="LLM agent 自我循環的工作流：LLM 規劃下一步、執行 tool、看結果、再規劃下一步、直到任務完成或停止條件觸發">Agent loop&lt;/a> 是 reflection 的延伸特例、進階失敗模式見 &lt;a href="https://tarrragon.github.io/blog/llm/04-applications/agent-architecture/" data-link-title="4.4 Agent 架構原理" data-link-desc="Agent loop 結構、失敗模式、什麼任務適合 vs 不適合、跟人類審查的協作模型">4.4 Agent 架構&lt;/a>。完整 workflow pattern 比較見 &lt;a href="https://tarrragon.github.io/blog/llm/04-applications/workflow-patterns/" data-link-title="4.7 Workflow 編排模式" data-link-desc="Pipeline / router / parallel / reflection：多 LLM call 組合的四種基本模式與退化條件">4.7 Workflow patterns&lt;/a>。&lt;/p></description><content:encoded><![CDATA[<p>Reflection（self-critique）的核心概念是「<strong>模型先生成一個草版、再對自己的草版 critique、再修改</strong>」。屬於推理引導類的 prompting 技術、也是 <a href="/blog/llm/04-applications/workflow-patterns/" data-link-title="4.7 Workflow 編排模式" data-link-desc="Pipeline / router / parallel / reflection：多 LLM call 組合的四種基本模式與退化條件">workflow pattern</a> 的基本模式之一。跟 <a href="/blog/llm/knowledge-cards/chain-of-thought/" data-link-title="Chain-of-Thought（CoT）" data-link-desc="讓 LLM 先輸出推理步驟再給最終答案的 prompting / 訓練方式、reasoning model 的基礎機制">chain-of-thought</a> 不同：CoT 是「過程要 explicit」、reflection 是「先寫一版再批評再改」、有明確的兩階段。</p>
<h2 id="概念位置">概念位置</h2>
<p>Reflection 三步：</p>





<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="ln">1</span><span class="cl">[Generate]    模型生成 v1
</span></span><span class="line"><span class="ln">2</span><span class="cl">   ↓
</span></span><span class="line"><span class="ln">3</span><span class="cl">[Critique]    模型（或 critic LLM）對 v1 給回饋
</span></span><span class="line"><span class="ln">4</span><span class="cl">   ↓
</span></span><span class="line"><span class="ln">5</span><span class="cl">[Refine]      模型按回饋生成 v2
</span></span><span class="line"><span class="ln">6</span><span class="cl">   ↓
</span></span><span class="line"><span class="ln">7</span><span class="cl">(可選 loop)</span></span></code></pre></div><p>跟其他模式對照：</p>
<table>
  <thead>
      <tr>
          <th>模式</th>
          <th>結構</th>
          <th>主要解的問題</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>CoT</td>
          <td>Think step by step、單次生成</td>
          <td>隱式推理變 explicit</td>
      </tr>
      <tr>
          <td>Reflection</td>
          <td>Generate → critique → refine</td>
          <td>一次生成不夠好、需要二次審視</td>
      </tr>
      <tr>
          <td>Multi-step</td>
          <td>Retrieve / decide / retrieve again</td>
          <td>資訊不足、要動態補資料</td>
      </tr>
  </tbody>
</table>
<h2 id="設計責任">設計責任</h2>
<p>讀 prompt engineering / agent paper 看到「reflection」「self-critique」「self-refine」「critic」就是這個機制。實作判讀：</p>
<ol>
<li><strong>適用模型有能力辨識「自己寫的不夠好」</strong>、critique 跟 generator 不會共用同樣 blind spot。</li>
<li><strong>失敗在 systematic error</strong>：critique 跟 generator 是同個模型、訓練分佈中的盲點不會因為「再想一次」消失。判讀訊號：critique 每次給很像的建議、或修完還是同一類錯——換 critic 用不同 base model、或加外部驗證（test、lint、schema）取代 LLM critique。</li>
<li><strong>失敗在低能力模型</strong>：critic 能力不足、產不出有用建議、徒增 cost / latency。</li>
<li><strong>失敗在無限循環</strong>：沒有客觀停止訊號、reflection 一直跑、cost 爆掉。緩解：step cap + 外部 metric（test pass、schema valid）。</li>
<li><strong>失敗在過度修正</strong>：每次 reflection 都改一點、累積結果變糟（過度 fitting critic 意見）。緩解：保留 baseline、reflection 結果要跟 baseline 比、不一定採用。</li>
</ol>
<p><a href="/blog/llm/knowledge-cards/agent-loop/" data-link-title="Agent Loop" data-link-desc="LLM agent 自我循環的工作流：LLM 規劃下一步、執行 tool、看結果、再規劃下一步、直到任務完成或停止條件觸發">Agent loop</a> 是 reflection 的延伸特例、進階失敗模式見 <a href="/blog/llm/04-applications/agent-architecture/" data-link-title="4.4 Agent 架構原理" data-link-desc="Agent loop 結構、失敗模式、什麼任務適合 vs 不適合、跟人類審查的協作模型">4.4 Agent 架構</a>。完整 workflow pattern 比較見 <a href="/blog/llm/04-applications/workflow-patterns/" data-link-title="4.7 Workflow 編排模式" data-link-desc="Pipeline / router / parallel / reflection：多 LLM call 組合的四種基本模式與退化條件">4.7 Workflow patterns</a>。</p>
]]></content:encoded></item><item><title>Chain-of-Thought（CoT）</title><link>https://tarrragon.github.io/blog/llm/knowledge-cards/chain-of-thought/</link><pubDate>Tue, 12 May 2026 00:00:00 +0000</pubDate><guid>https://tarrragon.github.io/blog/llm/knowledge-cards/chain-of-thought/</guid><description>&lt;p>Chain-of-Thought（CoT、思維鏈、Wei et al., 2022）的核心概念是「&lt;strong>讓 LLM 先輸出一連串中間推理步驟、再給最終答案&lt;/strong>」、不是直接從問題跳到結論。CoT 是 reasoning model 的基礎機制；prompting 形式（few-shot 提示）跟訓練形式（reasoning RLHF / RL）兩條路都圍繞它演化。&lt;/p>
&lt;h2 id="概念位置">概念位置&lt;/h2>
&lt;p>CoT 的兩種觸發方式：&lt;/p>





&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-text" data-lang="text">&lt;span class="line">&lt;span class="ln">1&lt;/span>&lt;span class="cl">直接回答：
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="ln">2&lt;/span>&lt;span class="cl"> Q: 23 × 47 = ?
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="ln">3&lt;/span>&lt;span class="cl"> A: 1081
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="ln">4&lt;/span>&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="ln">5&lt;/span>&lt;span class="cl">Chain-of-Thought：
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="ln">6&lt;/span>&lt;span class="cl"> Q: 23 × 47 = ?
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="ln">7&lt;/span>&lt;span class="cl"> A: 先算 20 × 47 = 940、再算 3 × 47 = 141、加起來 940 + 141 = 1081。
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="ln">8&lt;/span>&lt;span class="cl"> 答案：1081&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>CoT 在 LLM 演化中的兩個階段：&lt;/p>
&lt;table>
 &lt;thead>
 &lt;tr>
 &lt;th>階段&lt;/th>
 &lt;th>觸發方式&lt;/th>
 &lt;th>代表模型 / 技術&lt;/th>
 &lt;/tr>
 &lt;/thead>
 &lt;tbody>
 &lt;tr>
 &lt;td>Prompting CoT&lt;/td>
 &lt;td>Few-shot 提示「請逐步思考」或「let&amp;rsquo;s think step by step」&lt;/td>
 &lt;td>GPT-3、PaLM、早期 instruct 模型&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td>Training CoT&lt;/td>
 &lt;td>訓練資料含大量 reasoning trace、模型學會「自然」用 CoT&lt;/td>
 &lt;td>GPT-4、Claude 3.5、Gemini Pro&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td>Reasoning RL&lt;/td>
 &lt;td>RL 階段獎勵「正確答案的長 reasoning trace」、模型學會用更長 CoT&lt;/td>
 &lt;td>DeepSeek-R1、o1 / o3、Qwen-QwQ、Claude 3.7 Sonnet thinking&lt;/td>
 &lt;/tr>
 &lt;/tbody>
&lt;/table>
&lt;p>第三階段的特性：模型自己決定「該想多久」（&lt;a href="https://tarrragon.github.io/blog/llm/knowledge-cards/test-time-compute/" data-link-title="Test-Time Compute" data-link-desc="推論時動態增加計算量換取答案品質的 paradigm、reasoning model 跟 best-of-N 的共同基底">test-time compute&lt;/a> 動態擴展）、推理 trace 可達數千 token、最終答案才是少數 token。&lt;/p>
&lt;h2 id="設計責任">設計責任&lt;/h2>
&lt;p>讀 prompt engineering / paper 看到「CoT」「step by step」「reasoning trace」「thinking」等就是這個機制。寫 code 場景的判讀：&lt;/p>
&lt;ol>
&lt;li>&lt;strong>複雜推理任務開 CoT 通常有幫助&lt;/strong>（math、debug、algorithm design）— 即使是 instruct model 也能透過 prompting 觸發&lt;/li>
&lt;li>&lt;strong>簡單任務 CoT 浪費 token&lt;/strong>（autocomplete、單行查詢、純查表）&lt;/li>
&lt;li>&lt;strong>Reasoning model 的 CoT 是內建行為&lt;/strong>、不需要用 prompt 觸發、但 reasoning trace 會消耗大量 &lt;a href="https://tarrragon.github.io/blog/llm/knowledge-cards/token/" data-link-title="Token" data-link-desc="LLM 處理文字時的最小單位：介於字元與單字之間">token&lt;/a>（推論時間、context、API 成本都翻倍）&lt;/li>
&lt;li>&lt;strong>本地跑 reasoning model&lt;/strong>：DeepSeek-R1 distill 系列、Qwen-QwQ 等可本地跑、但需要較大 &lt;a href="https://tarrragon.github.io/blog/llm/knowledge-cards/context-window/" data-link-title="Context Window" data-link-desc="模型一次能處理的最大 token 數量：prompt 加生成的總和上限">context window&lt;/a> 容納 reasoning trace&lt;/li>
&lt;/ol></description><content:encoded><![CDATA[<p>Chain-of-Thought（CoT、思維鏈、Wei et al., 2022）的核心概念是「<strong>讓 LLM 先輸出一連串中間推理步驟、再給最終答案</strong>」、不是直接從問題跳到結論。CoT 是 reasoning model 的基礎機制；prompting 形式（few-shot 提示）跟訓練形式（reasoning RLHF / RL）兩條路都圍繞它演化。</p>
<h2 id="概念位置">概念位置</h2>
<p>CoT 的兩種觸發方式：</p>





<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="ln">1</span><span class="cl">直接回答：
</span></span><span class="line"><span class="ln">2</span><span class="cl">  Q: 23 × 47 = ?
</span></span><span class="line"><span class="ln">3</span><span class="cl">  A: 1081
</span></span><span class="line"><span class="ln">4</span><span class="cl">
</span></span><span class="line"><span class="ln">5</span><span class="cl">Chain-of-Thought：
</span></span><span class="line"><span class="ln">6</span><span class="cl">  Q: 23 × 47 = ?
</span></span><span class="line"><span class="ln">7</span><span class="cl">  A: 先算 20 × 47 = 940、再算 3 × 47 = 141、加起來 940 + 141 = 1081。
</span></span><span class="line"><span class="ln">8</span><span class="cl">     答案：1081</span></span></code></pre></div><p>CoT 在 LLM 演化中的兩個階段：</p>
<table>
  <thead>
      <tr>
          <th>階段</th>
          <th>觸發方式</th>
          <th>代表模型 / 技術</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>Prompting CoT</td>
          <td>Few-shot 提示「請逐步思考」或「let&rsquo;s think step by step」</td>
          <td>GPT-3、PaLM、早期 instruct 模型</td>
      </tr>
      <tr>
          <td>Training CoT</td>
          <td>訓練資料含大量 reasoning trace、模型學會「自然」用 CoT</td>
          <td>GPT-4、Claude 3.5、Gemini Pro</td>
      </tr>
      <tr>
          <td>Reasoning RL</td>
          <td>RL 階段獎勵「正確答案的長 reasoning trace」、模型學會用更長 CoT</td>
          <td>DeepSeek-R1、o1 / o3、Qwen-QwQ、Claude 3.7 Sonnet thinking</td>
      </tr>
  </tbody>
</table>
<p>第三階段的特性：模型自己決定「該想多久」（<a href="/blog/llm/knowledge-cards/test-time-compute/" data-link-title="Test-Time Compute" data-link-desc="推論時動態增加計算量換取答案品質的 paradigm、reasoning model 跟 best-of-N 的共同基底">test-time compute</a> 動態擴展）、推理 trace 可達數千 token、最終答案才是少數 token。</p>
<h2 id="設計責任">設計責任</h2>
<p>讀 prompt engineering / paper 看到「CoT」「step by step」「reasoning trace」「thinking」等就是這個機制。寫 code 場景的判讀：</p>
<ol>
<li><strong>複雜推理任務開 CoT 通常有幫助</strong>（math、debug、algorithm design）— 即使是 instruct model 也能透過 prompting 觸發</li>
<li><strong>簡單任務 CoT 浪費 token</strong>（autocomplete、單行查詢、純查表）</li>
<li><strong>Reasoning model 的 CoT 是內建行為</strong>、不需要用 prompt 觸發、但 reasoning trace 會消耗大量 <a href="/blog/llm/knowledge-cards/token/" data-link-title="Token" data-link-desc="LLM 處理文字時的最小單位：介於字元與單字之間">token</a>（推論時間、context、API 成本都翻倍）</li>
<li><strong>本地跑 reasoning model</strong>：DeepSeek-R1 distill 系列、Qwen-QwQ 等可本地跑、但需要較大 <a href="/blog/llm/knowledge-cards/context-window/" data-link-title="Context Window" data-link-desc="模型一次能處理的最大 token 數量：prompt 加生成的總和上限">context window</a> 容納 reasoning trace</li>
</ol>
]]></content:encoded></item></channel></rss>