使用 few-shot 提示的情感分析
您正在进行市场调研,目标是使用 few-shot 提示对客户评价进行情感分析。对于每段客户对话,您需要分配一个数值:情感为负记为 -1,情感为正记为 1。您向模型提供以下示例,作为可学习的以往对话。
- The product quality exceeded my expectations -> 1
- I had a terrible experience with this product's customer service -> -1
OpenAI 包已为您预先加载。
本练习是课程的一部分
使用 OpenAI API 的 Prompt Engineering
练习说明
- 将示例作为以往对话提供:把文本作为
user角色的上下文,把数值作为assistant角色的上下文。 - 提供以下文本让模型进行分类,并使用合适的角色:
The price of the product is really fair given its features。
交互式实操练习
通过完成这段示例代码来试试这个练习。
client = OpenAI(api_key="")
response = client.chat.completions.create(
model = "gpt-4o-mini",
# Provide the examples as previous conversations
messages = [{"role": "____", "content": "____"},
{"role": "____", "content": "____"},
{"role": "____", "content": "____"},
{"role": "____", "content": "____"},
# Provide the text for the model to classify
{"role": "____", "content": "____"}
],
temperature = 0
)
print(response.choices[0].message.content)