การวิเคราะห์ความรู้สึกด้วย few-shot prompting
คุณกำลังทำงานด้านการวิจัยตลาด และต้องการใช้ few-shot prompting เพื่อวิเคราะห์ความรู้สึก (sentiment analysis) จากรีวิวของลูกค้า โดยกำหนดตัวเลขให้กับบทสนทนาของลูกค้าแต่ละราย ได้แก่ -1 หากความรู้สึกเป็นเชิงลบ และ 1 หากเป็นเชิงบวก โดยมีตัวอย่างบทสนทนาก่อนหน้าสำหรับให้โมเดลเรียนรู้ดังนี้
- The product quality exceeded my expectations -> 1
- I had a terrible experience with this product's customer service -> -1
แพ็กเกจ OpenAI ถูกโหลดไว้ให้แล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Prompt Engineering กับ OpenAI API
คำแนะนำการฝึกหัด
- ระบุตัวอย่างในรูปแบบบทสนทนาก่อนหน้า โดยกำหนดข้อความเป็น context สำหรับ role
userและตัวเลขเป็น context สำหรับ roleassistant - ระบุข้อความต่อไปนี้ให้โมเดลจำแนก พร้อมกำหนด role ที่เหมาะสม:
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)