agent-05 · Self-correction 有三層:decoding、workflow 與 reasoning
AI self-correction 的實用地圖:decoding tricks、workflow feedback、trained reasoning 都需要真實 signal,而不只是 reflection。
本文為 LLM 自動翻譯,原文以 English 版本為準;另有 Lee Hung-yi-inspired English teaching-style version 與 李宏毅老師經典的教學風格版。 如有不通順或誤譯處,建議參照原文。
第五堂課問了一個聽起來很簡單的問題:AI 能自我修正嗎?
答案取決於我們所謂「自我修正」是什麼意思。model 可以在人類指出錯誤後修改答案,這很常見。更難的問題是,它能不能在沒有人類直接透露答案的情況下,自己偵測並修掉自己的錯誤。
Hung-yi Lee 把這個空間整理成三層:
- 改變 decoding
- 改變 workflow
- 透過 reasoning training 改變 model
這個分類很有用,因為人們常把三者都壓成一個模糊詞:self-correction。
它們不是同一件事。
Builder takeaway:self-correction 需要 signal。先用 tests、verifiers、retrieved evidence、contrastive baselines 或 trained rewards,再相信 model 自己覺得已經修好。
第 1 層:decoding
第一類方法不改變 model weights,而是改變下一個 token 的選擇方式。
核心想法是 contrastive decoding。
一般 language model 會產生下一個 token 的機率分布。Contrastive decoding 會建立另一個分布,代表比較糟或更容易出錯的狀態,然後把壞分布從好分布中扣掉。
粗略來說:
better_answer = normal_distribution - bad_distribution
關鍵在於如何取得壞分布。
早期版本使用較小的 model。如果大 model 和小 model 都對某個泛用 continuation 給高機率,但大 model 對正確答案有更多訊號,那麼扣掉小 model 可能會有幫助。
DoLa 使用同一個 model 內部的 layers。較早的 layers 可以被視為較不成熟的猜測;較晚的 layers 比較精煉。把它們拿來比較,並把最終輸出推離較早、較弱的分布。
Context-aware decoding 對 retrieval 做類似的事。讓 model 在有 retrieved document 與沒有 retrieved document 的情況下各跑一次。沒有文件的答案更可能反映 parametric prior 或 hallucination。把它扣掉,就能讓 model 更依賴 retrieved context。
視覺與音訊版本則會降級輸入。模糊圖片、移除圖片、加入 noise,或把音訊換成靜音。降級後的輸入會揭露 model 的 prior。再把這個 prior 從正常答案中扣掉。
這是個漂亮的想法。它把 hallucination 視為一個可以估計、也可以遠離的方向。
成本問題
Contrastive decoding 往往需要額外 inference。你可能需要跑兩次 model:一次正常,一次在降級條件下。
這很昂貴。
這堂課討論 minimum test-time intervention,或 MTI,作為降低成本的方法。不要在每個 token 都套用 contrastive decoding。只在 model 不確定時使用,例如 entropy 很高的時候。
這很符合直覺。大多數 token 不會改變世界。只在決策點花額外 compute。
當 normal 與 contrastive input 共享 prefix 時,KV cache reuse 可以進一步降低成本。這同樣是真實系統裡很重要的工程細節。一個到處把 inference cost 翻倍的聰明方法,可能輸給無聊的 baseline。
第 2 層:workflow
第二類方法把 model 包在一個流程裡。
先生成答案,再要求 model 檢查它。也許請它 reflect。也許跑測試。也許用 checklist。也許對外搜尋。也許把輸出送給 verifier。
這是最熟悉的 self-correction 形式,因為它看起來就像人們使用 chat model 的方式:
Are you sure?
Check your work.
Find the bug.
Revise the answer.
這堂課在這裡很謹慎。純 self-reflection 並不可靠地有效。
model 可以從錯變對,也可以從對變錯。要求 model 重新考慮,可能增加它修改答案的意願,但這不等於提升正確性。
這就是為什麼這堂課區分 internal self-reflection 與 external feedback。
Internal reflection 是 model 在沒有新 evidence 的情況下批評自己。
External feedback 則給它有 grounding 的東西:compiler error、failed test、retrieved document、checklist、人類 comment、simulator result。
External feedback 通常是更好的賭注。
reflection 有 compute baseline
這堂課最好的提醒之一,是關於 majority vote。
假設你的 self-reflection workflow 需要三次 model call:generate、reflect、revise。公平的比較不是一個原始答案。公平的比較可能是抽樣三個獨立答案,然後取 majority 或最好的那個。
如果 reflection 贏不了它,也許不值得花那些 compute。
這很重要,因為 self-correction paper 可能不小心拿弱 baseline 來比較。額外 compute 常常有幫助。問題是 reflection 的結構,是否比單純多抽樣更有幫助。
Verification 有用,但不是免費。
revision 的四種結果
這堂課對 revision outcome 的拆解很簡單,也很清楚:
- wrong to right
- right to right
- wrong to wrong
- right to wrong
夢想是 wrong to right。
惡夢是 right to wrong。
兩個 metrics 讓這件事變得具體:
- Confidence Level:如果原答案是對的,model 會保留它嗎?
- Critic Score:如果原答案是錯的,model 會修正它嗎?
一個什麼都改的 model 有高 plasticity,但低 stability。一個永遠不改的 model 有 stability,但無法修正錯誤。
不同 reflection prompts 會移動這個 tradeoff。稱讚可能讓 model 堅持答案。懷疑可能讓它更常 revise。這很有趣,但也很重要。model 在 reflection 下的「personality」,有一部分只是 prompt 的產物。
第 3 層:reasoning
第三類方法試圖把 correction 內化到 model 裡。
與其外接一個 workflow 告訴它「現在 reflect」,不如訓練 model,讓檢查與修改發生在它自己的 reasoning process 裡。
這就是 RL with verifiable rewards 變得相關的地方。對數學或 code 而言,最終答案可以被檢查。model 產生 reasoning tokens 和答案。答案正確就得到 positive reward;錯誤就得到 negative reward。
訓練不需要標註每個中間 thought。它只需要最後的 verification signal。
常見結果是 emergent verification:model 開始產生一種 reasoning,會嘗試一條路、注意到錯誤,並在回答前修正。
那看起來更接近真正的 self-correction。
知道事實還不夠
這堂課給了一個重要的概念提醒:model 內部擁有正確知識,並不等於會用它來修正自己。
model 可能在孤立情境下知道某個事實,但在回答另一個問題時無法套用它。知識存在於 weights 的某處。self-correction behavior 關乎控制:何時 retrieve 這個 fact、何時懷疑當前路徑、何時 revise。
這個區分很重要,因為很多人談 reasoning 時,好像唯一問題是 model 是否「知道」得夠多。
有時候知識已經在那裡。錯的是 routing。
REVISE 與 distribution shift 問題
這堂課討論 REVISE,它把 error detection 和 error correction 分開。
model 先學會偵測答案是否需要 refinement。如果需要,它會發出特殊 refine token。接著它再學會產生修正後的答案。
這種拆解很合理。偵測錯誤和修正錯誤是不同技能。
但這裡有個微妙問題。一旦 fine-tune model,它犯錯的種類可能改變。舊錯誤構成的 dataset 可能不再符合新 model 的 failure distribution。
這是 self-improvement 裡常見的陷阱。用昨天的錯誤訓練可以有幫助,但也可能是在追逐一個移動目標。
RL 學到了新東西嗎?
這堂課最後談到一個我覺得很重要的爭論。
當 RL 改善 reasoning 時,到底改變了什麼?
一種看法是,base model 原本就有好的 reasoning paths,只是機率很低。RL 只是把它們 upweight。支持證據來自 pass@k:如果從 base model 多抽樣幾次,它最後也可能產生正確路徑。
另一種看法是,RL 可以教出真正新的 reasoning behavior,而不只是重新加權舊路徑。證據來自觀察 reasoning path 本身,而不只是最終答案。如果 RL model 在更嚴格的 path evaluation 下產生更好的 chain of thought,那可能代表更深層的東西改變了。
這堂課的答案不教條。早期訓練可能主要是在重新加權既有路徑。後期訓練可能創造新 capability。
我覺得這很合理。
我的實務 takeaway
如果我想讓 agent 修正自己,我不會從「reflect on your answer」開始。
我會用這個階梯:
- 我能取得 external verifier 嗎?
- 我能跑 test、search、compiler、simulator 或 checklist 嗎?
- 我能便宜地比較 multiple samples 嗎?
- 在 hallucination prior 明顯時,我能使用 contrastive decoding 嗎?
- 我能訓練或選擇有更強 reasoning behavior 的 model 嗎?
除非 model 很強,而且任務沒有 external signal,否則純 self-reflection 會在我清單的很後面。
核心教訓
Self-correction 不是單一機制。
在 decoding layer,我們把 token probabilities 導離估計出的 error states。
在 workflow layer,我們用 verification 與 feedback 包住 generation。
在 reasoning layer,我們試著訓練會在定稿答案前自行檢查的 model。
更深的教訓是:correction 需要 signal。沒有 signal,reflection 可能變成風格,而不是真相。
最好的 self-correcting system 可能會結合三層:更好的 decoding、真實 external feedback,以及被訓練成能在 reasoning 裡使用 feedback 的 model。
概念清單
這堂課的主要 self-correction 概念:
- self-correction 是在沒有人類直接給答案的情況下進行 error detection 加 error correction
- 不更新 model weights 的 decoding-level methods
- contrastive decoding 與扣掉 error-prone distribution 的想法
- 控制 contrast 強度的 alpha 或 omega weights
- 用較小 model 當 error model
- 用 logit lens 檢查 intermediate-layer predictions
- DoLa,或 Decoding by Contrasting Layers
- multimodal models 裡的 layer contrastive decoding
- 使用刻意糟糕 instruction 的 instruction contrastive decoding
- RAG 裡透過對比有無 retrieved documents 的 context-aware decoding
- 透過移除、模糊或遮罩圖片的 visual contrastive decoding
- 對比正常音訊與降級音訊的 audio-aware decoding
- 高 entropy token 上的 minimum test-time intervention
- 用 KV cache reuse 降低 contrastive decoding 成本
- VISTA-style representation intervention
- attention-level contrastive methods,例如 ACG
- workflow-level generation、verification、reflection 與 revision
- internal self-reflection 對比 external feedback
- RefineBench-style multi-round refinement evaluation
- 四種 revision outcomes:wrong to right、right to right、wrong to wrong、right to wrong
- Confidence Level 與 Critic Score
- accuracy relationship
ACC2 = ACC1 CL + (1 - ACC1) CS - reflection prompt personality effects,例如稱讚會保留答案、懷疑會增加修改
- majority vote 作為 compute-matched baseline
- reasoning 作為 internalized correction
- 知道一個 fact,對比知道何時用它來 correction
- correction states 的 steering vectors
- REVISE 與 refine tokens
- 用舊錯誤模式訓練時的 distribution shift
- RL 與具可驗證 reward 的 RLVR
- reasoning training 後的 emergent verification
- thinking cost 與 reasoning-token budgets
- reasoning 透過 decomposing problems 降低 sample complexity
- parity 或 XOR 作為 multi-step reasoning 壓縮複雜度的例子
- pass@k 與 RL 是否只是重新加權既有路徑的問題
- training-free sampling methods,例如 COTPath-style path selection 或 checking
來源與參考資料
本文主要觀看的來源: