說明聊天式生成式 AI 模型

Python 的 Explainable AI

Fouad Trad

Machine Learning Engineer

聊天式生成式 AI 模型

  • 用於產生文字
  • 依情境與知識 {{2}} 做預測

 

顯示使用者傳送提示給生成式 AI 模型並收到回應的圖片。

Python 的 Explainable AI

思路鏈(Chain-of-thought)提示

  • 引導模型說明其推理過程

顯示「思路鏈」提示如何要求模型逐步解題,且輸出包含每一步推理的圖片。

Python 的 Explainable AI

建立思路鏈提示

prompt = """A shop starts with 20 apples. It sells 5 apples and then receives 8 more. 
How many apples does the shop have now? Show your reasoning step-by-step."""

response = get_response(prompt)
print(response)
To find out how many apples the shop has now, let's follow the transactions step-by-step:

1- The shop begins with 20 apples.
2- The shop sells 5 apples. We subtract this number from the starting quantity: 20 - 5 = 15
3- The shop receives 8 apples. We add this number to the remaining apples: 15 + 8 = 23
So, after these transactions, the shop has 23 apples.
Python 的 Explainable AI

Self-consistency(自洽性)

評估模型對產生答案的信心

顯示自洽性提示是對模型多次送出相同提示,並各自得到回應的圖片。

Python 的 Explainable AI

文字分類中的自洽性

適用於文字分類任務

顯示自洽性範例:模型需將使用者評論分類為正面或負面,並提供多個回應的圖片。

Python 的 Explainable AI

文字分類中的自洽性

適用於文字分類任務

顯示自洽性範例:模型將評論分為正面或負面並給出多個回應;信心以各類別在所有回應中的比例計算的圖片。

Python 的 Explainable AI

建立自洽性提示

prompt = """Classify the following review as positive or negative. 
You should reply with either "positive" or "negative", nothing else.
Review: 'The customer service was great, but the product itself did not meet my expectations.'"""

responses = []
for i in range(5): sentiment = get_response(review)
responses.append(sentiment.lower())
confidence = { 'positive': responses.count('positive') / len(responses), 'negative': responses.count('negative') / len(responses) }
Python 的 Explainable AI

建立自洽性提示

print(confidence)
{
    'positive': 0.6,
    'negative': 0.4
}
Python 的 Explainable AI

一起來練習吧!

Python 的 Explainable AI

Preparing Video For Download...