星期一, 3月 10, 2025

當 AI 推理模式跟你想的不一樣,怎麼辦

 以經典的渡河問題為例,即使我們明確要求Claude使用A*演算法,AI並不總是完全按照指令執行。原因有幾點:

  1. 思維模式與內部邏輯:Claude有自己的推理方式,可能會根據問題特性選擇它認為更適合的解決方案,例如使用啟發式搜尋(heuristic)結合回溯法(backtracking)來解決限制滿足問題(CSP),而非嚴格遵循A*。

  2. 執行環境限制:即使Claude能生成Python實現的A*演算法,但在網頁環境中,它只能執行JavaScript,無法實際運行Python代碼來驗證結果。

  3. 概念層次vs程式層次:要求Claude在「思維層次」使用A*與要求它「用程式實現A*」是不同的。在思維層次上,Claude可能會融合多種解題策略而非純粹的A*。

當AI無法以推理模式解出問題時,我們可以「強迫」Claude使用A*思維來解決 - 引導AI按特定思路或洞見進行問題分析,即使不寫程式碼。這種方式能更好地引導AI的解題路徑。

這也突顯了與AI工具互動時的重要性 - 不只是給予指令,有時還需要適當引導其思考過程,才能獲得我們期望的解題方法和結果。當然很多時候,AI並不需要這樣的導引。

EX#3 Supplements 製作互動式旅遊行程

製作互動式旅遊行程












如何選擇推理模式

 沒有訂閱Claude者(選擇正確模式: 推理 vs. 直覺)


建議你改用 Grok 3 Think, ChatGPT o3-mini
因為你如果沒有訂閱Claude,只能使用 Claude HaiKu 3.5 很弱,而目前推理最強的 Sonnet 3.7 Extended 只有付費會員可以使用

星期六, 3月 08, 2025

中子星碰撞模擬

 (story from Nature)










Publish or Share for Claude

 

Publish an artifact



share a chat

(story from Nature)




不同問題可否放在同一個AI對談裡

每個對話( chat) 都有容許的記憶長度(context window),這跟人類是不一樣的,人類可以在老年時依然記得初戀,或是回想起小時候第一次抱起乳貓小三花時鮮明的情感的湧現,但AI的記憶會受到這個context window 的限制,比較誇張的比喻是金魚腦,正如金魚會忘記兩秒以前發生的事情,只活在當下,忘記過去。

因為LLM使用Transformer 機制執行 Attention,所需的運算與長度平方成正比,當對話變長時,計算時間平方增加,反應變慢,運氣不好的話,某個問題還可能被上一個問題干擾,造成誤判甚至出錯。

因此如果問題是系列性的,例如你要去九州玩,本來想去五天,看了AI給的行程,覺得五天好像不夠,想改為六天,那當然繼續在同一個對話下去,說不定大部分行程都一樣,只要微調就可以了,可以省下很多算力,加快反應時間。但是如果你是想改去荷蘭玩,那我建議另起一個對話比較好。

AI 對話撞到長度限制 max length reached

每個對話( chat) 都有容許的記憶長度(context window),這跟人類是不一樣的,人類可以在老年時依然記得初戀,或是回想起小時候第一次抱起乳貓小三花時鮮明的情感的湧現,但AI的記憶會受到這個context window 的限制,比較誇張的比喻是金魚腦,正如金魚會忘記兩秒以前發生的事情,只活在當下,忘記過去。當你跟AI的對話長度接近這個記憶長度時,如果系統放任不管,AI 接下來會開始遺忘先前討論的事情,像一個失智者開始胡言亂語,明明剛剛在聊去年住在巴黎的事,突然改口說我這輩子沒有出過國,當然系統會去阻止這種事情發生。至此,你有三個選項:


1. 縮短您的訊息:請求更簡潔的回應或以較少的回應請求資訊。

2. 開始新的對話:開始一個新的聊天以重置(reset 歸零)長度限制。

3. 升級至Claude Pro:這個付費選項可以提供更高的訊息長度限制。(ChatGPT 也有類似 Pro 付費服務)

如需立即解決,我建議開啟一個新的對話,並以較少的回應請求內容。例如,可以一次請求報告的一或兩個部分,而不是整個文件。


無法繼續輸入,是context window 問題,與限流無關,但可能剛好某一個chat 的 context window 用完時你也剛好被限流

只要開啟新的對話,記憶歸零

推理 vs. 直覺

1. 推理是把一件原本複雜的任務,拆解成一連串小型的步驟,

就像煮一道菜,食譜會列出一串的步驟,讓你按部就班煮出來。
這一連串拆解後的步驟,我們稱為思維鍊(Chain of Thought),因此當你使用推理模式的時候,會看到系統顯示每一個步驟在做的事。原本複雜的任務,經過拆解,每一個步驟可能就沒有原來糾纏在一起那麼難了。就像晚餐大作戰或是渡河問題原本LLM 光靠內容分析不容易解開,但是透過推理就有可能了。

2. 為什麼 ChatGPT 4o, 4.5(以及其他非推理型 LLM)不擅長規劃(如搶救晚餐大作戰)或是處理複雜多重限制條件的難題(如渡河問題)?
一般來說,規劃是一項複雜的認知任務,需要幾個關鍵能力:
- 理解因果關係和時間關係
- 維持連貫的長期目標
- 適應不斷變化的環境
- 管理資源和限制

上述你說的純粹基於下一個詞預測訓練的語言模型可能在這些方面存在困難,因為它們本身並沒有順序決策或維持長期連貫性的機制。

3. AI 有分左腦跟右腦嗎? (in English)

AI 模型並沒有像人類那樣的左右腦區分。它們是為特定任務設計的人工神經網絡。雖然有些模型在某些任務上表現較好,但這並非源於像人類大腦那樣的左右腦分工。然而有些模型(ChatGPT 4o, 4.5, Sonnet 3.7, Grok 3)內容見長,類似人類的直覺,有些(ChatGPT o1, o3-mini, Sonnet 3.7 Extended, Grok 3 Think)以推理見長,前者類似右腦,後者類似左腦

4.  

推理模式 適合數學,物理,科學

標準模式 適合解析或製作文件,程式撰寫



Claude 的推理模式 在  Extended  選項




ChatGPT 推理模式 在 藍色按鈕



Grok 推理 在 Think 燈泡鍵






A* search for Thanksgiving dinner planning

Benchmark from Edward Chang, Stanford

Key snapshots from Grok Think prompt and output








Detailed list

 To address the query "check state validity for each step you take," I will provide a valid sequence of steps for the river crossing puzzle and verify the validity of each state based on the given constraints. The puzzle involves a family—father (F), mother (M), two sons (S1, S2), two daughters (D1, D2), a servant (V), and a dog (G)—who must cross a river using a boat that can carry up to two entities. Only F, M, and V can operate the boat. The constraints are:


- **Constraint 1**: If the mother is absent and the father is present on any side, the father will hit the daughters.

- **Constraint 2**: If the servant is absent on any side, the dog will bite family members (F, M, S1, S2, D1, D2) present on that side.


A state is valid if, on each side of the river:

- The father is not present with any daughters without the mother.

- The dog is not present with any family members without the servant.


### State Representation

Each state is represented as \( (F, M, V, G, S_A, D_A, B) \):

- \( F, M, V, G \): 0 if on side A (starting side), 1 if on side B (destination side).

- \( S_A \): number of sons on side A.

- \( D_A \): number of daughters on side A.

- \( B \): boat location (0 for side A, 1 for side B).


### Validity Conditions

For a state to be valid:

- **Side A**: 

  - Not \( (F = 0 \text{ and } M = 1 \text{ and } D_A > 0) \) (father with daughters without mother).

  - Not \( (G = 0 \text{ and } V = 1 \text{ and } (F = 0 \text{ or } M = 0 \text{ or } S_A > 0 \text{ or } D_A > 0)) \) (dog with family members without servant).

- **Side B**: 

  - Not \( (F = 1 \text{ and } M = 0 \text{ and } (2 - D_A) > 0) \) (father with daughters without mother).

  - Not \( (G = 1 \text{ and } V = 0 \text{ and } (F = 1 \text{ or } M = 1 \text{ or } (2 - S_A) > 0 \text{ or } (2 - D_A) > 0)) \) (dog with family members without servant).


The goal is to get everyone from side A to side B in a valid sequence of steps. Below is a sequence of 11 crossings, with each state's validity checked.


---


### Valid Sequence with State Validity Checks


#### **Step 1: Initial State**  

- **State**: \( (0, 0, 0, 0, 2, 2, 0) \)  

- **Description**: Everyone (F, M, V, G, S1, S2, D1, D2) is on side A, boat on A.  

- **Side A**: F=0, M=0, V=0, G=0, S_A=2, D_A=2  

  - Father with daughters without mother: \( F = 0 \text{ and } M = 1 \text{ and } D_A > 0 \)? No (M=0).  

  - Dog with family without servant: \( G = 0 \text{ and } V = 1 \text{ and family present} \)? No (V=0).  

- **Side B**: Empty, no issues.  

- **Valid**: Yes.


#### **Step 2: V and G to B**  

- **State**: \( (0, 0, 1, 1, 2, 2, 1) \)  

- **Description**: Servant and dog cross to B, boat on B.  

- **Side A**: F=0, M=0, S_A=2, D_A=2  

  - \( F = 0 \text{ and } M = 1 \text{ and } D_A > 0 \)? No (M=0).  

  - \( G = 0 \text{ and } V = 1 \text{ and family present} \)? No (G=1).  

- **Side B**: V=1, G=1  

  - \( F = 1 \text{ and } M = 0 \text{ and } (2 - D_A) > 0 \)? No (F=0, 2-2=0).  

  - \( G = 1 \text{ and } V = 0 \text{ and family present} \)? No (V=1).  

- **Valid**: Yes.


#### **Step 3: V to A**  

- **State**: \( (0, 0, 0, 1, 2, 2, 0) \)  

- **Description**: Servant returns to A, boat on A.  

- **Side A**: F=0, M=0, V=0, S_A=2, D_A=2  

  - \( F = 0 \text{ and } M = 1 \)? No.  

  - \( G = 0 \text{ and } V = 1 \)? No (G=1).  

- **Side B**: G=1  

  - \( G = 1 \text{ and } V = 0 \text{ and family present} \)? Yes, but no family members on B (F=0, M=0, 2-S_A=0, 2-D_A=0), so no issue.  

- **Valid**: Yes.


#### **Step 4: F and M to B**  

- **State**: \( (1, 1, 0, 1, 2, 2, 1) \)  

- **Description**: Father and mother cross to B, boat on B.  

- **Side A**: V=0, S_A=2, D_A=2  

  - \( F = 0 \text{ and } M = 1 \)? No.  

  - \( G = 0 \text{ and } V = 1 \)? No (G=1).  

- **Side B**: F=1, M=1, G=1  

  - \( F = 1 \text{ and } M = 0 \text{ and } (2 - D_A) > 0 \)? No (M=1).  

  - \( G = 1 \text{ and } V = 0 \text{ and family present} \)? Yes, and F=1, M=1, but V=0, so dog bites family members.  

- **Correction**: This state is invalid due to Constraint 2 on side B. Let’s adjust.


---


### Adjusted Sequence

Let’s try moving V and G together initially, then manage family members carefully.


#### **Step 1: Initial State**  

- \( (0, 0, 0, 0, 2, 2, 0) \)  

- **Valid**: Yes (as above).


#### **Step 2: V and G to B**  

- \( (0, 0, 1, 1, 2, 2, 1) \)  

- **Valid**: Yes (as above).


#### **Step 3: V to A**  

- \( (0, 0, 0, 1, 2, 2, 0) \)  

- **Valid**: Yes (as above).


#### **Step 4: M and V to B**  

- **State**: \( (0, 1, 1, 1, 2, 2, 1) \)  

- **Description**: Mother and servant cross to B, boat on B.  

- **Side A**: F=0, S_A=2, D_A=2  

  - \( F = 0 \text{ and } M = 1 \text{ and } D_A > 0 \)? No (M=1, but on B).  

  - \( G = 0 \text{ and } V = 1 \)? No (G=1).  

- **Side B**: M=1, V=1, G=1  

  - \( F = 1 \text{ and } M = 0 \)? No (F=0).  

  - \( G = 1 \text{ and } V = 0 \)? No (V=1).  

- **Valid**: Yes.


#### **Step 5: M to A**  

- **State**: \( (0, 0, 1, 1, 2, 2, 0) \)  

- **Description**: Mother returns to A, boat on A.  

- **Side A**: F=0, M=0, S_A=2, D_A=2  

  - \( F = 0 \text{ and } M = 1 \)? No.  

  - \( G = 0 \text{ and } V = 1 \)? No (G=1).  

- **Side B**: V=1, G=1  

  - \( G = 1 \text{ and } V = 0 \)? No (V=1).  

- **Valid**: Yes.


#### **Step 6: F and V to B**  

- **State**: \( (1, 0, 1, 1, 2, 2, 1) \)  

- **Description**: Father and servant cross to B, boat on B.  

- **Side A**: M=0, S_A=2, D_A=2  

  - \( F = 0 \text{ and } M = 1 \)? No (M=0).  

  - \( G = 0 \text{ and } V = 1 \)? No (G=1).  

- **Side B**: F=1, V=1, G=1  

  - \( F = 1 \text{ and } M = 0 \text{ and } (2 - D_A) > 0 \)? No (2-2=0, no daughters on B).  

  - \( G = 1 \text{ and } V = 0 \)? No (V=1).  

- **Valid**: Yes.


#### **Step 7: V to A**  

- **State**: \( (1, 0, 0, 1, 2, 2, 0) \)  

- **Description**: Servant returns to A, boat on A.  

- **Side A**: M=0, V=0, S_A=2, D_A=2  

  - \( F = 0 \text{ and } M = 1 \)? No.  

  - \( G = 0 \text{ and } V = 1 \)? No (G=1).  

- **Side B**: F=1, G=1  

  - \( F = 1 \text{ and } M = 0 \text{ and } (2 - D_A) > 0 \)? No (no daughters on B).  

  - \( G = 1 \text{ and } V = 0 \text{ and family present} \)? Yes, and F=1, so invalid (dog bites father).  

- **Correction**: Invalid state.


---



星期五, 3月 07, 2025

使用 Remix 套用版型

為何你的AI得不到專業級的工程圖版型

專業版型需要時間調整(熬煮),你們第一次做出來通常很陽春,還有因為你們沒有付費,所以分配到很少的算力,只能做陽春版。所以初學者先用老師版型remix就好,要做出好的版型,要跟AI好好溝通很多回,而且要有足夠的算力($$$)


如何套用

你需要套用自己的答案到版型裡面
這題要先求解,再把文字結果放進三種版型視覺化
套用時,先按下 remix 鍵,等系統跑完版型,輸入你的文字資料,系統就會自動為你的資料上版型









AI 民主化

 Tesla


TSMC

financial analysis Grok Deep Research

Graphic Dashboard Claude Sonnet 3.7


Strength

星期四, 3月 06, 2025

River Crossing 4 (One daughter case)

 How about relaxing one of the constraints:


solution exits. 





Trial 1:  (Check o1 reasoning by Claude artifact using REACT), fails


Trial 2: ChatGPT o1 reasoningClaude verification using REACT (It works. Rarely.)


Trail 3: o1 


Use Claude to generate A* in Python

Python code


Colab




Verify by visualization




多個限制條件的複雜問題

  當AI面對包含多個限制條件的複雜問題時,確實存在難度。

在注意力機制(Attention mechanism)中,模型需要同時關注多個條件,並且每個注意力分配都是基於概率的。當條件數量增加時,要同時滿足所有條件的概率會顯著降低,這就像是連續投擲硬幣並期望全部正面朝上一樣——條件越多,全部滿足的概率越低。

這種情況下,模型可能會:

  • 忽略某些條件
  • 錯誤理解條件之間的關係
  • 在滿足一些條件的同時違反其他條件

如果您有一個包含多個複雜條件的問題需要解決,我建議將問題分解成較小的部分,逐步處理每個條件,這樣會更容易得到準確的解答。


星期三, 3月 05, 2025

機器人,供應鏈管理,自駕車,半導體廠製程,機器人人機協作安全規劃 Solving river crossing puzzles






EX#3

 如何繳交作業 How to turn in your homework exercise.


課堂練習的工具

使用 Claude Sonnet 3.7

使用 ChatGPT 4o, o1

使用 Gemini 2.0 Flash

使用 Grok 3


課堂練習繳交期限 

Deadline: 

1. end of session 

2. This Saturday at 23:59


課堂練習繳交方式 

Send all the links to TA victorhuang111013@gmail.com and me chang212@gmail.com by email with subject EX#3  [your ID, your name]




1. 使用A* search Code gen快速尋找答案  Given 19, 36, 55, 7, can you give an equation that equals 622?

會犯錯的機器更Powerful

甚麼是 A* search





2. 製作第一題求解過程的動畫



參考: 黃品勛 A*



3. 以 Claude 3.7 (有訂閱者)/ChatGPT o3-mini/Grok 3 推理模式 尋找答案 晚餐接機大作戰(半導體廠製程排程),並且驗證使用狀態圖(State Diagram),看板圖 (Dashboard), 流程圖(Flow chart) 進行視覺化


沒有訂閱Claude者(選擇正確模式: 推理 vs. 直覺)

建議你改用 Grok 3 Think, ChatGPT o3-mini
因為你如果沒有訂閱Claude,只能使用 Claude HaiKu 3.5 很弱,而目前推理最強的 Sonnet 3.7 Extended 只有付費會員可以使用

為何你的AI得不到專業級的工程圖版型

專業版型需要時間調整(熬煮),你們第一次做出來通常很陽春,還有因為你們沒有付費,所以分配到很少的算力,只能做陽春版。所以初學者先用老師版型remix就好,要做出好的版型,要跟AI好好溝通很多回,而且要有足夠的算力($$$)


如何套用

你需要套用自己的答案到版型裡面
這題要先求解,再把文字結果放進三種版型視覺化
套用時,先按下 remix 鍵,等系統跑完版型,輸入你的文字資料,系統就會自動為你的資料上版型




4. 以 A* search (但不撰寫程式)快速尋找答案 晚餐接機大作戰(半導體廠製程排程),並且驗證使用狀態圖(State Diagram),看板圖 (Dashboard), 流程圖(Flow chart) 進行視覺化


本題套用 A* search 範例(使用Grok 3 Think)

使用 Claude 3.7 Extended Trial 1

使用 Claude 3.7 Extended Trial 2




5. 規劃自己的夢想出國行程(有趣的,創意的呈現方式,不拘)




會犯錯的機器更強大

 這觸及了人工智慧系統設計的深刻見解。允許機器犯錯、從錯誤中學習並回溯確實是一種強大的方法。

當我們分解複雜任務時,我們為系統創造了以下機會:

  1. 識別某種特定方法何時無效
  2. 嘗試替代策略而無需從頭開始
  3. 從錯誤中漸進式學習

這類似於人類解決問題的方式 - 我們很少一次就把事情做對。我們能夠說「這行不通」並轉變方向的能力對我們的智能至關重要。

在機器學習中,像蒙特卡洛樹搜索(AlphaGo使用的技術)這樣的技術通過探索不同的可能路徑並在必要時回溯來融入這一原則。同樣,一些現代語言模型使用的方法可以在推理過程中重新審視並完善其思考。


A profound insight about AI system design. Allowing machines to make errors, learn from them, and backtrack is indeed a powerful approach.

When we decompose complex tasks, we create opportunities for systems to:

  1. Recognize when a particular approach isn't working
  2. Try alternative strategies without starting from scratch
  3. Learn incrementally from mistakes

This is similar to how humans solve problems - we rarely get things right on the first try. Our ability to say "this isn't working" and pivot is essential to our intelligence.

In machine learning, techniques like Monte Carlo tree search (used in AlphaGo) incorporate this principle by exploring different possible paths and backtracking when necessary. Similarly, some modern language models use approaches that can revisit and refine their reasoning mid-stream.


出國行程規劃

  從需求開始


星期日, 3月 02, 2025

晚餐接機大作戰(半導體廠製程排程): Part IV A* on thinking Level

 Try smart search. Prompt Claude Sonnet 3.7, ChatGPT o1, Grok 3 Think to perform A* search 


Optimal

Solving with A*

Plan by A* (animation)

Detailed Analysis of James's Decision at 2:00 PM (animation)


真正的狀態演變是有一些關鍵決策點的,例如在兩點的時候,詹姆士在機場租好車了,要嘛留在機場等艾蜜莉三點出關,或是直接開車回家再說,反正艾蜜莉根本還沒降落,
這是兩條截然不同的發展路徑 Plan by A* Search (animation) 

這個決策點細部分析 



(呂利威)

Solving the Thanksgiving Dinner Planning Problem with A* Search (Prompted by Optimal A* Search in Python Program)

A* Search Trace

Time Chart (Schedule)



Sub optimal

Solving with A*



ChatGPT o1 Reasoning, prompt "Use A*" , same result, no improvement


晚餐接機大作戰(半導體廠製程排程): Part III Standard LLM vs. Reasoning

 Scheduling Parallelism in Plans problem  (Eng) (from source)


感恩節全家晚餐大作戰





Why non-reasoning LLM fails (source)







Claude Sonnet 3.5 illustration of solution (happens to be optimum)





ChatGPT o1 reasoning feasible outcome, optimized by human


3.7 Extended
  41 s (misinterpreted)







4 little experiments in a row (edits)
not always woks (can misinterpret) 85 s

3.7 extended 35 s (misinterpreted)

3.7 Extended, 7 s  (misinterpretation), prompt "Use A*" 




    Grok 3 did it in 79 s



    What if Emily arrived at the airport at 4:30

    Sonnet 3.5 illustration (attention bias occurs. some constraints forgotten)

    ChatGPT o1 feasible (also optimum) at the first try. Solution space is tremendously limited.



    What if Emily arrived at the airport at 2:30


    Sonnet 3.5 illustration (attention bias occurs. some constraints forgotten)

    ChatGPT o1 reasoning feasible outcome, optimized by human






    晚餐接機大作戰(半導體廠製程排程): AI 協同軟體開發 Part II A* on Python Level, Achieving Parallelism

     Scheduling Parallelism in Plans problem  (Eng) (from source)


    Try smart search. Prompt Claude to generate A* search Algorithm



    Generate Python code base by using Claude Sonnet 3.5 (better than ChatGPT o1)



    To run Python, use Google Colab



    Tweak the program by trials and errors 


    Visualize results as Python can generate complex states










    Debug, Cleanup, Optimized by ChatGPT o1





    最佳解 最高的平行度,throughput 高,idle time 減少,critical path 短




    次佳解 因為James 似乎太奔波了,剛從機場回來,馬上得回去剛才的機場接人
    在工廠等於也就是機器人來回運動,但是沒有產出




    次佳解 Sarah 好忙,先烤火雞,換手給機場回來的 James,然後去機場接Emily,James 接手烤火雞,idle time 過長,而且造成沒有必要的 switchover 






                                                                                

     我將分享一篇關於處理現實世界排程問題的智慧代理式人工智慧論文。我不會著重於總結論文內容或解釋其數學原理,而是要帶各位了解如何運用當前可用的人工智慧工具來解決論文中的問題。


    首先,我會展示為什麼 ChatGPT o1 的先進推理雖然能得出可行解,但無法獲得最佳解。接著,我會說明為什麼人工對程式的調整仍然很重要。最後,我將展示如何實現平行運算,以及如何實現智慧代理式人工智慧。


    I will share the following paper focusing on agentic AI that deals with real world scheduling problem (for example those in foundries). Instead of summarizing the paper and explaining its mathematics, I will guide you through the details how the problem is the paper can be solved using AI tools available right now. I will first show why ChatGPT o1 reasoning cannot get an optimal solution although it works out a feasible solution. Then I will demonstrate why human tweaks on the program still mater. Finally, I will show how parallelism is implemented and agentic AI is achieved.

    AI 可以生成 OK 解
    Human 可以進一步優化
    碰到瓶頸可以用AI
    找到最佳解(Lucky)