Tự nhất quán để đánh giá độ tin cậy
prompt dưới đây nhằm yêu cầu ChatGPT phân loại cảm xúc (sentiment) của một bài đánh giá. Bạn cần ước lượng mức độ tin cậy của ChatGPT cho mỗi lớp bằng cách dùng phương pháp tự nhất quán (self-consistency).
Hàm get_response() để giao tiếp với ChatGPT đã được nạp sẵn cho bạn.
Bài tập này là một phần của khóa học
Explainable AI trong Python
Hướng dẫn bài tập
- Với mỗi bài đánh giá, thêm
sentimentvào danh sáchresponses. - Tính độ tin cậy cho từng loại cảm xúc.
Bài tập tương tác thực hành trực tiếp
Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.
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)