使用 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 的提示工程
練習說明
- 將這些範例作為先前對話提供:把文字指定為
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)