เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

Few-shot prompting กับ Llama

คุณกำลังใช้โมเดล Llama เพื่อวิเคราะห์ความรู้สึก (sentiment) ของรีวิวลูกค้าจาก Google และ Yelp โดยจำแนกเป็น Positive หรือ Negative เพื่อให้ป้ายกำกับเหล่านี้มีความสอดคล้องกัน จะต้องออกแบบ few-shot prompt ที่มีตัวอย่างสามรายการ

นี่คือตัวอย่างที่ต้องการส่งให้โมเดล:

  • I ordered from this place last night, and I'm impressed! → Positive
  • My order was delayed by over an hour without any updates. Disappointing! → Negative
  • The food quality is top-notch. Highly recommend! → Positive

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

การทำงานกับ Llama 3

ดูคอร์ส

คำแนะนำการฝึกหัด

  • เติมให้ few-shot prompt สมบูรณ์โดยกำหนด Positive หรือ Negative ให้กับรีวิวแต่ละรายการ
  • ส่งพรอมต์ไปยังโมเดลพร้อมกำหนด stop word เป็น "Review" เพื่อให้โมเดลตอบสนองต่อรีวิวเพียงรายการเดียว

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# Complete the few-shot prompt
prompt="""Review 1: I ordered from this place last night, and I'm impressed! 
Sentiment 1: ____,
Review 2: My order was delayed by over an hour without any updates. Disappointing!  
Sentiment 2: ____,
Review 3: The food quality is top-notch. Highly recommend! 
Sentiment 3: ____,
Review 4: Delicious food, and excellent customer service! 
Sentiment 4:"""

# Send the prompt to the model with a stop word
output = llm(prompt, max_tokens=2, stop=["____"]) 
print(output['choices'][0]['text'])
แก้ไขและรันโค้ด