Mulai sekarangMulai gratis

Self-consistency untuk menilai keyakinan

prompt di bawah ini bertujuan meminta ChatGPT mengklasifikasikan sentimen sebuah ulasan. Anda harus memperkirakan tingkat keyakinan ChatGPT pada setiap kelas menggunakan self-consistency.

Fungsi get_response() untuk berkomunikasi dengan ChatGPT telah dimuat untuk Anda.

Latihan ini merupakan bagian dari kursus

Explainable AI in Python

Lihat Kursus

Instruksi latihan

  • Untuk setiap ulasan, tambahkan sentiment ke list responses.
  • Hitung tingkat keyakinan untuk setiap sentimen.

Latihan interaktif langsung praktik

Cobalah latihan ini dengan melengkapi kode contoh ini.

prompt = """Classify the following review as positive or negative. 
You should reply with either "positive" or "negative", nothing else.
Review: 'The coffee was excellent, but the service left much to be desired.'"""

responses = []
for i in range(5):
    sentiment = get_response(prompt)
    # Append the response to the responses list
    ____

# Compute the confidence for each sentiment
confidence = {
    'positive': ____,
    'negative': ____
}

print(confidence)
Edit dan Jalankan Kode