开始使用免费开始使用

Llama 的少样本提示

您正在使用 Llama 模型将来自 Google 和 Yelp 的客户评论识别为 PositiveNegative。为确保每条评论的标签一致,您将设计一个包含 3 个示例的少样本提示

以下是您希望提供给模型的示例:

  • 我昨晚在这家店下单,体验很棒! → Positive
  • 我的订单延迟了超过一小时也没有任何更新。太让人失望了! → Negative
  • 食物品质一流。强烈推荐! → Positive

本练习是课程的一部分

使用 Llama 3

查看课程

练习说明

  • 通过为给定的评论指定 PositiveNegative,补全少样本提示。
  • 使用停止词 "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'])
编辑并运行代码