Few-shot prompting với Llama
Bạn đang dùng một mô hình Llama để xác định cảm xúc của các đánh giá khách hàng từ Google và Yelp là Positive hoặc Negative. Để đảm bảo các nhãn này nhất quán cho từng đánh giá, bạn sẽ thiết kế một few-shot prompt gồm ba ví dụ.
Dưới đây là các ví dụ bạn muốn cung cấp cho mô hình:
- 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
Bài tập này là một phần của khóa học
Làm việc với Llama 3
Hướng dẫn bài tập
- Hoàn thiện few-shot prompt bằng cách gán
PositivehoặcNegativecho các đánh giá đã cho. - Gửi prompt đến mô hình với từ dừng
"Review"để mô hình chỉ phản hồi cho một đánh giá.
Bài tập tương tác thực hành trực tiếp
Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.
# 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'])