始める無料で始める

Llamaでの少数ショットプロンプト

あなたは Llama モデルを使って、Google と Yelp のカスタマーレビューの感情を PositiveNegative に判定します。各レビューでラベルが一貫するように、3つの例を含む少数ショットプロンプトを設計します。

モデルに提供したい例は次のとおりです。

  • 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 を割り当てて、少数ショットプロンプトを完成させます。
  • モデルが1件のレビューにだけ回答するよう、停止語に "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'])
コードを編集して実行