针对 few-shot 提示的迭代式提示工程
您目前在一家内容创作公司参与一个项目。该项目的目标是开发一个文本分类模型,能够准确识别并归类文本中的不同情绪,例如快乐、悲伤和恐惧。当文本不包含可辨识的情绪时,您希望模型返回 "no explicit emotion"。
您决定使用提供的 few-shot prompt。不过,您注意到 "Time flies like an arrow" 被错误地分类为 "surprise"。您现在的目标是改进这个 prompt,使模型将该示例正确分类为 "no explicit emotion"。
OpenAI 包和 get_response() 函数已为您预先加载。
本练习是课程的一部分
使用 OpenAI API 的 Prompt Engineering
练习说明
- 通过改进示例,迭代式地优化
prompt,使"They sat and ate their meal"这一示例的输出为 no explicit emotion。
交互式实操练习
通过完成这段示例代码来试试这个练习。
client = OpenAI(api_key="")
# Refine the following prompt
prompt = """
Receiving a promotion at work made me feel on top of the world -> Happiness
The movie's ending left me with a heavy feeling in my chest -> Sadness
Walking alone in the dark alley sent shivers down my spine -> Fear
____
____
They sat and ate their meal ->
"""
response = get_response(prompt)
print(response)