Get startedGet started for free

Few-shot prompting with Llama

You're using a Llama model to identify the sentiment of customer reviews from Google and Yelp as Positive or Negative. To ensure these labels are consistent for each review, you'll design a few-shot prompt containing three examples.

Here are the examples you want to provide to the model:

  • 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

This exercise is part of the course

Working with Llama 3

View Course

Exercise instructions

  • Complete the few-shot prompt by assigning Positive or Negative to the reviews provided.
  • Send the prompt to the model with the "Review" stop word so the model only responds to one review.

Hands-on interactive exercise

Have a go at this exercise by completing this sample 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'])
Edit and Run Code