開始使用免費開始

用自洽性評估信心度

下面的 prompt 會要求 ChatGPT 判斷評論的情緒傾向。你需要用自洽性(self-consistency)來估計 ChatGPT 在各分類上的信心度。

與 ChatGPT 溝通的 get_response() 函式已為你預先載入。

本練習屬於課程

Python 的 Explainable AI

檢視課程

練習說明

  • 針對每則評論,將 sentiment 加到 responses 清單後面。
  • 計算各情緒類別的信心度。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

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)
編輯並執行程式碼