Self-consistency เพื่อประเมินความเชื่อมั่น
prompt ด้านล่างนี้ใช้สำหรับขอให้ ChatGPT จำแนก sentiment ของรีวิว โดยต้องประเมินความเชื่อมั่นของ ChatGPT ในแต่ละคลาสด้วยวิธี self-consistency
ฟังก์ชัน get_response() สำหรับสื่อสารกับ ChatGPT ถูกโหลดไว้ให้แล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Explainable AI ด้วย Python
คำแนะนำการฝึกหัด
- สำหรับรีวิวแต่ละรายการ ให้เพิ่ม
sentimentเข้าไปในลิสต์responses - คำนวณค่าความเชื่อมั่นสำหรับแต่ละ sentiment
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
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)