MulaiMulai sekarang secara gratis

Few-shot prompting dengan Llama

Anda menggunakan model Llama untuk mengidentifikasi sentimen ulasan pelanggan dari Google dan Yelp sebagai Positive atau Negative. Untuk memastikan label ini konsisten pada setiap ulasan, Anda akan merancang few-shot prompt yang berisi tiga contoh.

Berikut contoh yang ingin Anda berikan kepada 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

Latihan ini adalah bagian dari kursus

Bekerja dengan Llama 3

Lihat Kursus

Petunjuk latihan

  • Lengkapi few-shot prompt dengan menetapkan Positive atau Negative untuk ulasan yang disediakan.
  • Kirim prompt ke model dengan kata henti "Review" agar model hanya merespons satu ulasan.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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 dan Jalankan Kode