解释基于聊天的生成式 AI 模型

Python 可解释性 AI

Fouad Trad

Machine Learning Engineer

基于聊天的生成式 AI 模型

  • 用于生成文本
  • 基于上下文和知识进行预测

 

图片显示用户向生成式 AI 模型发送提示并收到回复。

Python 可解释性 AI

链式思维(Chain-of-thought)提示

  • 促使模型阐明其推理过程

图片展示链式思维提示如何要求模型按步骤解题,输出包含每步推理。

Python 可解释性 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 可解释性 AI

自洽性

评估模型对生成答案的置信度

图片显示自洽性提示是对同一提示多次调用模型,每次均有回应。

Python 可解释性 AI

文本分类中的自洽性

适用于文本分类任务

图片展示自洽性示例:模型需将用户评价分类为正面或负面,并给出多次回答。

Python 可解释性 AI

文本分类中的自洽性

适用于文本分类任务

图片展示自洽性示例:模型需将用户评价分类为正面或负面,并给出多次回答。置信度按各类别占总回答数的比例计算。

Python 可解释性 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 可解释性 AI

创建自洽性提示

print(confidence)
{
    'positive': 0.6,
    'negative': 0.4
}
Python 可解释性 AI

Passons à la pratique !

Python 可解释性 AI

Preparing Video For Download...