Self-consistency to assess confidence
The prompt below aims to ask ChatGPT to classify the sentiment of a review. You have to estimate the confidence of ChatGPT in each class using self-consistency.
The get_response() function to communicate with ChatGPT is pre-loaded for you.
Latihan ini adalah bagian dari kursus
Explainable AI in Python
Petunjuk latihan
- For each review, append the
sentimentto theresponseslist. - Compute the confidence for each sentiment.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
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)