使用 Llama 進行少量示例提示(Few-shot prompting)
你正在使用 Llama 模型,將來自 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
練習說明
- 依題目提供的評論內容,補上
Positive或Negative,完成少量示例提示。 - 以
"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'])