Kom igångKom igång gratis

Few-shot-promptning med Llama

Du använder en Llama-modell för att identifiera sentimentet i kundrecensioner från Google och Yelp som Positive eller Negative. För att dessa etiketter ska bli konsekventa för varje recension utformar du en few-shot-prompt med tre exempel.

Här är de exempel du vill ge modellen:

  • 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

Den här övningen är en del av kursen

Arbeta med Llama 3

Visa kurs

Övningsinstruktioner

  • Fyll i few-shot-prompten genom att tilldela Positive eller Negative till de angivna recensionerna.
  • Skicka prompten till modellen med stoppord "Review" så att modellen bara svarar på en recension.

Interaktiv övning med praktiskt arbete

Testa den här övningen genom att slutföra den här exempelkoden.

# 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'])
Redigera och kör kod