Few-shot prompting avec Llama
Vous utilisez un modèle Llama pour identifier le sentiment d’avis clients provenant de Google et Yelp comme Positive ou Negative. Pour garantir des libellés cohérents pour chaque avis, vous allez concevoir une invite few-shot contenant trois exemples.
Voici les exemples que vous souhaitez fournir au modèle :
- 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
Cet exercice fait partie du cours
Travailler avec Llama 3
Instructions
- Complétez l’invite few-shot en attribuant
PositiveouNegativeaux avis fournis. - Envoyez l’invite au modèle avec le mot d’arrêt
"Review"pour que le modèle ne réponde qu’à un seul avis.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# 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'])